sysctl: report EINVAL if value is larger than UINT_MAX for proc_douintvec
authorLiping Zhang <zlpnobody@gmail.com>
Fri, 7 Apr 2017 15:51:07 +0000 (23:51 +0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 8 Apr 2017 17:27:40 +0000 (10:27 -0700)
Currently, inputting the following command will succeed but actually the
value will be truncated:

  # echo 0x12ffffffff > /proc/sys/net/ipv4/tcp_notsent_lowat

This is not friendly to the user, so instead, we should report error
when the value is larger than UINT_MAX.

Fixes: e7d316a02f68 ("sysctl: handle error writing UINT_MAX to u32 fields")
Signed-off-by: Liping Zhang <zlpnobody@gmail.com>
Cc: Subash Abhinov Kasiviswanathan <subashab@codeaurora.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
kernel/sysctl.c

index 8cca4c7bb21f04f4a5d136dbeed69ef9870ca97c..8c8714fcb53c35a390becf14f2fa8e1bfc20142c 100644 (file)
@@ -2133,6 +2133,8 @@ static int do_proc_douintvec_conv(bool *negp, unsigned long *lvalp,
        if (write) {
                if (*negp)
                        return -EINVAL;
+               if (*lvalp > UINT_MAX)
+                       return -EINVAL;
                *valp = *lvalp;
        } else {
                unsigned int val = *valp;