Commit 870d3c0a authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] sched_getaffinity vs cpu hotplug race fix

From: Srivatsa Vaddagiri <vatsa@in.ibm.com>

Fix the race in sys_sched_getaffinity.  Patch below takes cpu_hotplug lock
before reading cpus_allowed mask of a task.
parent ddea677b
...@@ -2934,6 +2934,7 @@ asmlinkage long sys_sched_getaffinity(pid_t pid, unsigned int len, ...@@ -2934,6 +2934,7 @@ asmlinkage long sys_sched_getaffinity(pid_t pid, unsigned int len,
if (len < real_len) if (len < real_len)
return -EINVAL; return -EINVAL;
lock_cpu_hotplug();
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
retval = -ESRCH; retval = -ESRCH;
...@@ -2946,6 +2947,7 @@ asmlinkage long sys_sched_getaffinity(pid_t pid, unsigned int len, ...@@ -2946,6 +2947,7 @@ asmlinkage long sys_sched_getaffinity(pid_t pid, unsigned int len,
out_unlock: out_unlock:
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
unlock_cpu_hotplug();
if (retval) if (retval)
return retval; return retval;
if (copy_to_user(user_mask_ptr, &mask, real_len)) if (copy_to_user(user_mask_ptr, &mask, real_len))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment