pipe: reject F_SETPIPE_SZ with size over UINT_MAX
authorEric Biggers <ebiggers@google.com>
Tue, 6 Feb 2018 23:42:00 +0000 (15:42 -0800)
committerBen Hutchings <ben@decadent.org.uk>
Sat, 16 Jun 2018 21:22:10 +0000 (22:22 +0100)
commit 96e99be40e4cff870a83233731121ec0f7f95075 upstream.

A pipe's size is represented as an 'unsigned int'.  As expected, writing a
value greater than UINT_MAX to /proc/sys/fs/pipe-max-size fails with
EINVAL.  However, the F_SETPIPE_SZ fcntl silently truncates such values to
32 bits, rather than failing with EINVAL as expected.  (It *does* fail
with EINVAL for values above (1 << 31) but <= UINT_MAX.)

Fix this by moving the check against UINT_MAX into round_pipe_size() which
is called in both cases.

Link: http://lkml.kernel.org/r/20180111052902.14409-6-ebiggers3@gmail.com
Signed-off-by: Eric Biggers <ebiggers@google.com>
Acked-by: Kees Cook <keescook@chromium.org>
Acked-by: Joe Lawrence <joe.lawrence@redhat.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: "Luis R . Rodriguez" <mcgrof@kernel.org>
Cc: Michael Kerrisk <mtk.manpages@gmail.com>
Cc: Mikulas Patocka <mpatocka@redhat.com>
Cc: Willy Tarreau <w@1wt.eu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
fs/pipe.c
include/linux/pipe_fs_i.h
kernel/sysctl.c

index 9fa8d82ce54d3328ebe5af3df0540e54c0828084..f75284e22b1be6df05f4981cd571e644015a7660 100644 (file)
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -1008,10 +1008,13 @@ const struct file_operations pipefifo_fops = {
  * Currently we rely on the pipe array holding a power-of-2 number
  * of pages. Returns 0 on error.
  */
-unsigned int round_pipe_size(unsigned int size)
+unsigned int round_pipe_size(unsigned long size)
 {
        unsigned long nr_pages;
 
+       if (size > UINT_MAX)
+               return 0;
+
        /* Minimum pipe size, as required by POSIX */
        if (size < PAGE_SIZE)
                size = PAGE_SIZE;
index 3f342d78afdf558239c4906830983e301b0d0323..eed87a0fdc5c60a2279120e6eb4064fd017e9ac3 100644 (file)
@@ -148,6 +148,6 @@ long pipe_fcntl(struct file *, unsigned int, unsigned long arg);
 struct pipe_inode_info *get_pipe_info(struct file *file);
 
 int create_pipe_files(struct file **, int);
-unsigned int round_pipe_size(unsigned int size);
+unsigned int round_pipe_size(unsigned long size);
 
 #endif
index a4f15c232afcc880d24674ae67c45e4e870fd5f0..e714622b6fa9bc17e9c126c71ffe4fb2c6150a78 100644 (file)
@@ -2230,9 +2230,6 @@ static int do_proc_dopipe_max_size_conv(bool *negp, unsigned long *lvalp,
        if (write) {
                unsigned int val;
 
-               if (*lvalp > UINT_MAX)
-                       return -EINVAL;
-
                val = round_pipe_size(*lvalp);
                if (*negp || val == 0)
                        return -EINVAL;