Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp2546402rwo; Sun, 23 Jul 2023 18:36:27 -0700 (PDT) X-Google-Smtp-Source: APBJJlGgH1wBpo/vpEpVQAbP2Ue0gpJi9BL/xWZTydxfI3ZDdWNFGDkpaY7TPn0U9OR0EvHu8jej X-Received: by 2002:a17:907:7791:b0:992:ef60:aae0 with SMTP id ky17-20020a170907779100b00992ef60aae0mr9641079ejc.54.1690162587713; Sun, 23 Jul 2023 18:36:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690162587; cv=none; d=google.com; s=arc-20160816; b=zTEB41KLrzj4jt+qELPlc14oR+G7L7VBi+UhCo/6LRoVargVMVz/vmjxfaqe766Kco cwb3LI5mMJcIo4VvcwmHOSDKK1i+0lMK0CRppFohkFoe992lKgT8WdZAlRZOp80P8GoJ NBN8oCVBQDDC7GkqIquDh0PDxpnqHbm8aW5qkUi4+qEe4B/SzBoMKgihDhu4Ek0LFbrC gtg7wuRgbm6+hDd6z4cvK5qLoyvTtgTK4pGGaGIMwg2xTnP258RP+xJnaw5bbTkyf6jy xLmmMpIwZlmaAXB54YFZB8MRkO9q+8wna+OIDdVC2j82yQT70MRE/dibhvuYJDn4q4vg t9kA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4jcgcAMvTpVTF3vAlG6YDNsmyTA4kEuOHVk1TQhmLFA=; fh=UqmF1nHXQoOevb82hG9/S+snDXObdO/svH0IGC2kb0w=; b=Q1AhxS7h8gh5aZM/Fue7sack2R6E9hLoJjSAT96EenOa+gHrVHcT6EutOH+gpXnxUv FgFJTyyPch+BWLJ1+Cw22QMBX4YvWhl18+MypHNNvNy39cPVtUCtsD10MXR6hnGtK/mL q6lnb/JSyLXgYSuPAB8ULMWVO8LmozAWDWmkQSIlvm70DsZYXmff4I1q6Y+9xR53xoP5 5m8+RNn9oQS1pd6Eya1aKvvdc8YqkKxM3Bp0QtIP1bq4u6cJo7LbOhunhHm75HC+wctv So8cXPsannNrYVHe80wD2cs7rTvlvHFgJTDuOlzk8B3HeVcDquErOGI1wCXbbPRrYlPq +2qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Y3Z+YrQP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lt5-20020a170906fa8500b00992ac59b3f2si5383056ejb.585.2023.07.23.18.36.03; Sun, 23 Jul 2023 18:36:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@kernel.org header.s=k20201202 header.b=Y3Z+YrQP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230330AbjGXBWI (ORCPT + 99 others); Sun, 23 Jul 2023 21:22:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230296AbjGXBVy (ORCPT ); Sun, 23 Jul 2023 21:21:54 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 480B710E5; Sun, 23 Jul 2023 18:21:32 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3F60560F14; Mon, 24 Jul 2023 01:21:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55DADC433C8; Mon, 24 Jul 2023 01:21:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690161662; bh=6Lez+mmwfquUjFO+5mlrw7HbkVuGLsekiuVsCPOHhaM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y3Z+YrQPXUSNShSfWvZKjTqUwns7LGeQ8AN2Pgdyz7GGDa/H5awz5tfIBkWnKeqD/ 9IRB5EeLTAMwdtxTBmTVsY/RqNHRDIIyAAocxeOO52prVpTihw3HEBuqw00K7GLFNd 0GYTO04CFY2gemSlahjvHHdTFlrCYyLxvRHgIk+2V6N6fqNljCvxKXuSBQmd+JOBCr jaqQexvHQUvjTe2RoL57rtpWuNqMJSHqWDZndip34Jtc504a5NhENrqfsHsW9rx0o9 LCEP0baYR28OkHoZCHyRJVgwKlaoWnVkZFeEQnYSmGMxcT/t6qwNAGHKo37xiysIGG 6vPZ4HNjahlsA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Yogesh , syzbot+853a6f4dfa3cf37d3aea@syzkaller.appspotmail.com, Dave Kleikamp , Sasha Levin , shaggy@kernel.org, wuhoipok@gmail.com, code@siddh.me, mudongliangabcd@gmail.com, liushixin2@huawei.com, jfs-discussion@lists.sourceforge.net, wonguk.lee1023@gmail.com Subject: [PATCH AUTOSEL 6.4 55/58] fs: jfs: Fix UBSAN: array-index-out-of-bounds in dbAllocDmapLev Date: Sun, 23 Jul 2023 21:13:23 -0400 Message-Id: <20230724011338.2298062-55-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230724011338.2298062-1-sashal@kernel.org> References: <20230724011338.2298062-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.4.5 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-kernel@vger.kernel.org From: Yogesh [ Upstream commit 4e302336d5ca1767a06beee7596a72d3bdc8d983 ] Syzkaller reported the following issue: UBSAN: array-index-out-of-bounds in fs/jfs/jfs_dmap.c:1965:6 index -84 is out of range for type 's8[341]' (aka 'signed char[341]') CPU: 1 PID: 4995 Comm: syz-executor146 Not tainted 6.4.0-rc6-syzkaller-00037-gb6dad5178cea #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 05/27/2023 Call Trace: __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0x1e7/0x2d0 lib/dump_stack.c:106 ubsan_epilogue lib/ubsan.c:217 [inline] __ubsan_handle_out_of_bounds+0x11c/0x150 lib/ubsan.c:348 dbAllocDmapLev+0x3e5/0x430 fs/jfs/jfs_dmap.c:1965 dbAllocCtl+0x113/0x920 fs/jfs/jfs_dmap.c:1809 dbAllocAG+0x28f/0x10b0 fs/jfs/jfs_dmap.c:1350 dbAlloc+0x658/0xca0 fs/jfs/jfs_dmap.c:874 dtSplitUp fs/jfs/jfs_dtree.c:974 [inline] dtInsert+0xda7/0x6b00 fs/jfs/jfs_dtree.c:863 jfs_create+0x7b6/0xbb0 fs/jfs/namei.c:137 lookup_open fs/namei.c:3492 [inline] open_last_lookups fs/namei.c:3560 [inline] path_openat+0x13df/0x3170 fs/namei.c:3788 do_filp_open+0x234/0x490 fs/namei.c:3818 do_sys_openat2+0x13f/0x500 fs/open.c:1356 do_sys_open fs/open.c:1372 [inline] __do_sys_openat fs/open.c:1388 [inline] __se_sys_openat fs/open.c:1383 [inline] __x64_sys_openat+0x247/0x290 fs/open.c:1383 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x63/0xcd RIP: 0033:0x7f1f4e33f7e9 Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 51 14 00 00 90 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 c0 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007ffc21129578 EFLAGS: 00000246 ORIG_RAX: 0000000000000101 RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f1f4e33f7e9 RDX: 000000000000275a RSI: 0000000020000040 RDI: 00000000ffffff9c RBP: 00007f1f4e2ff080 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 00007f1f4e2ff110 R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000 The bug occurs when the dbAllocDmapLev()function attempts to access dp->tree.stree[leafidx + LEAFIND] while the leafidx value is negative. To rectify this, the patch introduces a safeguard within the dbAllocDmapLev() function. A check has been added to verify if leafidx is negative. If it is, the function immediately returns an I/O error, preventing any further execution that could potentially cause harm. Tested via syzbot. Reported-by: syzbot+853a6f4dfa3cf37d3aea@syzkaller.appspotmail.com Link: https://syzkaller.appspot.com/bug?extid=ae2f5a27a07ae44b0f17 Signed-off-by: Yogesh Signed-off-by: Dave Kleikamp Signed-off-by: Sasha Levin --- fs/jfs/jfs_dmap.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/jfs/jfs_dmap.c b/fs/jfs/jfs_dmap.c index a3eb1e8269477..455300d38d315 100644 --- a/fs/jfs/jfs_dmap.c +++ b/fs/jfs/jfs_dmap.c @@ -1953,6 +1953,9 @@ dbAllocDmapLev(struct bmap * bmp, if (dbFindLeaf((dmtree_t *) & dp->tree, l2nb, &leafidx)) return -ENOSPC; + if (leafidx < 0) + return -EIO; + /* determine the block number within the file system corresponding * to the leaf at which free space was found. */ -- 2.39.2