Linux filesystem development
 help / color / mirror / Atom feed
From: Jiri Slaby <jslaby@suse.cz>
To: viro@zeniv.linux.org.uk
Cc: linux-kernel@vger.kernel.org, Jiri Slaby <jslaby@suse.cz>,
	linux-fsdevel@vger.kernel.org
Subject: [PATCH] fs: pipe, fix undefined behaviour
Date: Fri, 14 Oct 2016 11:23:42 +0200	[thread overview]
Message-ID: <20161014092342.25546-2-jslaby@suse.cz> (raw)
In-Reply-To: <20161014092342.25546-1-jslaby@suse.cz>

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

  reply	other threads:[~2016-10-14  9:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-14  9:23 [PATCH] fs: fcntl, avoid undefined behaviour Jiri Slaby
2016-10-14  9:23 ` Jiri Slaby [this message]
2016-10-14  9:57   ` [PATCH] fs: pipe, fix " Vegard Nossum
2016-10-14 11:48 ` [PATCH] fs: fcntl, avoid " Jeff Layton
2016-10-14 13:38   ` J. Bruce Fields
2016-10-24  9:15     ` Jiri Slaby
2016-10-24 11:29       ` Jeff Layton
2016-10-24 11:34         ` Jiri Slaby
2017-06-12  5:03 ` zhong jiang
2017-06-13  9:29   ` Jiri Slaby
2017-06-13 10:02     ` zhong jiang

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=20161014092342.25546-2-jslaby@suse.cz \
    --to=jslaby@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --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