]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.4.133/pipe-cap-initial-pipe-capacity-according-to-pipe-max-size-limit.patch
4.14-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.4.133 / pipe-cap-initial-pipe-capacity-according-to-pipe-max-size-limit.patch
1 From 086e774a57fba4695f14383c0818994c0b31da7c Mon Sep 17 00:00:00 2001
2 From: "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com>
3 Date: Tue, 11 Oct 2016 13:53:43 -0700
4 Subject: pipe: cap initial pipe capacity according to pipe-max-size limit
5
6 From: Michael Kerrisk (man-pages) <mtk.manpages@gmail.com>
7
8 commit 086e774a57fba4695f14383c0818994c0b31da7c upstream.
9
10 This is a patch that provides behavior that is more consistent, and
11 probably less surprising to users. I consider the change optional, and
12 welcome opinions about whether it should be applied.
13
14 By default, pipes are created with a capacity of 64 kiB. However,
15 /proc/sys/fs/pipe-max-size may be set smaller than this value. In this
16 scenario, an unprivileged user could thus create a pipe whose initial
17 capacity exceeds the limit. Therefore, it seems logical to cap the
18 initial pipe capacity according to the value of pipe-max-size.
19
20 The test program shown earlier in this patch series can be used to
21 demonstrate the effect of the change brought about with this patch:
22
23 # cat /proc/sys/fs/pipe-max-size
24 1048576
25 # sudo -u mtk ./test_F_SETPIPE_SZ 1
26 Initial pipe capacity: 65536
27 # echo 10000 > /proc/sys/fs/pipe-max-size
28 # cat /proc/sys/fs/pipe-max-size
29 16384
30 # sudo -u mtk ./test_F_SETPIPE_SZ 1
31 Initial pipe capacity: 16384
32 # ./test_F_SETPIPE_SZ 1
33 Initial pipe capacity: 65536
34
35 The last two executions of 'test_F_SETPIPE_SZ' show that pipe-max-size
36 caps the initial allocation for a new pipe for unprivileged users, but
37 not for privileged users.
38
39 Link: http://lkml.kernel.org/r/31dc7064-2a17-9c5b-1df1-4e3012ee992c@gmail.com
40 Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
41 Reviewed-by: Vegard Nossum <vegard.nossum@oracle.com>
42 Cc: Willy Tarreau <w@1wt.eu>
43 Cc: <socketpair@gmail.com>
44 Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
45 Cc: Jens Axboe <axboe@fb.com>
46 Cc: Al Viro <viro@zeniv.linux.org.uk>
47 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
48 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
49 Signed-off-by: Daniel Sangorrin <daniel.sangorrin@toshiba.co.jp>
50 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
51
52 ---
53 fs/pipe.c | 3 +++
54 1 file changed, 3 insertions(+)
55
56 --- a/fs/pipe.c
57 +++ b/fs/pipe.c
58 @@ -616,6 +616,9 @@ struct pipe_inode_info *alloc_pipe_info(
59 unsigned long pipe_bufs = PIPE_DEF_BUFFERS;
60 struct user_struct *user = get_current_user();
61
62 + if (pipe_bufs * PAGE_SIZE > pipe_max_size && !capable(CAP_SYS_RESOURCE))
63 + pipe_bufs = pipe_max_size >> PAGE_SHIFT;
64 +
65 if (!too_many_pipe_buffers_hard(user)) {
66 if (too_many_pipe_buffers_soft(user))
67 pipe_bufs = 1;