From: Eric Biggers <ebiggers3@gmail.com>
To: linux-fsdevel@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
Joe Lawrence <joe.lawrence@redhat.com>,
Michael Kerrisk <mtk.manpages@gmail.com>,
Willy Tarreau <w@1wt.eu>, Mikulas Patocka <mpatocka@redhat.com>,
"Luis R . Rodriguez" <mcgrof@kernel.org>,
Kees Cook <keescook@chromium.org>,
linux-kernel@vger.kernel.org, Eric Biggers <ebiggers@google.com>
Subject: [PATCH 5/7] pipe: reject F_SETPIPE_SZ with size over UINT_MAX
Date: Sun, 7 Jan 2018 21:35:40 -0800 [thread overview]
Message-ID: <20180108053542.6472-6-ebiggers3@gmail.com> (raw)
In-Reply-To: <20180108053542.6472-1-ebiggers3@gmail.com>
From: Eric Biggers <ebiggers@google.com>
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.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
fs/pipe.c | 5 ++++-
include/linux/pipe_fs_i.h | 2 +-
kernel/sysctl.c | 3 ---
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/fs/pipe.c b/fs/pipe.c
index 9f20e7128578..f1ee1e599495 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -1020,10 +1020,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;
diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
index 5028bd4b2c96..5a3bb3b7c9ad 100644
--- a/include/linux/pipe_fs_i.h
+++ b/include/linux/pipe_fs_i.h
@@ -190,6 +190,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
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 33e2f0f02000..31fe10fd745f 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2630,9 +2630,6 @@ static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
if (write) {
unsigned int val;
- if (*lvalp > UINT_MAX)
- return -EINVAL;
-
val = round_pipe_size(*lvalp);
if (val == 0)
return -EINVAL;
--
2.15.1
next prev parent reply other threads:[~2018-01-08 5:35 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-08 5:35 [PATCH 0/7] pipe: buffer limits fixes and cleanups Eric Biggers
2018-01-08 5:35 ` [PATCH 1/7] pipe, sysctl: drop 'min' parameter from pipe-max-size converter Eric Biggers
2018-01-09 22:20 ` Kees Cook
2018-01-10 2:29 ` Eric Biggers
2018-01-10 17:30 ` Kees Cook
2018-01-08 5:35 ` [PATCH 2/7] pipe, sysctl: remove pipe_proc_fn() Eric Biggers
2018-01-08 5:35 ` [PATCH 3/7] pipe: actually allow root to exceed the pipe buffer limits Eric Biggers
2018-01-09 22:23 ` Kees Cook
2018-01-10 2:34 ` Eric Biggers
2018-01-08 5:35 ` [PATCH 4/7] pipe: fix off-by-one error when checking " Eric Biggers
2018-01-08 6:42 ` Willy Tarreau
2018-01-08 5:35 ` Eric Biggers [this message]
2018-01-09 22:24 ` [PATCH 5/7] pipe: reject F_SETPIPE_SZ with size over UINT_MAX Kees Cook
2018-01-08 5:35 ` [PATCH 6/7] pipe: simplify round_pipe_size() Eric Biggers
2018-01-09 22:27 ` Kees Cook
2018-01-10 2:52 ` Eric Biggers
2018-01-10 3:13 ` Kees Cook
2018-01-08 5:35 ` [PATCH 7/7] pipe: read buffer limits atomically Eric Biggers
2018-01-09 22:27 ` Kees Cook
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180108053542.6472-6-ebiggers3@gmail.com \
--to=ebiggers3@gmail.com \
--cc=ebiggers@google.com \
--cc=joe.lawrence@redhat.com \
--cc=keescook@chromium.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=mpatocka@redhat.com \
--cc=mtk.manpages@gmail.com \
--cc=viro@zeniv.linux.org.uk \
--cc=w@1wt.eu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.