aboutsummaryrefslogtreecommitdiffstats
path: root/fs/pipe.c
diff options
context:
space:
mode:
authorJens Axboe <jens.axboe@oracle.com>2010-05-19 15:03:16 -0400
committerJens Axboe <jens.axboe@oracle.com>2010-05-21 15:12:52 -0400
commitb492e95be0ae672922f4734acf3f5d35c30be948 (patch)
treea8a1e7f035903796e6b8f626add8d269bf989a35 /fs/pipe.c
parent35f3d14dbbc58447c61e38a162ea10add6b31dc7 (diff)
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.c15
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 @@
19#include <linux/pagemap.h> 19#include <linux/pagemap.h>
20#include <linux/audit.h> 20#include <linux/audit.h>
21#include <linux/syscalls.h> 21#include <linux/syscalls.h>
22#include <linux/fcntl.h>
22 23
23#include <asm/uaccess.h> 24#include <asm/uaccess.h>
24#include <asm/ioctls.h> 25#include <asm/ioctls.h>
25 26
26/* 27/*
28 * The max size that a non-root user is allowed to grow the pipe. Can
29 * be set by root in /proc/sys/fs/pipe-max-pages
30 */
31unsigned int pipe_max_pages = PIPE_DEF_BUFFERS * 16;
32
33/*
27 * We use a start+len construction, which provides full use of the 34 * We use a start+len construction, which provides full use of the
28 * allocated memory. 35 * allocated memory.
29 * -- Florian Coosmann (FGC) 36 * -- Florian Coosmann (FGC)
@@ -1162,6 +1169,14 @@ long pipe_fcntl(struct file *file, unsigned int cmd, unsigned long arg)
1162 1169
1163 switch (cmd) { 1170 switch (cmd) {
1164 case F_SETPIPE_SZ: 1171 case F_SETPIPE_SZ:
1172 if (!capable(CAP_SYS_ADMIN) && arg > pipe_max_pages)
1173 return -EINVAL;
1174 /*
1175 * The pipe needs to be at least 2 pages large to
1176 * guarantee POSIX behaviour.
1177 */
1178 if (arg < 2)
1179 return -EINVAL;
1165 ret = pipe_set_size(pipe, arg); 1180 ret = pipe_set_size(pipe, arg);
1166 break; 1181 break;
1167 case F_GETPIPE_SZ: 1182 case F_GETPIPE_SZ: