Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1500786 > unrolled thread
| Started by | Jiri Slaby <jslaby@suse.cz> |
|---|---|
| First post | 2016-10-14 11:30 +0200 |
| Last post | 2016-10-14 12:00 +0200 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH] fs: pipe, fix undefined behaviour Jiri Slaby <jslaby@suse.cz> - 2016-10-14 11:30 +0200
Re: [PATCH] fs: pipe, fix undefined behaviour Vegard Nossum <vegard.nossum@gmail.com> - 2016-10-14 12:00 +0200
| From | Jiri Slaby <jslaby@suse.cz> |
|---|---|
| Date | 2016-10-14 11:30 +0200 |
| Subject | [PATCH] fs: pipe, fix undefined behaviour |
| Message-ID | <ss6Yp-7QI-5@gated-at.bofh.it> |
echo | ./program
where ./program contains fcntl(0, F_SETPIPE_SZ, 0) this is triggered:
UBSAN: Undefined behaviour in ../include/linux/log2.h:63:13
shift exponent 64 is too large for 64-bit type 'long unsigned int'
CPU: 3 PID: 4978 Comm: syz-executor Not tainted 4.8.1-0-syzkaller #1
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.9.1-0-gb3ef39f-prebuilt.qemu-project.org 04/01/2014
...
Call Trace:
...
[<ffffffffa18ced53>] ? pipe_fcntl+0xa3/0x7a0
[<ffffffffa18f1940>] ? SyS_fcntl+0x930/0xf30
[<ffffffffa2d1fb00>] ? entry_SYSCALL_64_fastpath+0x23/0xc1
Documentaion of roundup_pow_of_two explicitly mentions that passing
size 0 is undefined. So return 0 from round_pipe_size prematurely to
fix this.
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org
---
fs/pipe.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/fs/pipe.c b/fs/pipe.c
index 8e0d9f26dfad..23c0c06ffc33 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -1024,6 +1024,9 @@ static inline unsigned int round_pipe_size(unsigned int size)
{
unsigned long nr_pages;
+ if (!size)
+ return 0;
+
nr_pages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
return roundup_pow_of_two(nr_pages) << PAGE_SHIFT;
}
--
2.10.1
[toc] | [next] | [standalone]
| From | Vegard Nossum <vegard.nossum@gmail.com> |
|---|---|
| Date | 2016-10-14 12:00 +0200 |
| Message-ID | <ss7rr-810-3@gated-at.bofh.it> |
| In reply to | #1500786 |
On 14 October 2016 at 11:23, Jiri Slaby <jslaby@suse.cz> wrote:
> echo | ./program
> where ./program contains fcntl(0, F_SETPIPE_SZ, 0) this is triggered:
> UBSAN: Undefined behaviour in ../include/linux/log2.h:63:13
> shift exponent 64 is too large for 64-bit type 'long unsigned int'
> CPU: 3 PID: 4978 Comm: syz-executor Not tainted 4.8.1-0-syzkaller #1
> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.9.1-0-gb3ef39f-prebuilt.qemu-project.org 04/01/2014
> ...
> Call Trace:
> ...
> [<ffffffffa18ced53>] ? pipe_fcntl+0xa3/0x7a0
> [<ffffffffa18f1940>] ? SyS_fcntl+0x930/0xf30
> [<ffffffffa2d1fb00>] ? entry_SYSCALL_64_fastpath+0x23/0xc1
>
> Documentaion of roundup_pow_of_two explicitly mentions that passing
> size 0 is undefined. So return 0 from round_pipe_size prematurely to
> fix this.
>
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> Cc: linux-fsdevel@vger.kernel.org
> ---
> fs/pipe.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/fs/pipe.c b/fs/pipe.c
> index 8e0d9f26dfad..23c0c06ffc33 100644
> --- a/fs/pipe.c
> +++ b/fs/pipe.c
> @@ -1024,6 +1024,9 @@ static inline unsigned int round_pipe_size(unsigned int size)
> {
> unsigned long nr_pages;
>
> + if (!size)
> + return 0;
> +
> nr_pages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
> return roundup_pow_of_two(nr_pages) << PAGE_SHIFT;
> }
Just FYI I sent a patch for this earlier with a bit more analysis,
although it probably no longer applies cleanly:
https://lkml.org/lkml/2016/8/12/215
Personally I felt it was cleaner to limit the argument passed to
round_pipe_size() instead of relying on the implicit long -> int
truncation. Anyway, feel free to crib from the patch and/or changelog.
Vegard
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web