Skip to contentSkip to conversation

sched: Fix sched_getaffinity(): Invalid argument issue

PATCH New Alex Shi 1 participant 1 message Apr 1, 2010

lore
Share & tools
lore

Alex Shi

author
#0 lore raw

PATCH 1/1 sched: Fix sched_getaffinity(): Invalid argument issue

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.
---
 kernel/sched.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
kernel/sched.c +2 -3
index 49d2fa7..fb9661b 100644
@@ -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
Signature · 1 line
1.6.3