Skip to contentSkip to conversation

scheduler fix

GIT PULL Ingo Molnar 3 participants 6 messages Apr 8, 2010

lore
Share & tools
lore
#0 lore raw

Linus,

Please pull the latest sched-fixes-for-linus git tree from:

git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip.git sched-fixes-for-linus

Thanks,

Ingo

------------------>
Anton Blanchard (1):
sched: Fix sched_getaffinity()

 kernel/sched.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/sched.c +1 -1
index 528a105..eaf5c73 100644
@@ -4902,7 +4902,7 @@ SYSCALL_DEFINE3(sched_getaffinity, pid_t, pid, unsigned int, len,
 	int ret;
 	cpumask_var_t mask;
 
-	if (len < nr_cpu_ids)
+	if ((len * BITS_PER_BYTE) < nr_cpu_ids)
 		return -EINVAL;
 	if (len & (sizeof(unsigned long)-1))
 		return -EINVAL;
#1 lore raw

kernel/sched.c SYSCALL_DEFINE3(sched_getaffinity, pid_t, pid, unsigned int, len, · line 4906

Quoted 4 lines · Ingo Molnar
kernel/sched.c +1 -1
-	if (len < nr_cpu_ids)
+	if ((len * BITS_PER_BYTE) < nr_cpu_ids)
 		return -EINVAL;

Not that it really matters, but this will now fail for no good reason if you pass it a half-gigabyte area due to overflow.

Of course, if you pass it a half gig memory array, you're a f*cking moron to begin with, so I don't think anybody really _cares_. But in general, when checking system call arguments, I'd like people to think about overflow issues more.

In this case it doesn't matter, and overflow just makes the test more conservative than they need to be, but when it _does_ matter it often ends up being a security issue.

Linus

#2 lore raw
Quoted 8 lines · Linus Torvalds

kernel/sched.c SYSCALL_DEFINE3(sched_getaffinity, pid_t, pid, unsigned int, len, · line 4906

Quoted 4 lines · Ingo Molnar
kernel/sched.c +1 -1
-	if (len < nr_cpu_ids)
+	if ((len * BITS_PER_BYTE) < nr_cpu_ids)
 		return -EINVAL;

Not that it really matters, but this will now fail for no good reason if you pass it a half-gigabyte area due to overflow.

Which can easily be avoided.

if (len < DIV_ROUND_UP(nr_cpu_ids, BITS_PER_BYTE))

Andreas.

Signature · 3 lines
Andreas Schwab, [email protected]
GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84  5EC7 45C6 250E 6F00 984E
"And now for something completely different."
#3 lore raw
Quoted 11 lines · Andreas Schwab
Quoted 8 lines · Linus Torvalds

kernel/sched.c SYSCALL_DEFINE3(sched_getaffinity, pid_t, pid, unsigned int, len, · line 4906

Quoted 4 lines · Ingo Molnar
kernel/sched.c +1 -1
-	if (len < nr_cpu_ids)
+	if ((len * BITS_PER_BYTE) < nr_cpu_ids)
 		return -EINVAL;

Not that it really matters, but this will now fail for no good reason if you pass it a half-gigabyte area due to overflow.

Quoted 3 lines

Which can easily be avoided.

if (len < DIV_ROUND_UP(nr_cpu_ids, BITS_PER_BYTE))

nr_cpu_ids is a signed integer which turns the DIV_ROUND_UP into a somewhat suboptimal instruction sequence. (havent checked it though)

So i'd suggest changing nr_cpu_ids to unsigned int [unless there's some strong reason to have it signed] plus doing something like:

	if (len < (nr_cpu_ids >> BITS_PER_BYTE_BITS))

ought to both result in better code and should be more readable. We'd have to add:

  #define BITS_PER_BYTE_BITS 3

to linux/bitops.h.

Ingo

#4 lore raw
Quoted 5 lines · Ingo Molnar

So i'd suggest changing nr_cpu_ids to unsigned int [unless there's some strong reason to have it signed] plus doing something like:

	if (len < (nr_cpu_ids >> BITS_PER_BYTE_BITS))

No workee.

It really should round up.

If you worry about code generation, I'd suggest looking at whether nr_cpu_ids could just be made unsigned.

Anyway, this all was _not_ the point of my original email. I really don't care about this particular instance. I care more about the whole "in general people should think _way_ more about validating user-supplied arguments than clearly happened this time".

Linus

#5 lore raw
Quoted 4 lines · Linus Torvalds
Quoted 1 line · Ingo Molnar
Quoted 8 lines
Quoted 4 lines

So i'd suggest changing nr_cpu_ids to unsigned int [unless there's some strong reason to have it signed] plus doing something like:

	if (len < (nr_cpu_ids >> BITS_PER_BYTE_BITS))

No workee.

It really should round up.

Indeed.

Quoted 7 lines

If you worry about code generation, I'd suggest looking at whether nr_cpu_ids could just be made unsigned.

Anyway, this all was _not_ the point of my original email. I really don't care about this particular instance. I care more about the whole "in general people should think _way_ more about validating user-supplied arguments than clearly happened this time".

Yeah, no argument about that, point taken and accepted.

Ingo