From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.178 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796548979; b=g9mcbS7OnK/4PoSUydmG7BmhLoXvIZfMBRA9AxRzNhdBNq6S1Sq2CP1mA7+jTpKcAmFv 9Q++YR/h0vRpEHsfPgxtlTgqxE37J9nc3demIIpWGHBVFRJKJtXbaTyonRy4FdL6dbcC7 cnfe6wgH73e6t7yHUoSka1VLALgbNR7jPfXY2ny4vGj6PknOJm0R52D/yYq6CfBbgd/Ha s6QAoTuDGKfjVIrgu0uaL8YGBQ+XylK0D1PVL3lWYMMTUooTLARNYG+zsPWLvsIRduTIi hxen0eb7szYk4Kl1Ui+WIyb7uJ7oWkR+hjk5twz5zLQMEvfZfgrI3ERxp6+hG0VqmaQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796548979; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=s5lU8QE4XGGw5GZBFpfsc09vNVivI1gF2tgNN/R6MBQ=; b=1cxAHW4eeONXeKkpMLSMmzMYQSCiQW9k15oKtnIMVEEl3pj0frpjJpki5yvkrEEy85T1 ZwCkuvCaeqAwNaV9R9KOSdB7Alxa4EYGIbE83LtvnxLNeVJvXcWunLqC2eigJbf0cZR8z HAq9/cG/I7QEXNAQIiNTwRjFhcq+KIjNw2mwOVWtoUyr/7psljKL7Q/2tiZ/yCgRQ6WL5 vY8djFTU2Q3Eq03yraFVpScrs7LteMg0cOQahYIKclQ1rZPNN81ZB2xxODfNkDq5NFyT2 kgay6/sTXlJ4KoQ0er4rHPu/O3EiwxTI4DxQEgCvgWRLO/kLQZevk3hgizgGnY6jICw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=iiitd.ac.in; spf=pass smtp.mailfrom=iiitd.ac.in; dkim=pass header.d=iiitd.ac.in header.i=@iiitd.ac.in header.a=rsa-sha256 header.s=google header.b="aghKY/BQ"; arc=none smtp.remote-ip=74.125.82.178 Received: from mail-dy1-f178.google.com (mail-dy1-f178.google.com [74.125.82.178]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E797B606A31F for ; Sun, 6 Dec 2026 09:22:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E797B606A31F Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iiitd.ac.in Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iiitd.ac.in Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=iiitd.ac.in header.i=@iiitd.ac.in header.a=rsa-sha256 header.s=google header.b=aghKY/BQ Received: by mail-dy1-f178.google.com with SMTP id 5a478bee46e88-387486ad5abso3892188eec.0 for ; Sun, 06 Dec 2026 01:22:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iiitd.ac.in; s=google; t=1796548978; x=1797153778; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=s5lU8QE4XGGw5GZBFpfsc09vNVivI1gF2tgNN/R6MBQ=; b=aghKY/BQk6oQsYdoGuQWpaDW2vAvKj1KWNfLsX+cjRcMTjXryn9gtO/6Ccg6sWFuXH 1fBQu92k2+eDCEeAD9k/pZDPFlqRkcECuhFgnax6qKSh9lvqZvgdZmeDlE+D1f/MNLHO tyzBRL3Gx6BvFwNKmKQgrEU3zghtscJO5PeuM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796548978; x=1797153778; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=s5lU8QE4XGGw5GZBFpfsc09vNVivI1gF2tgNN/R6MBQ=; b=PlZsYZx+HI+zQL3hPBWTMVkBqNxk1E7Jx6GweUVsBY6nSddYU3BSsHzzTC4WDuEeHw I06HVHiySwoVpqw9/Sul3p3DLrQETJ7RkGLNAKtzheQryGA1q8zsrFyaG1SjYSsy5rQD y5/7hd3CoU5LnEYuvM8FNWaTGm8b5gw0R8sSMVBjiTLsO9zwgn8BSf1BEDXjMHiixBBX lChvefZKcXuXMqt4X7CIdzUdRPAK/Q6pkKSm4R+QnwcCg5WvC6ikhu8rMTFLSdifWeA0 oT60tADyBLzATYMOcAPV57kvn08Ixg8pfVrN3nQ5mXzLAN4Hco5NSU9Cp+HJVJInwSUA B/3A== X-Forwarded-Encrypted: i=1; AL+hErGI72/9PS5gN6WwRRsJnTFvEE1MRIn6Oc68s32yIGrlEiZn/zK7d1QZmq+rSe1BVghRr9lNC4CVMkuvg+A=@vger.kernel.org X-Gm-Message-State: AB4q+uGkC0jD0c3IFWOpy/pVyhXnmMW5iY0LvnoNNU0zyHtZ4ssP8oEQ Vn76aU68gakB9562QCe8UsC2Ry+HqmSjFLbmenEtrDb5i/g05Hc3W/fOJWHdE1INR/w= X-Gm-Gg: AZFdTZdwG+SdGqJkpvnApo+O044anPoumeHwfJwT+3zLK70exJFoyQR/po1Bg95enw5 Lmcd1Q0dqCguCZZmvyEBxhpoxY5gJxcXkYE4ijHBiUeQrrPrNvUGQAStb0CDXdOdcBPQGi+JLHL SvWxh29ioFSwEv4U37W4/J0Eni7Hk3ujHFzhO8KJ3Q2eyuzQVJDHfi+SEs+qiji2zNZv+UgH8Ja Hbb9v/IwR2sEapIA7fRmUJPn5hwWg1SzJI+n6BKWLILA6FS5Hl6kMv8bNfOMQuHmGFETgE4BCU+ XzZl34ku/BEBG3tc+CoEEpYcC0uSQZxsmKWbqWSLyjOnRi+uwCF5R6m/bUpAil9AEoXY9xj3vms tClzR+G45JRfPFbOL9y4W61RLLnphGGQAPALNoFTNvms1lxu3pRJYWHglVTagpYa2xrCgDfrB2p onzCAo26S7AEooN0+HJNiUTMHHwYtkgMVGVOYC6xqWvU8Q735dG4k9DEhQw1JVWwsbDXC0GPvQs 5JLKADTJVXlDZvSVJ7ipx/Iii8zlcmXgH16oMSEGrBNQfhGwIOeDp71ONBljwnNP/2E4joC4BXw 1eGIhZQD8exxu7QejPNkRjf3TCHj3Q18/QSzzjjMwvyn3qDpHT25EeOkFjofPYfG8laUCpiCxmw 3UH61OIfrOx3C3jf7zPnWneVlXZclZjtw4P0drzu/UaXf14gDg+vsdsQFPLjojuv0 X-Received: by 2002:a05:7301:da82:b0:386:b950:6ed with SMTP id 5a478bee46e88-38752229b9fmr7026728eec.38.1796548977879; Sun, 06 Dec 2026 01:22:57 -0800 (PST) Received: from iiitd-S2600STB.iiitd.edu.in ([103.25.231.160]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-387521c17a3sm31711485eec.11.2026.12.06.01.22.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Dec 2026 01:22:57 -0800 (PST) From: Piyus Kedia To: Carlos Maiolino , linux-xfs@vger.kernel.org Cc: "Darrick J . Wong" , Aldo Ariel Panzardo , linux-kernel@vger.kernel.org, Kapil Vaswani Subject: [BUG] xfs: log recovery copies a logged fork root by its own record count, into a fork sized by an unchecked di_forkoff Date: Sun, 6 Dec 2026 14:52:52 +0530 Message-Id: X-Mailer: git-send-email 2.34.1 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Hi, When log recovery replays an inode whose data or attr fork root was logged (XFS_ILOG_DBROOT, XFS_ILOG_ABROOT), it converts the logged incore root into the inode with xfs_bmbt_to_bmdr(), which copies as many keys and pointers as the logged root says it has: fs/xfs/libxfs/xfs_bmap_btree.c:170 (xfs_bmbt_to_bmdr) dmxr = xfs_bmdr_maxrecs(dblocklen, 0); fkp = xfs_bmbt_key_addr(mp, rblock, 1); tkp = xfs_bmdr_key_addr(dblock, 1); fpp = xfs_bmap_broot_ptr_addr(mp, rblock, 1, rblocklen); tpp = xfs_bmdr_ptr_addr(dblock, 1, dmxr); dmxr = be16_to_cpu(dblock->bb_numrecs); memcpy(tkp, fkp, sizeof(*fkp) * dmxr); memcpy(tpp, fpp, sizeof(*fpp) * dmxr); rblock is the log region, which xlog_recover_add_to_trans() allocates at the length the log gives it, and rblocklen that length; dblock is the fork in the inode buffer and dblocklen its size. The two lengths only place the pointer arrays. Nothing on the way compares bb_numrecs with either: not xlog_recover_inode_commit_pass2(), and not xfs_dinode_verify(), which runs on the inode after the copy. xfs_rtrmapbt_to_disk() and xfs_rtrefcountbt_to_disk(), which replay the root of a realtime rmap or refcount btree inode (xlog_recover_inode_dbroot()), copy their count unchecked the same way. 9232301894a0 ("xfs: bound inode fork length against the fork size during log recovery") bounded the DDATA/DEXT and ADATA/AEXT copies of the same function and left these two: its message says "The XFS_ILOG_DBROOT sibling already passes XFS_DFORK_DSIZE as a bound", and its comment (xfs_inode_item_recover.c:514) "The DBROOT/ABROOT cases already bound their copies against the fork size". They pass the fork size, but the length they copy is bb_numrecs. And the fork size itself comes from the logged inode, whose di_forkoff xfs_log_dinode_to_disk() copies in before the forks are replayed. The one check on it fs/xfs/xfs_inode_item_recover.c:465 (xlog_recover_inode_commit_pass2) if (unlikely(ldip->di_forkoff > mp->m_sb.sb_inodesize)) { compares a count of 8-byte units with a size in bytes, so with 512-byte inodes no value fails it. xfs_dinode_verify_forkoff() would reject a di_forkoff past the literal area, but only after the copy. Our fuzzer found the first of the following; we found the others while working out what the copy writes. All were run on the upstream base named below. 1. The count The fuzzer made a file with a btree data fork on a 4 KiB-block V5 filesystem with 512-byte inodes, forced the log out with XFS_IOC_GOINGDOWN(LOGFLUSH), set bb_numrecs of the logged root (an 88-byte region, one record) to 200, recomputed the record CRC and mounted the image. The inode was logged with di_forkoff 24: a 192-byte data fork, room for a root of 11 records. BUG: KASAN: slab-out-of-bounds in xfs_bmbt_to_bmdr (fs/xfs/libxfs/xfs_bmap_btree.c:176) Read of size 1600 at addr ffff88804ad9a6c8 by task x/9442 __asan_memcpy (mm/kasan/shadow.c:105) xfs_bmbt_to_bmdr (fs/xfs/libxfs/xfs_bmap_btree.c:176) xlog_recover_inode_commit_pass2 (fs/xfs/xfs_inode_item_recover.c:284 fs/xfs/xfs_inode_item_recover.c:536) xlog_recover_items_pass2 (fs/xfs/xfs_log_recover.c:2020) xlog_recover_commit_trans (fs/xfs/xfs_log_recover.c:2089) ... xlog_recover (fs/xfs/xfs_log_recover.c:3506) xfs_log_mount (fs/xfs/xfs_log.c:621) xfs_mountfs (fs/xfs/xfs_mount.c:1051) xfs_fs_fill_super (fs/xfs/xfs_super.c:1987) ... __x64_sys_mount (fs/namespace.c:4350 ...) The buggy address is located 72 bytes inside of allocated 88-byte region [ffff88804ad9a680, ffff88804ad9a6d8) (kmalloc-96, allocated by xlog_recover_add_to_trans(), fs/xfs/xfs_log_recover.c:2209) With kasan_multi_shot the pointers' memcpy() (:177, a tail call, so the report names the caller) is reported too: a read of size 1600 from 80 bytes into the same region. The same edit of a logged attr fork root (XFS_ILOG_ABROOT, xfs_inode_item_recover.c:573) gives the same two reads. The two copies write as much as they read: 8 * N bytes from 4 bytes into the fork and 8 * N from 4 + 8 * 11 = 92 bytes in, so past the 192-byte fork from N = 13 and past the inode's 336 bytes of forks from N = 31. KASAN does not report those writes, because __asan_memcpy() gives up on the read before it checks the write; but it reports only the first bad access of a boot, and lets the later ones through, which shows what they do: - N = 200: after the one report, the other copies (the first root's pointers, and both copies of the two roots logged after it) each write 1600 bytes of kmalloc-96 memory over the rest of /f's inode and into the three inodes after it in the buffer. At the end of recovery the buffer fails its write verifier, which dumps the next inode, kernel addresses (ffff8880..., ffffffff8...) and all; the filesystem shuts down and the mount fails with EUCLEAN. Nothing reaches the disk. The fuzzer's crash on 7.4-rc5 ended the same way. - N = 20, which stays inside the inode: the mount succeeds, and /f's inode goes to disk with 109 bytes changed, against 57 when the count is left at 1; the extra bytes are what the copies read past the region, from its neighbours in kmalloc-96. We did not identify those objects. The next iget of /f fails in xfs_iformat_btree() ("corrupt inode 8323 (btree)"). - N = 200 with /f the last inode of its buffer, in a boot where KASAN had already reported once: the keys' copy runs off the end of the buffer. To make that end visible we also set ilf_len of the logged inode items of that cluster to 24 basic blocks, so the 12 KiB buffer is vmalloc()ed (xfs_buf_alloc_backing_mem()) and followed by a guard page: BUG: unable to handle page fault for address: ffffc90002fcc000 #PF: supervisor write access in kernel mode #PF: error_code(0x0002) - not-present page Oops: Oops: 0002 [#1] SMP KASAN PTI RIP: 0010:memcpy_orig+0x2c/0x140 xfs_bmbt_to_bmdr (fs/xfs/libxfs/xfs_bmap_btree.c:176) xlog_recover_inode_commit_pass2 (fs/xfs/xfs_inode_item_recover.c:284 fs/xfs/xfs_inode_item_recover.c:536) ... Kernel panic - not syncing: Fatal exception 2. The fork offset With the root left as logged (one record, which fits both the region and the real fork) and di_forkoff set to 255 in the logged inode, the data fork is taken to be 2040 bytes, room for a root of 127 records, so the pointer is written 4 + 8 * 127 = 1020 bytes into the fork, past the inode. With /f last in a 12 KiB buffer as above: BUG: KASAN: vmalloc-out-of-bounds in xlog_recover_inode_commit_pass2 (fs/xfs/xfs_inode_item_recover.c:284 fs/xfs/xfs_inode_item_recover.c:536) Write of size 8 at addr ffffc900031142ac by task poc/9483 __asan_memcpy (mm/kasan/shadow.c:106) xlog_recover_inode_commit_pass2 (...) The buggy address belongs to a 3-page vmalloc region starting at 0xffffc90003111000 allocated at xfs_buf_alloc+0x8ba/0xff0 684 bytes past the end of the buffer. The same di_forkoff starts the attr fork 2040 bytes into the inode with a size of XFS_LITINO(mp) - 2040 computed in size_t, so the ADATA/AEXT check that 9232301894a0 added passes for any length. /f with four extents and a 16-byte xattr (logged with DEXT and ADATA), di_forkoff 255: BUG: KASAN: vmalloc-out-of-bounds in xlog_recover_inode_commit_pass2 (fs/xfs/xfs_inode_item_recover.c:568) Write of size 24 at addr ffffc90002fc46a8 by task poc/9509 1704 bytes past the end of the buffer. In both cases the recovered inode then fails xfs_dinode_verify() and the mount fails with EUCLEAN; the write has been done by then. 3. Not run: xfs_rtrmapbt_to_disk() and xfs_rtrefcountbt_to_disk() copy the logged root of a metadir rtrmap or rtrefcount inode by its bb_numrecs the same way, 48 or 12 bytes per record at level > 0 and 24 or 12 at level 0. We could not make such a filesystem here (the VM image has no mkfs.xfs; the host's xfsprogs, 5.13.0, predates metadir), so this is from the source only. Impact - who can trigger it: - A crafted XFS image with a dirty log has to be mounted, and nothing more: everything above happens inside mount(2), in log recovery, before the filesystem is usable. XFS is not FS_USERNS_MOUNT, so mount(2) needs CAP_SYS_ADMIN in the initial user namespace: root, or a service that mounts on a user's behalf. We have not tested whether desktop auto-mounting of removable media mounts such an image. We mounted read-write and did not try a read-only mount. - The log needs no forgery beyond the edited fields: the record CRC, which the image's author recomputes, is all that guards them. - What is read: for a count N (at most 65535), 8 * N bytes from 72 bytes into the logged root and 8 * N from where its pointers start (80 bytes in, for the 88-byte root), so up to about 512 KiB past a kmalloc() buffer of the root's size. The neighbouring slab objects are what gets read. - What is written: the same bytes into the inode buffer, from 4 and from 4 + 8 * (the fork's root capacity) bytes into the fork. We measured them landing over the next inodes of the buffer (and, with N = 20, in the inode written to disk), and running off the end of a vmalloc()ed buffer into its guard page. With di_forkoff 255, a root that fits writes its pointers up to 1020 + 8 * (records) bytes into the data fork, and an ADATA or AEXT region, of bytes the image chooses, is written 2040 bytes into it; both are past a 512-byte inode. An inode buffer of the usual 16 KiB is a folio (xfs_buf_alloc_backing_mem()), so for the last inodes of a cluster these writes go into whatever page follows; we did not look at what that could be made to do. - What a kernel without KASAN does: we have no non-KASAN build in this rig. In the runs above where KASAN had stopped reporting, the copies were carried out as such a kernel carries them out; that is as far as we measured. Seen on 7.4.0-rc5 (two reports, the 88-byte root with N = 200) and REPRODUCED ON UPSTREAM: on ksmbd-for-next (d70570cf8003, 2026-12-04), our upstream base, whose fs/xfs is identical to mainline master (9437ee8b6cf6), with KASAN. xfs_inode_item_recover.c, xfs_bmap_btree.c and xfs_rtrmap_btree.c are also unchanged in mainline c3500c5ef648 (2026-12-04) and in xfs-linux for-next (ab1a77ab136c); xfs_rtrefcount_btree.c differs in those two only in xfs_rtrefcountbt_broot_realloc(). Same config and images before and after, the patch the only change: without the patch count, data fork a KASAN read in xfs_bmbt_to_bmdr() in 6 of 6 boots: the fuzzer's program unchanged, ours with N = 200 four times and N = 20 once; with KASAN no longer reporting and /f last in a vmalloc()ed buffer, N = 200 ran off its end (1 boot, an oops) count, attr fork the same reads in 2 of 2 boots di_forkoff 255 a KASAN write past the inode buffer, the root's pointer in 2 of 2 boots and the ADATA copy in 2 of 2 with the patch (kasan_multi_shot on): no KASAN report and no oops in 5 boots, each running every trigger above (the first also the fuzzer's program). The mount fails with EUCLEAN, and the kernel logs, for the count: XFS (loop0): Internal error Bad log dinode fork root (-117) at line 319 of file fs/xfs/xfs_inode_item_recover.c. ... XFS (loop0): Bad inode 0x2083, data fork root of 88 bytes with 200 records, fork size 192 ("attr fork root ... fork size 144" for the attr fork), and for di_forkoff 255: XFS (loop0): Internal error Bad log dinode fork offset (-117) at line 529 of file fs/xfs/xfs_inode_item_recover.c. ... XFS (loop0): Bad inode 0x2097, di_forkoff 0xff then "log mount/recovery failed: error -117". controls, the log as written (count 1, di_forkoff 24), CRCs still recomputed: both kernels recover the log and mount, /f stats, and no KASAN report or XFS error, in 4 boots on the base and 5 on the fixed kernel. A patch follows in reply to this mail. It checks the logged di_forkoff against the literal area, as xfs_dinode_verify_forkoff() does for the recovered inode, and checks a logged root's record count against both its region and the fork it goes into (bmbt, rtrmap and rtrefcount roots, data and attr fork) before anything is copied, failing recovery with -EFSCORRUPTED and a corruption report. The checks are in log recovery, next to 9232301894a0's, rather than in xfs_bmbt_to_bmdr() and the rt helpers, which the inode flush path also uses, with roots the kernel built itself. This was found by AI-driven fuzzing built on top of syzkaller; its analysis was then checked by hand against the code, and every access above was reproduced, except the rtrmap and rtrefcount copies, which we have from the source only. The reproducer is one program that carries its filesystem image, and we are happy to send it on request. Kapil Vaswani Piyus Kedia