Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp912878rwb; Thu, 8 Dec 2022 04:42:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf4bRFjkMkuG1YBaKfnY20yar6liRhDj+dpQtIcTBjkuaZ4KuYgcltUiSofku0ujCjHFnRCc X-Received: by 2002:a05:6402:5505:b0:45c:835b:8fb5 with SMTP id fi5-20020a056402550500b0045c835b8fb5mr2063596edb.32.1670503335349; Thu, 08 Dec 2022 04:42:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670503335; cv=none; d=google.com; s=arc-20160816; b=o088An5uTmTuXtCqHPuk6NIR/jOQBMsNX1F/ZUkx5G1dDZnpx8K8Vw5be44gersrB8 HXRbmZroTpp1sJQMZ9ZdRnYsJ+8Q5BpQc2PfbbiYzs0LfRX6gWYacszHdxZDGVUpNl3H CE9OJT2bkH4m8cRXPT0oO0fLqjIzUXv2o3DgdtBvlUjJYqJjJmaE6RrHidp8QsENsL5f 7SifZ6qLbUeRyj82bP1PrO//l6CaE4KLZhWagmKnxtqztZra1LtFEhAOYUSUvgklpFQE cp9feHXWBL2fBhMuHyupognf0iGWPGmz8zEu91zAQg1rtV+iP+EVDShU+rzvj883rwiW QVTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:subject:message-id:date:from:mime-version :dkim-signature; bh=PukXWO5SmT2z9VgFFF86WSApelvOrN04uHodxuaqNzQ=; b=W++oQNqk11DbSJtw5Dke+xwjQg9WdIg7tTEfW6RBqKu7bgVpBzh9GM8Oy6V1iorS/3 WjtZAsj0dUP6uW6wjxFgi3iBHsgh71opKv6wpHRSmr9EDzNVZA4BwD9zaEfHoAc2hwvm gkllTQJ5u7sMh2Y4NJQrDBs2s4jbWqsbxWb/i2agRZFkEssgwXoK3Wacisp2Ux3xj0ZP 3QT4MIEkCSBhBGAUOqIp9wD6buA7jbh6nxvE5SHgyeavBITkpO+7xDdT5XpW3FK04Ifx vjfQUTu5tZEqFd1VMuzl77tmQMMdaFCl9J9nGgV9pxQbFc5kKzMFmIygjOE47gwp1/1b oy4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RUrsS1eS; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u15-20020a05640207cf00b004615c5728e8si5988265edy.494.2022.12.08.04.41.45; Thu, 08 Dec 2022 04:42:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RUrsS1eS; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229558AbiLHM2C (ORCPT + 99 others); Thu, 8 Dec 2022 07:28:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229523AbiLHM2B (ORCPT ); Thu, 8 Dec 2022 07:28:01 -0500 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F8DA1FCC0; Thu, 8 Dec 2022 04:27:59 -0800 (PST) Received: by mail-ej1-x62d.google.com with SMTP id vv4so3485875ejc.2; Thu, 08 Dec 2022 04:27:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=PukXWO5SmT2z9VgFFF86WSApelvOrN04uHodxuaqNzQ=; b=RUrsS1eSXdzkcS5OdrG26WOFGQ/H4oCfgPOjYUjLX/MksZcRQS3jUDpC8fTLpaDTtG bfAz9JqkLj0QqKh+U6huajL3oTQjMt8hCcIFAMd+l9dasIwbUOpZQ7X0yaj4j3ckEpPJ rKu9SBMPEGx3zL9s4myPkjQ1W2ibseB3kSyrr4yUUqw2pEGS9ylF47qKS4EQYameCsdc oi4yT8GeS0cKY0++86xfY37motW4GkAoScKyafv5Lc0HP/sxFKHmSWw4ouCVhIF4Pw3H A5rN1ib31xuXvXx2s5HuUfILIadJZRVriTF+kGbLPSDTiC1Ur9M9bRW6aWPUbi3lBOhm LkCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=PukXWO5SmT2z9VgFFF86WSApelvOrN04uHodxuaqNzQ=; b=lwGnjgkmuYF3TGlp77yC44elEExokp9kSqCEvZsPW5hrvlZ67CUD2Ram0D2x6zolxI eupDybBYLdZ6lqNjOgSPzkZ2Jqfwa3ESBKx/AVTvRLtak+kiTcaMN3QJ1o4VTcW7ZCHy ukZOe/PkNZYKlWcC8Ebvpx5gID2jHKyo4cV487hXEBZO/e9Z35XKGMgWo3OI7fZJNGeO f84hV9yTzqD9TYcfkx2SfrjFAVQZ/InTetZhl61oadY60TSkjTTNFOFyNRjVJQEaS64Z y07aq1oYptpN58SogNMdhENzCiXcpCUl6aDN2HTQJToD8x7VAIQ4mYdNcucT5fdrLwyH fttA== X-Gm-Message-State: ANoB5pkD90RyLqaL0Yzsb9dnv1qtu43yvS0fq+lG4TahCW85RR3Z9RM9 wS1p/dd5nDvS3B2XOevIPc8/yD0XrMLrCqs1/U4= X-Received: by 2002:a17:906:ce44:b0:7c0:e81a:5564 with SMTP id se4-20020a170906ce4400b007c0e81a5564mr15868079ejb.421.1670502477858; Thu, 08 Dec 2022 04:27:57 -0800 (PST) MIME-Version: 1.0 From: Wei Chen Date: Thu, 8 Dec 2022 20:27:24 +0800 Message-ID: Subject: divide error in mb_update_avg_fragment_size To: tytso@mit.edu, adilger.kernel@dilger.ca, syzbot , linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Dear Linux Developers, Recently, when using our tool to fuzz kernel, the following crash was triggered. HEAD commit: 147307c69ba git tree: linux-next compiler: clang 12.0.0 console output: https://drive.google.com/file/d/1tComytzKYQKzKfiS1PwrKBLQJwZn4usl/view?usp=share_link kernel config: https://drive.google.com/file/d/1NAf4S43d9VOKD52xbrqw-PUP1Mbj8z-S/view?usp=share_link Unfortunately, I didn't have a reproducer for this crash. When calling ioctl with command FITRIM, the variable grp->bb_fragments is zero, thus leading to divide error when executing grp->bb_free / grp->bb_fragments. I'm wondering if a sanity check is missing when handling malicious disk image. IMPORTANT: if you fix the bug, please add the following tag to the commit: Reported-by: Wei Chen divide error: 0000 [#1] PREEMPT SMP CPU: 0 PID: 8874 Comm: syz-executor.0 Not tainted 6.1.0-rc5-next-20221118 #2 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.13.0-48-gd9c812dda519-prebuilt.qemu.org 04/01/2014 RIP: 0010:mb_update_avg_fragment_size+0x84/0x2e0 fs/ext4/mballoc.c:835 Code: 41 5f 5d c3 49 8d 7e 14 e8 a9 38 ca ff 41 8b 5e 14 31 ff 89 de e8 ac d3 b6 ff 85 db 74 61 49 8d 7e 18 e8 8f 38 ca ff 89 d8 99 <41> f7 7e 18 89 44 24 14 bb ff ff ff ff 0f bd 5c 24 14 8d 73 ff 45 RSP: 0018:ffffc90001bf3a60 EFLAGS: 00010246 RAX: 0000000000000456 RBX: 0000000000000456 RCX: ffffffff8170e251 RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffff88810204e018 RBP: ffff8881030de800 R08: 000188810204e01b R09: 0000000000000000 R10: 0001ffffffffffff R11: 000188810204e020 R12: 0000000000008000 R13: ffff88810315b000 R14: ffff88810204e000 R15: ffffc90001bf3cc0 FS: 00007f4a1db97700(0000) GS:ffff88813bc00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 000055ebcf207bd0 CR3: 0000000131681000 CR4: 00000000003506f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000600 Call Trace: mb_mark_used+0xb5c/0xcc0 fs/ext4/mballoc.c:1958 ext4_trim_extent+0xd4/0x340 fs/ext4/mballoc.c:6352 ext4_try_to_trim_range+0x194/0x460 fs/ext4/mballoc.c:6382 ext4_trim_all_free+0x26e/0x3d0 fs/ext4/mballoc.c:6444 ext4_trim_fs+0x56b/0x6d0 fs/ext4/mballoc.c:6540 __ext4_ioctl+0x13b6/0x2990 fs/ext4/ioctl.c:1483 ext4_ioctl+0x1e/0x30 fs/ext4/ioctl.c:1606 vfs_ioctl fs/ioctl.c:51 [inline] __do_sys_ioctl fs/ioctl.c:870 [inline] __se_sys_ioctl+0xcb/0x140 fs/ioctl.c:856 __x64_sys_ioctl+0x3f/0x50 fs/ioctl.c:856 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x2b/0x70 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x63/0xcd RIP: 0033:0x4697f9 Code: f7 d8 64 89 02 b8 ff ff ff ff c3 66 0f 1f 44 00 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 73 01 c3 48 c7 c1 bc ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007f4a1db96c48 EFLAGS: 00000246 ORIG_RAX: 0000000000000010 RAX: ffffffffffffffda RBX: 000000000077bf80 RCX: 00000000004697f9 RDX: 0000000020000040 RSI: 00000000c0185879 RDI: 0000000000000004 RBP: 00000000004d29e9 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 000000000077bf80 R13: 0000000000000000 R14: 000000000077bf80 R15: 00007fffbabb2d30 Modules linked in: ---[ end trace 0000000000000000 ]--- RIP: 0010:mb_update_avg_fragment_size+0x84/0x2e0 fs/ext4/mballoc.c:835 Code: 41 5f 5d c3 49 8d 7e 14 e8 a9 38 ca ff 41 8b 5e 14 31 ff 89 de e8 ac d3 b6 ff 85 db 74 61 49 8d 7e 18 e8 8f 38 ca ff 89 d8 99 <41> f7 7e 18 89 44 24 14 bb ff ff ff ff 0f bd 5c 24 14 8d 73 ff 45 RSP: 0018:ffffc90001bf3a60 EFLAGS: 00010246 RAX: 0000000000000456 RBX: 0000000000000456 RCX: ffffffff8170e251 RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffff88810204e018 RBP: ffff8881030de800 R08: 000188810204e01b R09: 0000000000000000 R10: 0001ffffffffffff R11: 000188810204e020 R12: 0000000000008000 R13: ffff88810315b000 R14: ffff88810204e000 R15: ffffc90001bf3cc0 FS: 00007f4a1db97700(0000) GS:ffff88813bc00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 000055ebcf207bd0 CR3: 0000000131681000 CR4: 00000000003506f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000600 ---------------- Code disassembly (best guess): 0: 41 5f pop %r15 2: 5d pop %rbp 3: c3 retq 4: 49 8d 7e 14 lea 0x14(%r14),%rdi 8: e8 a9 38 ca ff callq 0xffca38b6 d: 41 8b 5e 14 mov 0x14(%r14),%ebx 11: 31 ff xor %edi,%edi 13: 89 de mov %ebx,%esi 15: e8 ac d3 b6 ff callq 0xffb6d3c6 1a: 85 db test %ebx,%ebx 1c: 74 61 je 0x7f 1e: 49 8d 7e 18 lea 0x18(%r14),%rdi 22: e8 8f 38 ca ff callq 0xffca38b6 27: 89 d8 mov %ebx,%eax 29: 99 cltd * 2a: 41 f7 7e 18 idivl 0x18(%r14) <-- trapping instruction 2e: 89 44 24 14 mov %eax,0x14(%rsp) 32: bb ff ff ff ff mov $0xffffffff,%ebx 37: 0f bd 5c 24 14 bsr 0x14(%rsp),%ebx 3c: 8d 73 ff lea -0x1(%rbx),%esi 3f: 45 rex.RB Best, Wei