aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--kernel/sched.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/kernel/sched.c b/kernel/sched.c
index 9ab3cd7858d3..6eaef3df2d19 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -4902,7 +4902,9 @@ SYSCALL_DEFINE3(sched_getaffinity, pid_t, pid, unsigned int, len,
4902 int ret; 4902 int ret;
4903 cpumask_var_t mask; 4903 cpumask_var_t mask;
4904 4904
4905 if (len < cpumask_size()) 4905 if (len < nr_cpu_ids)
4906 return -EINVAL;
4907 if (len & (sizeof(unsigned long)-1))
4906 return -EINVAL; 4908 return -EINVAL;
4907 4909
4908 if (!alloc_cpumask_var(&mask, GFP_KERNEL)) 4910 if (!alloc_cpumask_var(&mask, GFP_KERNEL))
@@ -4910,10 +4912,12 @@ SYSCALL_DEFINE3(sched_getaffinity, pid_t, pid, unsigned int, len,
4910 4912
4911 ret = sched_getaffinity(pid, mask); 4913 ret = sched_getaffinity(pid, mask);
4912 if (ret == 0) { 4914 if (ret == 0) {
4913 if (copy_to_user(user_mask_ptr, mask, cpumask_size())) 4915 int retlen = min(len, cpumask_size());
4916
4917 if (copy_to_user(user_mask_ptr, mask, retlen))
4914 ret = -EFAULT; 4918 ret = -EFAULT;
4915 else 4919 else
4916 ret = cpumask_size(); 4920 ret = retlen;
4917 } 4921 }
4918 free_cpumask_var(mask); 4922 free_cpumask_var(mask);
4919 4923