diff options
author | Jens Axboe <jens.axboe@oracle.com> | 2010-05-19 21:03:16 +0200 |
---|---|---|
committer | Jens Axboe <jens.axboe@oracle.com> | 2010-05-21 21:12:52 +0200 |
commit | b492e95be0ae672922f4734acf3f5d35c30be948 (patch) | |
tree | a8a1e7f035903796e6b8f626add8d269bf989a35 /fs/pipe.c | |
parent | 35f3d14dbbc58447c61e38a162ea10add6b31dc7 (diff) | |
download | lwn-b492e95be0ae672922f4734acf3f5d35c30be948.tar.gz lwn-b492e95be0ae672922f4734acf3f5d35c30be948.zip |
pipe: set lower and upper limit on max pages in the pipe page array
We need at least two to guarantee proper POSIX behaviour, so
never allow a smaller limit than that.
Also expose a /proc/sys/fs/pipe-max-pages sysctl file that allows
root to define a sane upper limit. Make it default to 16 times the
default size, which is 16 pages.
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Diffstat (limited to 'fs/pipe.c')
-rw-r--r-- | fs/pipe.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/fs/pipe.c b/fs/pipe.c index 054b8a6a2c7a..d79872eba09a 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -19,11 +19,18 @@ #include <linux/pagemap.h> #include <linux/audit.h> #include <linux/syscalls.h> +#include <linux/fcntl.h> #include <asm/uaccess.h> #include <asm/ioctls.h> /* + * The max size that a non-root user is allowed to grow the pipe. Can + * be set by root in /proc/sys/fs/pipe-max-pages + */ +unsigned int pipe_max_pages = PIPE_DEF_BUFFERS * 16; + +/* * We use a start+len construction, which provides full use of the * allocated memory. * -- Florian Coosmann (FGC) @@ -1162,6 +1169,14 @@ long pipe_fcntl(struct file *file, unsigned int cmd, unsigned long arg) switch (cmd) { case F_SETPIPE_SZ: + if (!capable(CAP_SYS_ADMIN) && arg > pipe_max_pages) + return -EINVAL; + /* + * The pipe needs to be at least 2 pages large to + * guarantee POSIX behaviour. + */ + if (arg < 2) + return -EINVAL; ret = pipe_set_size(pipe, arg); break; case F_GETPIPE_SZ: |