In the Linux kernel, the following vulnerability has been resolved:
fs: jfs: Fix UBSAN: array-index-out-of-bounds in dbAllocDmapLev
Syzkaller reported the following issue:
UBSAN: array-index-out-of-bounds in fs/jfs/jfsdmap.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: <TASK> _dumpstack lib/dumpstack.c:88 [inline] dumpstacklvl+0x1e7/0x2d0 lib/dumpstack.c:106 ubsanepilogue lib/ubsan.c:217 [inline] _ubsanhandleoutofbounds+0x11c/0x150 lib/ubsan.c:348 dbAllocDmapLev+0x3e5/0x430 fs/jfs/jfsdmap.c:1965 dbAllocCtl+0x113/0x920 fs/jfs/jfsdmap.c:1809 dbAllocAG+0x28f/0x10b0 fs/jfs/jfsdmap.c:1350 dbAlloc+0x658/0xca0 fs/jfs/jfsdmap.c:874 dtSplitUp fs/jfs/jfsdtree.c:974 [inline] dtInsert+0xda7/0x6b00 fs/jfs/jfsdtree.c:863 jfscreate+0x7b6/0xbb0 fs/jfs/namei.c:137 lookupopen fs/namei.c:3492 [inline] openlastlookups fs/namei.c:3560 [inline] pathopenat+0x13df/0x3170 fs/namei.c:3788 dofilpopen+0x234/0x490 fs/namei.c:3818 dosysopenat2+0x13f/0x500 fs/open.c:1356 dosysopen fs/open.c:1372 [inline] _dosysopenat fs/open.c:1388 [inline] _sesysopenat fs/open.c:1383 [inline] _x64sysopenat+0x247/0x290 fs/open.c:1383 dosyscallx64 arch/x86/entry/common.c:50 [inline] dosyscall64+0x41/0xc0 arch/x86/entry/common.c:80 entrySYSCALL64afterhwframe+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 ORIGRAX: 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 </TASK>
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.
[ { "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@4e302336d5ca1767a06beee7596a72d3bdc8d983", "target": { "function": "dbAllocDmapLev", "file": "fs/jfs/jfs_dmap.c" }, "signature_version": "v1", "deprecated": false, "digest": { "function_hash": "310388106046913334335747376675214699340", "length": 525.0 }, "id": "CVE-2023-53485-09a988e0", "signature_type": "Function" }, { "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@39f6292d75959e8accac0b3e24090094ba0824e9", "target": { "file": "fs/jfs/jfs_dmap.c" }, "signature_version": "v1", "deprecated": false, "digest": { "line_hashes": [ "304447747632047469714027018740474322702", "35391737706430323357657569122015990019", "25534661260378124244520027338913790301" ], "threshold": 0.9 }, "id": "CVE-2023-53485-0f901c9d", "signature_type": "Line" }, { "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@4e302336d5ca1767a06beee7596a72d3bdc8d983", "target": { "file": "fs/jfs/jfs_dmap.c" }, "signature_version": "v1", "deprecated": false, "digest": { "line_hashes": [ "304447747632047469714027018740474322702", "35391737706430323357657569122015990019", "25534661260378124244520027338913790301" ], "threshold": 0.9 }, "id": "CVE-2023-53485-9f608c30", "signature_type": "Line" }, { "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@39f6292d75959e8accac0b3e24090094ba0824e9", "target": { "function": "dbAllocDmapLev", "file": "fs/jfs/jfs_dmap.c" }, "signature_version": "v1", "deprecated": false, "digest": { "function_hash": "310388106046913334335747376675214699340", "length": 525.0 }, "id": "CVE-2023-53485-f219c5f0", "signature_type": "Function" } ]