Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2846678imm; Tue, 4 Sep 2018 10:56:44 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZq5HsYOVI9v6A1zJbVdXa5LUicQ29RJKGUAnygLmmf6NcSFd1BXSMNyHFdtnw7GfPYoVF9 X-Received: by 2002:a63:10c:: with SMTP id 12-v6mr32134107pgb.62.1536083804223; Tue, 04 Sep 2018 10:56:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536083804; cv=none; d=google.com; s=arc-20160816; b=IfjDv7Kmdt/w+HtyiqrLDYzImKa0y6dB41FnZdnEktNUPjepp7THa8aRty9CfAcs5w GowgNEs273h8PFenY3kuIVoLt8eL8nVlC8BPtZpRE2yW8c4p1REz2xrUfmSVmYH9k0wA MMDdfgQO0Y7eGywkZ5GnhnuL2scMOQQ/eUNJghrGXEMYx+s0vUocamqXUeTADIYqQAJJ /PZVnugwf3U4ymC7nKhFIznMdl9c6csomxYF61BYf1F+LlybhNGgGCuxY4o4jCoABYcq sloSDKU3jl1PqJ11GEeOyJSRv7OKrY9t4KD+Gab9X8SlfZbeq5chVKziF5pWTxaN5xf8 KrQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=lfoea8LSSlIaamVDrdlIwHUpP+wIjjOrIkYLNMhEM54=; b=dog8yrhhjgmpiRimeSV3lQpp6oXftn+1adqxThy9Tw3+FY3YFn3j70XV9wyEQdrqn+ o7DSh8cRLsDk9qJ92OKlRDPYUloJxOqueAroLbkNHXvlMgyFFBB1ARCEhEFqMvb9TK9X boPHu+1ONiTR1m0t1wfH3w098U9hwLE7DMxLkKUNydzhffJlXOYtLVViLxtdQT7MoeY1 d0BtSItSMu49MWoYoPP6x4jxtCD2GgAnOMXgV9Zml/A8fH+NxIREns40V0vB/qcTj21K 1xv4xAwg8M7l7P+ij00s5jeZF2toXovK4D/pj9JYeWYPKsjh114pX2J2qgx/QhZ6TAxb aQOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=PPLCNqVg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 4-v6si20929388pgp.645.2018.09.04.10.56.28; Tue, 04 Sep 2018 10:56:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=PPLCNqVg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727551AbeIDWVZ (ORCPT + 99 others); Tue, 4 Sep 2018 18:21:25 -0400 Received: from mail-io0-f195.google.com ([209.85.223.195]:42886 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726749AbeIDWVY (ORCPT ); Tue, 4 Sep 2018 18:21:24 -0400 Received: by mail-io0-f195.google.com with SMTP id n18-v6so3733537ioa.9 for ; Tue, 04 Sep 2018 10:55:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=lfoea8LSSlIaamVDrdlIwHUpP+wIjjOrIkYLNMhEM54=; b=PPLCNqVgSX2rWA3g8vwMUgwzFVO+dWdugloiN2HKQQVlVsGYyg6DuVKMP/JSErTL0+ XF9oVoMD9xlFQGYK3jrja0tMUxeAlLF12O4rRUJ3COBaRjQVZf3pmm+G9cJLL/TTMybz QqI99MICIBPkaOoMVzKtok7/Ut5q3qADwKsZGhGkIr+WOHfmX0Ei7B2CfHEl1UBaBI9O e7v3IYu8w/hRoaxkdOWay3ad6LMTylLfcdvEn64xG0mz1UKXwfbKLpt5V7Ebjz7PHfZ9 SkLBCKr/eeDTUbBJUBVK0ENfXZL4W7m1UEzhvTnYzSx0AmbTymlcJL64stv0hQTnbC67 Dc9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=lfoea8LSSlIaamVDrdlIwHUpP+wIjjOrIkYLNMhEM54=; b=JRChuccEJQC4CXR5gKWY7n7tK6MryYdzecpRSpZ6E2kcYe+/xxgVT6gOA9LtTLdHB+ G9IVLhCu/6a53Qwf2DfzsqKchk969SkT2jinZ+r4iX3+Re2CJ/g0X1/qao7Y2xe13h/u /fZlbmJSBH7HNZVj+y2/JGPgV1QD5Cg+mtKpV71aUcEbBj+RIZqjOgcPm3vWaXcHk3Uz Av8hqeniTeUZ+kimNf2lMb08epReRxdzdERu4BgV2fh/qgUGJH7v/Syi+bxQCW2RZ84n RyNtNtg9EWvW+lp1Bk6QoRczDSEqXbY4362y8OkdQAGpDh4s9DGBVwrY1P0EmGuUzbtb aACA== X-Gm-Message-State: APzg51ArGG9K+6WhWttvmd6Izk9ROIgEGr9zQZM8vuxzK0w3evgGVihq QX+pyNEx7rS7MD8ftgM1tyoLsA== X-Received: by 2002:a6b:b445:: with SMTP id d66-v6mr22913613iof.163.1536083713590; Tue, 04 Sep 2018 10:55:13 -0700 (PDT) Received: from [192.168.1.56] ([216.160.245.98]) by smtp.gmail.com with ESMTPSA id m126-v6sm8714105ioa.79.2018.09.04.10.55.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 10:55:12 -0700 (PDT) Subject: Re: divide error in nbd_ioctl To: Josef Bacik Cc: syzbot , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, nbd@other.debian.org, syzkaller-bugs@googlegroups.com References: <0000000000006105bf057506ebb9@google.com> <20180904174810.gp7bd5s3kijhjp5d@destiny> From: Jens Axboe Message-ID: <9571a094-a87f-e6dd-2bdf-f9b4ea500ca9@kernel.dk> Date: Tue, 4 Sep 2018 11:55:11 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: <20180904174810.gp7bd5s3kijhjp5d@destiny> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/4/18 11:48 AM, Josef Bacik wrote: > On Tue, Sep 04, 2018 at 09:07:37AM -0600, Jens Axboe wrote: >> On 9/4/18 1:51 AM, syzbot wrote: >>> Hello, >>> >>> syzbot found the following crash on: >>> >>> HEAD commit: 217c3e019675 disable stringop truncation warnings for now >>> git tree: upstream >>> console output: https://syzkaller.appspot.com/x/log.txt?x=13665da6400000 >>> kernel config: https://syzkaller.appspot.com/x/.config?x=531a917630d2a492 >>> dashboard link: https://syzkaller.appspot.com/bug?extid=25dbecbec1e62c6b0dd4 >>> compiler: gcc (GCC) 8.0.1 20180413 (experimental) >>> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=163e910a400000 >>> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=169dfe0a400000 >>> >>> IMPORTANT: if you fix the bug, please add the following tag to the commit: >>> Reported-by: syzbot+25dbecbec1e62c6b0dd4@syzkaller.appspotmail.com >>> >>> random: sshd: uninitialized urandom read (32 bytes read) >>> random: sshd: uninitialized urandom read (32 bytes read) >>> random: sshd: uninitialized urandom read (32 bytes read) >>> random: sshd: uninitialized urandom read (32 bytes read) >>> random: sshd: uninitialized urandom read (32 bytes read) >>> divide error: 0000 [#1] SMP KASAN >>> CPU: 0 PID: 4667 Comm: syz-executor024 Not tainted 4.19.0-rc1+ #216 >>> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS >>> Google 01/01/2011 >>> RIP: 0010:div_s64_rem include/linux/math64.h:41 [inline] >>> RIP: 0010:div_s64 include/linux/math64.h:139 [inline] >>> RIP: 0010:__nbd_ioctl drivers/block/nbd.c:1242 [inline] >>> RIP: 0010:nbd_ioctl+0x53c/0xcf0 drivers/block/nbd.c:1303 >>> Code: ea 03 80 3c 02 00 0f 85 1c 07 00 00 48 8b b5 c0 fe ff ff 48 63 8d b8 >>> fe ff ff 48 8b 86 c8 00 00 00 48 8d be c0 00 00 00 48 99 <48> f7 f9 48 ba >>> 00 00 00 00 00 fc ff df 48 89 f9 48 c1 e9 03 80 3c >>> RSP: 0018:ffff8801c90bf828 EFLAGS: 00010246 >>> RAX: 0000000000000000 RBX: 0000000000000001 RCX: 0000000000000000 >>> RDX: 0000000000000000 RSI: ffff8801ccb23c00 RDI: ffff8801ccb23cc0 >>> RBP: ffff8801c90bf9a0 R08: ffff8801bc502640 R09: ffffed003a62d01d >>> R10: ffff8801c90bf818 R11: ffff8801d31680ef R12: ffff8801d3168000 >>> R13: 00000000ffffffe7 R14: ffff8801d31680e0 R15: ffff8801d5730840 >>> FS: 00000000015b2880(0000) GS:ffff8801db000000(0000) knlGS:0000000000000000 >>> CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 >>> CR2: 000000000043e560 CR3: 00000001b8034000 CR4: 00000000001406f0 >>> DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 >>> DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 >>> Call Trace: >>> __blkdev_driver_ioctl block/ioctl.c:303 [inline] >>> blkdev_ioctl+0x9cd/0x2030 block/ioctl.c:601 >>> block_ioctl+0xee/0x130 fs/block_dev.c:1883 >>> vfs_ioctl fs/ioctl.c:46 [inline] >>> file_ioctl fs/ioctl.c:501 [inline] >>> do_vfs_ioctl+0x1de/0x1720 fs/ioctl.c:685 >>> ksys_ioctl+0xa9/0xd0 fs/ioctl.c:702 >>> __do_sys_ioctl fs/ioctl.c:709 [inline] >>> __se_sys_ioctl fs/ioctl.c:707 [inline] >>> __x64_sys_ioctl+0x73/0xb0 fs/ioctl.c:707 >>> do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290 >>> entry_SYSCALL_64_after_hwframe+0x49/0xbe >>> RIP: 0033:0x443d29 >>> Code: 18 89 d0 c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 00 48 89 f8 48 89 f7 >>> 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff >>> ff 0f 83 7b d8 fb ff c3 66 2e 0f 1f 84 00 00 00 00 >>> RSP: 002b:00007ffe343644d8 EFLAGS: 00000213 ORIG_RAX: 0000000000000010 >>> RAX: ffffffffffffffda RBX: 00000000004002e0 RCX: 0000000000443d29 >>> RDX: 0000000000000000 RSI: 000000000000ab01 RDI: 0000000000000003 >>> RBP: 00000000006ce018 R08: 0000000000000000 R09: 00000000004002e0 >>> R10: 000000000000000f R11: 0000000000000213 R12: 0000000000401a30 >>> R13: 0000000000401ac0 R14: 0000000000000000 R15: 0000000000000000 >>> Modules linked in: >>> Dumping ftrace buffer: >>> (ftrace buffer empty) >>> ---[ end trace 25c60c4714d4e2ee ]--- >>> RIP: 0010:div_s64_rem include/linux/math64.h:41 [inline] >>> RIP: 0010:div_s64 include/linux/math64.h:139 [inline] >>> RIP: 0010:__nbd_ioctl drivers/block/nbd.c:1242 [inline] >>> RIP: 0010:nbd_ioctl+0x53c/0xcf0 drivers/block/nbd.c:1303 >>> Code: ea 03 80 3c 02 00 0f 85 1c 07 00 00 48 8b b5 c0 fe ff ff 48 63 8d b8 >>> fe ff ff 48 8b 86 c8 00 00 00 48 8d be c0 00 00 00 48 99 <48> f7 f9 48 ba >>> 00 00 00 00 00 fc ff df 48 89 f9 48 c1 e9 03 80 3c >>> RSP: 0018:ffff8801c90bf828 EFLAGS: 00010246 >>> RAX: 0000000000000000 RBX: 0000000000000001 RCX: 0000000000000000 >>> RDX: 0000000000000000 RSI: ffff8801ccb23c00 RDI: ffff8801ccb23cc0 >>> RBP: ffff8801c90bf9a0 R08: ffff8801bc502640 R09: ffffed003a62d01d >>> R10: ffff8801c90bf818 R11: ffff8801d31680ef R12: ffff8801d3168000 >>> R13: 00000000ffffffe7 R14: ffff8801d31680e0 R15: ffff8801d5730840 >>> FS: 00000000015b2880(0000) GS:ffff8801db000000(0000) knlGS:0000000000000000 >>> CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 >>> CR2: 000000000043e560 CR3: 00000001b8034000 CR4: 00000000001406f0 >>> DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 >>> DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 >> >> Looks like NBD_SET_BLKSIZE is happy to just take whatever value. >> We should ensure that it's a power of 2, not zero, and bigger >> or equal than 512, but smaller or equal to PAGE_SIZE. Something >> like this? >> >> >> diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c >> index 3863c00372bb..14a51254c3db 100644 >> --- a/drivers/block/nbd.c >> +++ b/drivers/block/nbd.c >> @@ -1239,6 +1239,9 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd, >> case NBD_SET_SOCK: >> return nbd_add_socket(nbd, arg, false); >> case NBD_SET_BLKSIZE: >> + if (!arg || !is_power_of_2(arg) || arg < 512 || >> + arg > PAGE_SIZE) >> + return -EINVAL; >> nbd_size_set(nbd, arg, >> div_s64(config->bytesize, arg)); >> return 0; > > Thanks Jens, you can add > > Reviewed-by: Josef Bacik Thanks, applied for 4.19. -- Jens Axboe