]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
4.4-stable patches
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 10 Aug 2021 15:00:02 +0000 (17:00 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 10 Aug 2021 15:00:02 +0000 (17:00 +0200)
added patches:
pipe-increase-minimum-default-pipe-size-to-2-pages.patch

queue-4.4/pipe-increase-minimum-default-pipe-size-to-2-pages.patch [new file with mode: 0644]
queue-4.4/series

diff --git a/queue-4.4/pipe-increase-minimum-default-pipe-size-to-2-pages.patch b/queue-4.4/pipe-increase-minimum-default-pipe-size-to-2-pages.patch
new file mode 100644 (file)
index 0000000..fd1f46f
--- /dev/null
@@ -0,0 +1,74 @@
+From 46c4c9d1beb7f5b4cec4dd90e7728720583ee348 Mon Sep 17 00:00:00 2001
+From: "Alex Xu (Hello71)" <alex_y_xu@yahoo.ca>
+Date: Thu, 5 Aug 2021 10:40:47 -0400
+Subject: pipe: increase minimum default pipe size to 2 pages
+
+From: Alex Xu (Hello71) <alex_y_xu@yahoo.ca>
+
+commit 46c4c9d1beb7f5b4cec4dd90e7728720583ee348 upstream.
+
+This program always prints 4096 and hangs before the patch, and always
+prints 8192 and exits successfully after:
+
+  int main()
+  {
+      int pipefd[2];
+      for (int i = 0; i < 1025; i++)
+          if (pipe(pipefd) == -1)
+              return 1;
+      size_t bufsz = fcntl(pipefd[1], F_GETPIPE_SZ);
+      printf("%zd\n", bufsz);
+      char *buf = calloc(bufsz, 1);
+      write(pipefd[1], buf, bufsz);
+      read(pipefd[0], buf, bufsz-1);
+      write(pipefd[1], buf, 1);
+  }
+
+Note that you may need to increase your RLIMIT_NOFILE before running the
+program.
+
+Fixes: 759c01142a ("pipe: limit the per-user amount of pages allocated in pipes")
+Cc: <stable@vger.kernel.org>
+Link: https://lore.kernel.org/lkml/1628086770.5rn8p04n6j.none@localhost/
+Link: https://lore.kernel.org/lkml/1628127094.lxxn016tj7.none@localhost/
+Signed-off-by: Alex Xu (Hello71) <alex_y_xu@yahoo.ca>
+Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ fs/pipe.c |   17 ++++++++++++++++-
+ 1 file changed, 16 insertions(+), 1 deletion(-)
+
+--- a/fs/pipe.c
++++ b/fs/pipe.c
+@@ -28,6 +28,21 @@
+ #include "internal.h"
+ /*
++ * New pipe buffers will be restricted to this size while the user is exceeding
++ * their pipe buffer quota. The general pipe use case needs at least two
++ * buffers: one for data yet to be read, and one for new data. If this is less
++ * than two, then a write to a non-empty pipe may block even if the pipe is not
++ * full. This can occur with GNU make jobserver or similar uses of pipes as
++ * semaphores: multiple processes may be waiting to write tokens back to the
++ * pipe before reading tokens: https://lore.kernel.org/lkml/1628086770.5rn8p04n6j.none@localhost/.
++ *
++ * Users can reduce their pipe buffers with F_SETPIPE_SZ below this at their
++ * own risk, namely: pipe writes to non-full pipes may block until the pipe is
++ * emptied.
++ */
++#define PIPE_MIN_DEF_BUFFERS 2
++
++/*
+  * 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-size
+  */
+@@ -621,7 +636,7 @@ struct pipe_inode_info *alloc_pipe_info(
+               if (!too_many_pipe_buffers_hard(user)) {
+                       if (too_many_pipe_buffers_soft(user))
+-                              pipe_bufs = 1;
++                              pipe_bufs = PIPE_MIN_DEF_BUFFERS;
+                       pipe->bufs = kzalloc(sizeof(struct pipe_buffer) * pipe_bufs, GFP_KERNEL);
+               }
index d85e8ceb969a4b6e97189e0a679d104769b12de6..a014007392a1ae6a87ef5ebda3eed3ff3b6ce1c5 100644 (file)
@@ -19,3 +19,4 @@ reiserfs-add-check-for-root_inode-in-reiserfs_fill_s.patch
 reiserfs-check-directory-items-on-read-from-disk.patch
 alpha-send-stop-ipi-to-send-to-online-cpus.patch
 net-qla3xxx-fix-schedule-while-atomic-in-ql_wait_for.patch
+pipe-increase-minimum-default-pipe-size-to-2-pages.patch