From patchwork Fri Oct 14 09:23:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 9376287 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 420DA6075E for ; Fri, 14 Oct 2016 09:24:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 322F42A561 for ; Fri, 14 Oct 2016 09:24:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2671F2A563; Fri, 14 Oct 2016 09:24:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 47ABB2A561 for ; Fri, 14 Oct 2016 09:24:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753380AbcJNJYd (ORCPT ); Fri, 14 Oct 2016 05:24:33 -0400 Received: from mx2.suse.de ([195.135.220.15]:42204 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752110AbcJNJYW (ORCPT ); Fri, 14 Oct 2016 05:24:22 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id EE73CAC47; Fri, 14 Oct 2016 09:23:43 +0000 (UTC) From: Jiri Slaby To: viro@zeniv.linux.org.uk Cc: linux-kernel@vger.kernel.org, Jiri Slaby , linux-fsdevel@vger.kernel.org Subject: [PATCH] fs: pipe, fix undefined behaviour Date: Fri, 14 Oct 2016 11:23:42 +0200 Message-Id: <20161014092342.25546-2-jslaby@suse.cz> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20161014092342.25546-1-jslaby@suse.cz> References: <20161014092342.25546-1-jslaby@suse.cz> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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: ... [] ? pipe_fcntl+0xa3/0x7a0 [] ? SyS_fcntl+0x930/0xf30 [] ? 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 Cc: Alexander Viro 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; }