Skip to content

Commit

Permalink
net: Add explicit bound checks in net/socket.c
Browse files Browse the repository at this point in the history
The sys_socketcall() function has a very clever system for the copy
size of its arguments. Unfortunately, gcc cannot deal with this in
terms of proving that the copy_from_user() is then always in bounds.
This is the last (well 9th of this series, but last in the kernel) such
case around.

With this patch, we can turn on code to make having the boundary provably
right for the whole kernel, and detect introduction of new security
accidents of this type early on.

Signed-off-by: Arjan van de Ven <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
fenrus75 authored and davem330 committed Sep 28, 2009
1 parent 30df94f commit 4737905
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion net/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -2098,12 +2098,17 @@ SYSCALL_DEFINE2(socketcall, int, call, unsigned long __user *, args)
unsigned long a[6];
unsigned long a0, a1;
int err;
unsigned int len;

if (call < 1 || call > SYS_ACCEPT4)
return -EINVAL;

len = nargs[call];
if (len > sizeof(a))
return -EINVAL;

/* copy_from_user should be SMP safe. */
if (copy_from_user(a, args, nargs[call]))
if (copy_from_user(a, args, len))
return -EFAULT;

audit_socketcall(nargs[call] / sizeof(unsigned long), a);
Expand Down

0 comments on commit 4737905

Please sign in to comment.