[REGRESSION?] Simultaneous writes to a reader-less, non-full pipe can hang
Linus Torvalds
torvalds at linux-foundation.org
Wed Aug 4 20:04:24 UTC 2021
On Wed, Aug 4, 2021 at 12:48 PM Alex Xu (Hello71) <alex_y_xu at yahoo.ca> wrote:
>
> I agree that if this only affects programs which intentionally adjust
> the pipe buffer size, then it is not a huge issue. The problem,
> admittedly buried very close to the bottom of my email, is that the
> kernel will silently provide one-page pipe buffers if the user has
> exceeded 16384 (by default) pipe buffer pages allocated.
That's a good point.
That "fall back to a single buffer" case is meant to make things
hobble along if the user has exhausted the pipe buffers, but you're
right that we might want to make that minimum be two buffers.
I didn't test this, but the obvious fix seems to be just increasing
the '1' to '2'.
@@ -781,8 +784,8 @@ struct pipe_inode_info *alloc_pipe_info(void)
user_bufs = account_pipe_buffers(user, 0, pipe_bufs);
if (too_many_pipe_buffers_soft(user_bufs) &&
pipe_is_unprivileged_user()) {
- user_bufs = account_pipe_buffers(user, pipe_bufs, 1);
- pipe_bufs = 1;
+ user_bufs = account_pipe_buffers(user, pipe_bufs, 2);
+ pipe_bufs = 2;
}
if (too_many_pipe_buffers_hard(user_bufs) &&
pipe_is_unprivileged_user())
although a real patch would need a comment about how a single buffer
is problematic, and probably make the '2' be a #define to not just
repeat the same magic constant silently.
IOW, something like
/*
* The general pipe use case needs at least two buffers: one
* for data yet to be read, and one for new data
*/
#define DEF_MIN_PIPE_BUFFERS 2
to go with the existing PIPE_DEF_BUFFERS (although the
DEF_MIN_PIPE_BUFFERS use would only be in fs/pipe.c, so I guess it
doesn't actually need to be exposed to anybody else in the pipe.h
header file).
I'd take that patch with some proper testing and a commit message.
Hint hint ;)
Linus
More information about the Linux-security-module-archive
mailing list