From: Joe Lawrence <joe.lawrence@redhat.com>
To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
"Luis R. Rodriguez" <mcgrof@kernel.org>,
Kees Cook <keescook@chromium.org>,
Mikulas Patocka <mpatocka@redhat.com>,
Michael Kerrisk <mtk.manpages@gmail.com>
Subject: [PATCH RFC 0/3] A few round_pipe_size() and pipe-max-size fixups
Date: Tue, 5 Sep 2017 10:44:33 -0400 [thread overview]
Message-ID: <1504622676-2992-1-git-send-email-joe.lawrence@redhat.com> (raw)
While backporting Michael's "pipe: fix limit handling" [1] patchset to a
distro-kernel, Mikulas noticed that current upstream pipe limit handling
contains a few problems:
1 - round_pipe_size() nr_pages overflow on 32bit: this would
subsequently try roundup_pow_of_two(0), which is undefined.
2 - visible non-rounded pipe-max-size value: there is no mutual
exclusion or protection between the time pipe_max_size is assigned
a raw value from proc_dointvec_minmax() and when it is rounded.
3 - procfs signed wrap: echo'ing a large number into
/proc/sys/fs/pipe-max-size and then cat'ing it back out shows a
negative value.
This RFC serves as a bug report and a contains a few possible fixes.
There may be better / more consistent ways to fix the overflows and
procfs bugs, but I figured I'd throw an RFC w/code out there for initial
conversation. Suggestions welcome!
-- Joe
Testing
=======
Patch 1 - 32bit overflow
------------------------
>From userspace:
fcntl(fd, F_SETPIPE_SZ, 0xffffffff);
- Before the fix, return value was 4096 as pipe size overflowed and
was set to 4096
- After the fix, returns -1 and sets errno EINVAL, pipe size remains
untouched
Patch 2 - non-rounded pipe-max-size value
-----------------------------------------
Keep plugging in values that need to be rounded:
while (true); do echo 1048570 > /proc/sys/fs/pipe-max-size; done
and in another terminal, loop around reading the value:
time (while (true); do SIZE=$(cat /proc/sys/fs/pipe-max-size); [[ $(( $SIZE % 4096 )) -ne 0 ]] && break; done; echo "$SIZE")
1048570
real 0m46.213s
user 0m29.688s
sys 0m20.042s
after the fix, the test loop never encountered a non-page-rounded value.
Patch 3 - procfs signed wrap
----------------------------
Before:
% echo 2147483647 >/proc/sys/fs/pipe-max-size
% cat /proc/sys/fs/pipe-max-size
-2147483648
After:
% echo 2147483647 >/proc/sys/fs/pipe-max-size
% cat /proc/sys/fs/pipe-max-size
2147483648
Joe Lawrence (3):
pipe: avoid round_pipe_size() nr_pages overflow on 32-bit
pipe: protect pipe_max_size access with a mutex
pipe: match pipe_max_size data type with procfs
fs/pipe.c | 48 +++++++++++++++++++++++++++++++++++++++++-------
kernel/sysctl.c | 2 +-
2 files changed, 42 insertions(+), 8 deletions(-)
--
1.8.3.1
next reply other threads:[~2017-09-05 14:44 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-05 14:44 Joe Lawrence [this message]
2017-09-05 14:44 ` [PATCH RFC 1/3] pipe: avoid round_pipe_size() nr_pages overflow on 32-bit Joe Lawrence
2017-09-05 14:44 ` [PATCH RFC 2/3] pipe: protect pipe_max_size access with a mutex Joe Lawrence
2017-09-14 23:09 ` Mikulas Patocka
2017-09-15 14:08 ` Joe Lawrence
2017-09-19 7:53 ` Mikulas Patocka
2017-09-19 21:32 ` Joe Lawrence
2017-09-21 10:05 ` Mikulas Patocka
2017-09-19 21:47 ` Joe Lawrence
2017-09-25 10:44 ` Mikulas Patocka
2017-09-05 14:44 ` [PATCH RFC 3/3] pipe: match pipe_max_size data type with procfs Joe Lawrence
2017-09-14 13:26 ` [PATCH RFC 0/3] A few round_pipe_size() and pipe-max-size fixups Michael Kerrisk (man-pages)
2017-09-14 16:57 ` Randy Dunlap
2017-09-14 19:19 ` Joe Lawrence
2017-09-14 20:22 ` Randy Dunlap
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1504622676-2992-1-git-send-email-joe.lawrence@redhat.com \
--to=joe.lawrence@redhat.com \
--cc=keescook@chromium.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=mpatocka@redhat.com \
--cc=mtk.manpages@gmail.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®