]> www.infradead.org Git - users/jedix/linux-maple.git/commit
pipe: limit the per-user amount of pages allocated in pipes
authorWilly Tarreau <w@1wt.eu>
Mon, 18 Jan 2016 15:36:09 +0000 (16:36 +0100)
committerChuck Anderson <chuck.anderson@oracle.com>
Fri, 10 Jun 2016 22:06:13 +0000 (15:06 -0700)
commit758c75731d8bf3c2255698788a589d561f2c5161
tree599203f35d925b08ede5d2768be3a88d7b84963e
parent0c8ecee92c2241adf9ca910aa42ef0112913b817
pipe: limit the per-user amount of pages allocated in pipes

Add fix for Kabi breakage for pipe: limit the per-user amount of pages
allocated in pipes

On no-so-small systems, it is possible for a single process to cause an
OOM condition by filling large pipes with data that are never read. A
typical process filling 4000 pipes with 1 MB of data will use 4 GB of
memory. On small systems it may be tricky to set the pipe max size to
prevent this from happening.

This patch makes it possible to enforce a per-user soft limit above
which new pipes will be limited to a single page, effectively limiting
them to 4 kB each, as well as a hard limit above which no new pipes may
be created for this user. This has the effect of protecting the system
against memory abuse without hurting other users, and still allowing
pipes to work correctly though with less data at once.

The limit are controlled by two new sysctls : pipe-user-pages-soft, and
pipe-user-pages-hard. Both may be disabled by setting them to zero. The
default soft limit allows the default number of FDs per process (1024)
to create pipes of the default size (64kB), thus reaching a limit of 64MB
before starting to create only smaller pipes. With 256 processes limited
to 1024 FDs each, this results in 1024*64kB + (256*1024 - 1024) * 4kB =
1084 MB of memory allocated for a user. The hard limit is disabled by
default to avoid breaking existing applications that make intensive use
of pipes (eg: for splicing).

Reported-by: socketpair@gmail.com
Reported-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Orabug: 22901731
CVE: CVE-2016-2847

Signed-off-by: Manjunath Govindashetty <manjunath.govindashetty@oracle.com>
(cherry picked from commit f3145594d3e30092cc3a5b70ed57b72722626d2f)
mainline v4.5 commit 759c01142a5d0f364a462346168a56de28a80f52:
pipe: limit the per-user amount of pages allocated in pipes

Need pre-req commit 0c8ecee92c2241adf9ca910aa42ef0112913b817
  add user_struct element unix_inflight pre-req for "pipe: limit the per-user
due to a merge conflict with master:
  c057264c4ba7ddf9d775c013fcb1cecb910bf2b9
  fix kABI breakage from "unix: properly account for FDs passed over unix sock
Signed-off-by: Chuck Anderson <chuck.anderson@oracle.com>
Documentation/sysctl/fs.txt
fs/pipe.c
include/linux/pipe_fs_i.h
include/linux/sched.h
kernel/sysctl.c