[PATCH] sched: Fix sched_getaffinity(): Invalid argument issue

From: Alex Shi
Date: Thu Apr 01 2010 - 11:08:09 EST



commit cd3d8031eb fixed NU_CPUS > 1024 issue for old glibc binary
code compatibility. But it forget another situation: if the
nr_cpu_ids < len, the system call will return -EINVAL incorrectly.

The situation happened on my NHM-EP machine with 16 LCPUs.
$ taskset -c 0 ls
sched_getaffinity: Invalid argument
failed to get pid 0's affinity.

Signed-off-by: Alex Shi <alex.shi@xxxxxxxxx>
---
kernel/sched.c | 5 ++---
1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/kernel/sched.c b/kernel/sched.c
index 49d2fa7..fb9661b 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -4901,8 +4901,9 @@ SYSCALL_DEFINE3(sched_getaffinity, pid_t, pid, unsigned int, len,
{
int ret;
cpumask_var_t mask;
+ size_t retlen = min_t(size_t, nr_cpu_ids, cpumask_size());

- if (len < nr_cpu_ids)
+ if (len < retlen)
return -EINVAL;
if (len & (sizeof(unsigned long)-1))
return -EINVAL;
@@ -4912,8 +4913,6 @@ SYSCALL_DEFINE3(sched_getaffinity, pid_t, pid, unsigned int, len,

ret = sched_getaffinity(pid, mask);
if (ret == 0) {
- size_t retlen = min_t(size_t, len, cpumask_size());
-
if (copy_to_user(user_mask_ptr, mask, retlen))
ret = -EFAULT;
else
--
1.6.3



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/