• Ilya Dryomov's avatar
    sysctl: fix int -> unsigned long assignments in INT_MIN case · 9a5bc726
    Ilya Dryomov authored
    The following
        if (val < 0)
            *lvalp = (unsigned long)-val;
    is incorrect because the compiler is free to assume -val to be positive
    and use a sign-extend instruction for extending the bit pattern.  This is
    a problem if val == INT_MIN:
        # echo -2147483648 >/proc/sys/dev/scsi/logging_level
        # cat /proc/sys/dev/scsi/logging_level
    Cast to unsigned long before negation - that way we first sign-extend and
    then negate an unsigned, which is well defined.  With this:
        # cat /proc/sys/dev/scsi/logging_level
    Signed-off-by: default avatarIlya Dryomov <idryomov@gmail.com>
    Cc: Mikulas Patocka <mikulas@twibright.com>
    Cc: Robert Xiao <nneonneo@gmail.com>
    Cc: "Eric W. Biederman" <ebiederm@xmission.com>
    Cc: Kees Cook <keescook@chromium.org>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
sysctl.c 63.5 KB