[lkml]   [2009]   [Sep]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    Patch in this message
    Subject[PATCH 9/9] Add explicit bound checks in net/socket.c
    From: Arjan van de Ven <>
    Subject: [PATCH 9/9] Add explicit bound checks in net/socket.c

    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 <>

    diff --git a/net/socket.c b/net/socket.c
    index 49917a1..13a8d67 100644
    --- a/net/socket.c
    +++ b/net/socket.c
    @@ -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 > 6)
    + 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);

    Arjan van de Ven Intel Open Source Technology Centre
    For development, discussion and tips for power savings,

     \ /
      Last update: 2009-09-26 20:57    [W:0.020 / U:19.112 seconds]
    ©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site