lkml.org 
[lkml]   [2008]   [May]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 1/6] ERR_PTR: if errno value is known at compile time, make sure it's valid
    Date
    ERR_PTR is easy to call with wrong argument (positive errno),
    and this error lead to catastrophic event - oops or kernel panic
    (dereference of invalid pointer).

    As most of error handling code paths are rarely tested, this kind of
    bug can be hidden for years.

    (Currently there are > 1400 calls of ERR_PTR with constant argument.)

    Signed-off-by: Marcin Slusarz <marcin.slusarz@gmail.com>
    Cc: Andrew Morton <akpm@linux-foundation.org>
    ---
    include/linux/err.h | 4 +++-
    1 files changed, 3 insertions(+), 1 deletions(-)

    diff --git a/include/linux/err.h b/include/linux/err.h
    index ec87f31..7b5daa6 100644
    --- a/include/linux/err.h
    +++ b/include/linux/err.h
    @@ -19,11 +19,13 @@

    #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)

    -static inline void *ERR_PTR(long error)
    +static inline void *__ERR_PTR(long error)
    {
    return (void *) error;
    }

    +#define ERR_PTR(error) (BUILD_BUG_ON(__builtin_constant_p(error) && !IS_ERR_VALUE(error)), __ERR_PTR(error))
    +
    static inline long PTR_ERR(const void *ptr)
    {
    return (long) ptr;
    --
    1.5.4.5


    \
     
     \ /
      Last update: 2008-05-19 00:01    [W:0.024 / U:0.576 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site