From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.170 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796560899; b=5QfNae1gg9OJqIX42AI6MNxHv9fzDE2LIAJI/gSaqJYlxama5ExPMYtOyqUbuZ5QbaEp EHqO2IycGtBRRMy2h/bYrAYBVrK1VpG3j1gA0/kgwOCPi4bUc6+mK8iEwzNkxTRp9Go9/ nHjP469rszcK6QQVgfe1RW5hJsMWsMqMWRFcY9qgSSj6ESreCWC2Rrt0uKiIwEvB4lKSA EuUadmLrgzXBwPiIaEXem3WOFKNxAaHq1sfjiNRjEOZXr2n9obJqib3EvVpA/zzVH4ld1 xOLZWTIzPsV8x6KI6Li8JGPGqQ9tFaH98fdBDocqb4IomW08Sj5xsJyaii51CwEJICQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796560899; 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=3gkULCcYd+3gsR6CX9U1MSJxadwdgMt1ucQbe+SIdm0=; b=fAxLTgdafK8F6a7FX2yUArg3uxC70g41FpqmjBeL7xS+I7BURiou7QDHtqW9maQHNzZV YDhDZPiMMxMDQ16L5F3DjVciM/Cmv8GI+L/WqNJXTJMVFuKhKdJS39SwDmQxuPqvTl01r 06nsp3Lb+oGlIeFWm/noD0KKH4rLwouB+j+XqpY6RLvaSuKctpqFBlIbzkjOebjJAI1mj SViqd+ahozt/Sy1uf5F61sKXjE5bkYAELr2o4US+kacdB6WryjT4Niz65LJxSb1ltwn/S wigIKoiQM2CElfSiT73BK2lXRNPl9yh2JfQxyOMm9cHrXHPgy/Q4M6XDXCQ0U2bfEIg== 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=NyvzmT4t; arc=none smtp.remote-ip=74.125.82.170 Received: from mail-dy1-f170.google.com (mail-dy1-f170.google.com [74.125.82.170]) (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 8A254606A321 for ; Sun, 6 Dec 2026 12:41:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8A254606A321 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=NyvzmT4t Received: by mail-dy1-f170.google.com with SMTP id 5a478bee46e88-385d8a00598so3445643eec.1 for ; Sun, 06 Dec 2026 04:41:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iiitd.ac.in; s=google; t=1796560897; x=1797165697; 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=3gkULCcYd+3gsR6CX9U1MSJxadwdgMt1ucQbe+SIdm0=; b=NyvzmT4tltIfL/IsTAbgwTLDyYiM0H5dxzUrwL4XLnemcGpXzDkRkwI4rO1kAIpMWu ZKD5qGw4vA1hIvOuGxbOzPOvlVRs3eZFn7Zc1q7ZScn4BFNta/jGOEOw+PrNqteqEVSl PJoQeEYjG2zBKCgoQnHjF/1uCq1Cp94QW5h6M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796560897; x=1797165697; 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=3gkULCcYd+3gsR6CX9U1MSJxadwdgMt1ucQbe+SIdm0=; b=rb37r9p+vf/wR6g3kGA7ybhDAtR19YyaggpwcAKB+CS8SNiKrqJIUmMMbEEoi4IsK/ 7QYenr9RvoVcRbDCoFmTDWCCrfrblbsJtlryxpD3aIG9a6G7uFfT1P3jgfgWt1w6CdXY HcfckjVFFCcLEpHY9ArJ+Rr7u2G7LBuGXCdKghJ16JVH/Iq1xgXHCWjnSEV6x9XMiZX7 yhEeryfiQAnRU2UDnRMyirJwlgxn0ykqIyfEkoUU+LXXf+saXDE/5pTSlk/ywtPFmE2i sTw2nmrTLPQMjYvcJdmX35WZkZVHn9iMkn3oR5VJXQS935i1vNzen0FBZ0je2AZsFmu5 R7+w== X-Forwarded-Encrypted: i=1; AL+hErH400w5llvSSdWe7QQrrkjrF7E4FGGzdxctqwofKjxfcpq1MPnoD3HtKMTgRyNcUaFSRfprmaaVImUX9xE=@vger.kernel.org X-Gm-Message-State: AB4q+uHFIka4ja5lNkAiv1aJjwrPJmLaNuj38RkfDGCRXhkm0JziAKF0 dMD3xccnbK45qC7S5AW3s7AOCwtuiESHjRjLYxU6aXZs1015RV59a2XegP6MjmDv2PC93S9fRVE hHaY8nPGM7Q== X-Gm-Gg: AZFdTZdFekGuSwOdP/jNDZ5w/rR5N1WomN7952n1jPausOczqZXlJgJOYM0J3oc3jYc bWh0hUdYNsJx99IMDvxNZi6nYdB+K6e4yCq9FgJyoLSpYD9MVj1jPs9ZwC1q7BN7ItQyiPLLvyo FvKJ4ixpxtr4u+HOOJeo4kXMjLQNUCGWeAoBYeo2eZPBNEromPIN9NkT42aw/RTDK87wWGPB4rP krtyj+c+h+0/IOmldC1Rog4J6dHbfjCLbPC633KRxVNe/9y791LDkxB/0NhYiJ4uqFsD1oslWWO JarWTLpkdEpa1MAjX2Sku9FcjzULFOChebHQ9iX3gnjfGiSjDUgHerhRLbfbcRo6YlDfvocwnsc OlB1VDL+ylApXtFXFInT/Ug0wXOKGtmWazSG24IOV6XfKvDKyV3jNC1AKVBA5osjalh4RCORzQl WXmnOm/Wwh3MnYlzLqzt2alp4/wXp5Cgulw80rJihaiSeztlaNnXctH9Qu9NCqw0fbEMgc0ueFw TwCuxf0Lycswytr0XlRZD1fZ4D2OSKd0w+8ItWxQXxp9L+qvQQ1+q3u1ab5SWGM8ZtDJ7PRmYd7 S52x5iIqQNRPmUqrrI+IMDKFUop1dlSzK+HGBV2aPYo6u7UXn5wtB45hOOn0KsuH9SozneOu7mS fMcAGY6TP0FC3V+wR1qk36x0KCgR18K3i02L5QoiK/6HjqDKjD1yncYxm5e8OlwqmEqBKzMLWhC pcIKLaKTKFQg== X-Received: by 2002:a05:7301:f24:b0:386:b0ea:327d with SMTP id 5a478bee46e88-38751fc5337mr8273392eec.5.1796560897395; Sun, 06 Dec 2026 04:41:37 -0800 (PST) Received: from iiitd-S2600STB.iiitd.edu.in ([103.25.231.160]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3875221a4a3sm30002415eec.24.2026.12.06.04.41.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Dec 2026 04:41:36 -0800 (PST) From: Piyus Kedia To: Carlos Maiolino , linux-xfs@vger.kernel.org Cc: "Darrick J . Wong" , Ibrahim Hashimov , linux-kernel@vger.kernel.org, Kapil Vaswani Subject: [BUG] xfs: buffer log item recovery indexes regions by the dirty bitmap without a bound Date: Sun, 6 Dec 2026 18:11:31 +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, Mounting an XFS image whose log is dirty replays the buffer items in the log, and both ways a buffer item is replayed find the logged region for each run of set bits in the item's dirty bitmap by counting runs into item->ri_buf[], without checking that the region exists or that it is as long as its run. Our fuzzer found two out-of-bounds reads this way, both inside mount(2). The code is identical in 7.4-rc5, mainline and xfs/for-next, and the line numbers below hold for all three. xlog_recover_add_to_trans() sizes item->ri_buf[] by the item's blf_size (xfs_log_recover.c:2235), and the item is committed with however many regions arrived, ri_cnt <= ri_total; 2094dab19d45 ("xfs: fail recovery on a committed log item with no regions") rejects only ri_cnt == 0. Each image below is one filesystem whose dirty log has a field of its items changed and the record's CRC recomputed; the same log written back unchanged recovers and mounts on every kernel we ran. xlog_recover_do_reg_buffer() copies one region per run of set bits in blf_data_map, and nothing bounds i: fs/xfs/xfs_buf_item_recover.c:480 i = 1; /* 0 is the buf format structure */ while (1) { bit = xfs_next_bit(buf_f->blf_data_map, ...); ... if (item->ri_buf[i].iov_len < (nbits << XFS_BLF_SHIFT)) nbits = item->ri_buf[i].iov_len >> XFS_BLF_SHIFT; ... memcpy(xfs_buf_offset(bp, (uint)bit << XFS_BLF_SHIFT), item->ri_buf[i].iov_base, nbits << XFS_BLF_SHIFT); i++; bit += nbits; } /* Shouldn't be any more regions */ ASSERT(i == item->ri_total); 813f8136a2ce ("xfs: bounds-check buffer log item's dirty bitmap") bounds each run by the buffer, not by the regions. A buffer item with one data region (blf_size 2) and a bitmap of every other 128-byte chunk: BUG: KASAN: slab-out-of-bounds in xlog_recover_do_reg_buffer+0x235/0x580 Read of size 8 at addr ffff8880216d70e8 by task x/9437 xlog_recover_do_reg_buffer (fs/xfs/xfs_buf_item_recover.c:518) xlog_recover_buf_commit_pass2 (fs/xfs/xfs_buf_item_recover.c:1128) 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) The buggy address is located 8 bytes to the right of allocated 32-byte region (kmalloc-32: ri_buf[] of two entries, xlog_recover_add_to_trans(), xfs_log_recover.c:2236) That is ri_buf[2].iov_len; ri_buf[2].iov_base, the 8 bytes after the array (without KASAN, the start of the next kmalloc-32 object), is then the memcpy() source at :549, and in all three of our runs and both of the fuzzer's it was not a valid pointer: Oops: general protection fault, ... non-canonical address 0x9a025400000010 RIP: 0010:memcpy_orig+0x16/0x140 xlog_recover_do_reg_buffer (fs/xfs/xfs_buf_item_recover.c:549) xlog_recover_do_inode_buffer(), for XFS_BLF_INODE_BUF items, counts runs the same way into item_index and reads each inode's di_next_unlinked from its run's region, at its offset in the run: fs/xfs/xfs_buf_item_recover.c:700 logged_nextp = item->ri_buf[item_index].iov_base + next_unlinked_offset - reg_buf_offset; if (XFS_IS_CORRUPT(mp, *logged_nextp == 0)) { Neither item_index nor the offset is checked against what was logged. The unlink of a file logs one 128-byte region of its 16 KiB inode cluster buffer; with that item's bitmap moved to chunks 3 and 4, inode 1's di_next_unlinked (buffer offset 608) is read 224 bytes into the region: BUG: KASAN: slab-out-of-bounds in xlog_recover_do_inode_buffer+0x29a/0x4c0 Read of size 4 at addr ffff88801cd77fe0 by task poc/9456 xlog_recover_do_inode_buffer (fs/xfs/xfs_buf_item_recover.c:702) xlog_recover_buf_commit_pass2 (fs/xfs/xfs_buf_item_recover.c:1100) xlog_recover_items_pass2 (fs/xfs/xfs_log_recover.c:2020) The buggy address is located 96 bytes to the right of allocated 128-byte region (kmalloc-128: the logged region, xlog_recover_add_to_trans(), xfs_log_recover.c:2209) With chunks 1 and 4 instead (two runs, one region) ri_buf[2] is read past its end at :700 and its iov_base dereferenced, a general protection fault as above. The fuzzer set XFS_BLF_INODE_BUF on 4 KiB buffer items of one 128-byte region with a run over chunks 1 to 31: the read was 480 bytes into the region, and KASAN called it use-after-free once and out-of-bounds once, after what lay there. Impact - who can trigger it - A crafted XFS image with a dirty log has to be mounted; all of the above happens inside mount(2), before the filesystem can be used. 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. Recovery runs at every mount of a dirty log but -o norecovery (which has to be read-only); a read-only mount (MS_RDONLY) replays the log too (we measured that with a dquot item). The image chooses its own geometry and contents. - What is read, and what it feeds: 1. xlog_recover_do_reg_buffer(): one 16-byte struct kvec per run beyond the item's regions, past ri_buf[] (16 * blf_size bytes, kmalloc). Its length and pointer become the length (at most the run, which 813f8136a2ce keeps in the buffer) and the source of a memcpy() into the metadata buffer being recovered. Every run of ours and the fuzzer's ended in a general protection fault there. By the source, if the bytes past the array hold a kernel pointer, the memcpy() copies that kernel memory into the buffer, which recovery then writes to the image if the buffer's verifier passes; we have not tested that. 2. xlog_recover_do_inode_buffer(): 4 bytes at the region plus the field's offset in its run, up to the buffer's length (16 KiB here) past a region of 128 bytes, or a struct kvec past ri_buf[] as in 1. A non-zero value is stored as that inode's di_next_unlinked, the inode's CRC recomputed and the buffer written back (by the source); in our runs it read 0, which XFS rejects, and the mount failed. Seen on 7.4.0-rc5 (each read twice) 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. fs/xfs/xfs_buf_item_recover.c is also unchanged in mainline c3500c5ef648 (2026-12-04) and in xfs-linux for-next (ab1a77ab136c), where the patch applies as is. Same config and image before and after, the patch the only change; one boot per run, the fuzzer's own program included where it had one: without the patch KASAN report reg_buffer: bitmap of every other chunk 3 of 3, + fault inode buffer: run 96 bytes past the region 3 of 3 inode buffer: two runs, one region 1 of 1, + fault with the patch, kasan_multi_shot on: no report, alone in two boots that each ran every trigger above (and the fuzzer's bitmap), and together with our other log recovery fixes in three more (one of them the fuzzer's own programs). Each mount fails with EUCLEAN after an XFS_IS_CORRUPT() report and one of Too few regions (1) for buffer log item bitmap at daddr 0x0. No logged region for inode buffer offset 608 at daddr 0x24c0. controls, the same logs written back unchanged: both kernels recover and mount. Not covered by the patch, by the source and not run: the buffer format's blf_flags is read by xlog_recover_buf_reorder() before xfs_buf_log_check_iovec() checks the format region's length in pass 1, and xlog_recover_add_to_trans() reads the size field of a first region that may be 1 to 3 bytes long. We can send a patch for those. A patch follows in reply to this mail. In both functions it stops at a bitmap run that has no region left, and in xlog_recover_do_inode_buffer() it checks that di_next_unlinked lies in the region it is read from; the mount then fails with EUCLEAN and the corruption report. We are reporting four related log recovery bugs separately, each with its own patch: inode items whose fork regions are missing, an unchecked inode ilf_boffset, an unchecked dquot qlf_boffset, and the inode buffer verifier's inode count. 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. The reproducer is one program that carries its filesystem image, and we are happy to send it on request. Kapil Vaswani Piyus Kedia