Skip to content

Commit

Permalink
pipe: reject F_SETPIPE_SZ with size over UINT_MAX
Browse files Browse the repository at this point in the history
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/[email protected]
Signed-off-by: Eric Biggers <[email protected]>
Acked-by: Kees Cook <[email protected]>
Acked-by: Joe Lawrence <[email protected]>
Cc: Alexander Viro <[email protected]>
Cc: "Luis R . Rodriguez" <[email protected]>
Cc: Michael Kerrisk <[email protected]>
Cc: Mikulas Patocka <[email protected]>
Cc: Willy Tarreau <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
ebiggers authored and torvalds committed Feb 7, 2018
1 parent 9903a91 commit 96e99be
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
5 changes: 4 additions & 1 deletion fs/pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion include/linux/pipe_fs_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 0 additions & 3 deletions kernel/sysctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2623,9 +2623,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;
Expand Down

0 comments on commit 96e99be

Please sign in to comment.