From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796543260; b=hCtRGT6jyLeRflQWZq6xTBXw/7iNH+9Hz9nlnZ2MvmuPp+iev6x69xMGroyCTCkLQy+g bP5vb2uvLQcAWXiAePa5kyfOyWKdk5P08aok0L74XppWnwX0WXE3hW0OOE+JLq6EPeVIh uWtDSjXlYQ3wZAU7qdbqduzy3bLOwmqC2OHixHsldh2PmnNYTapCCxPH/wL5zD62NIe9h HQgtc9JRcdcJnnt38JtQQmdl7QzGGPJbHKhgM9C7GgkUW2slY4KS8n0j1KIorvZa+6uyD SUjjRA1tZ3MQ2Jk2FZnNJGwlAgi75aOjKk3ZYODKc5ROUtyfA1W/Tv0KFYa2JaahTJA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796543260; 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=qe9QawFH7nnxYrGpWWc3UdBxC73OsfEWADE0Owl5vIM=; b=JsHsvcEWVfmBueB6fZ6TvdUpm/L4pve2MhiaExTvY7m1FEsJ9vuqEw2SQ+JJQL8d63cg CdOkEHcbsIAnnEb7VigJR7jrbS+0o46AvVPJ3eEkPztr3lFqDFpYKVO+6ozT7RSZTki53 2LLktT0atGdbVjq2VUIDipIE4DGaKi2McBFqmwjl5Y8b/+sVB+4dePZ8gH09Q+lnQ7KIq StfiZc0Vtk66l0Y9l+SG1q4zTXtr7osa2zVc9TWrMP9BTA5ClglQ4cglefz1Vx9iqhP7B E8OMOEWeDWvGeqEFpXkHy6MmRxUfgu7HbCFd74WAhfQuLmNDjSYsvFJZeivX0lxhx8Q== 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=EpG7+EAl; arc=none smtp.remote-ip=74.125.82.51 Received: from mail-dl1-f51.google.com (mail-dl1-f51.google.com [74.125.82.51]) (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 A4C69606A321 for ; Sun, 6 Dec 2026 07:47:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A4C69606A321 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=EpG7+EAl Received: by mail-dl1-f51.google.com with SMTP id a92af1059eb24-1b546061d58so5365662c88.1 for ; Sat, 05 Dec 2026 23:47:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iiitd.ac.in; s=google; t=1796543259; x=1797148059; 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=qe9QawFH7nnxYrGpWWc3UdBxC73OsfEWADE0Owl5vIM=; b=EpG7+EAlFMPjGm/FwJatNL8AeF3qyIsYlmmtgL4UEt5Uo9LbNlqSlSHN1ZcH/2ST4w tLfqyFjfNLPMXQNRXdIa80cFC01oSu6S3fK2LV2bGAmF7MfMcLjgELrjYCHBYlT1Yw3d 7wNTNi5L+1lmLVb/OckcjXftGVPKQgLAm4N54= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796543259; x=1797148059; 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=qe9QawFH7nnxYrGpWWc3UdBxC73OsfEWADE0Owl5vIM=; b=mZRueGMHFuZ0w6SCBOte9kdvL6fVJ8JvKVe9zVBY3Tw4J6P5H0StInlir+BhDQRIcd 0ntYx+/8P5w+6PGpjD4OHCzO6VO5AZKEbUMRZUvKZAgAxOQnoCtpCFj/swS2a4vK3lNa hp41le49a1J1U8V1ITV98RS7ghH8ImKv9kIeaVcGUbMlZ6X6xDRfxcQE8AfsVlfAM4B7 ACHKymletNWr+XrgibyAHWhf/asSGQtk2jKzpuA9sraMXTGQo52NRWRvkPPjQGLPMLMk YZvBs1+tTiS+XHz3PzmBr7ELMWkpuFWekp87JpoyfXBKxyz08RSc3Qu4O9IXIiYIbcf9 QKPQ== X-Forwarded-Encrypted: i=1; AL+hErGU7z8TjZraTV77X2lgfrKE3ac7/b2KbIJGeWOyL5xmPjqAgC+3DdO+89mcjjdzV2zBgRQ5tkP5EChbQKY=@vger.kernel.org X-Gm-Message-State: APuU4Z/tAQSt46xnlYOjW4QG4HGQeGffva5awf5AQzUSHGkPEc0Yhm0T bIXMoont97eYBT1GCzzFe2uhwNL7WyAvD4Imb/q46HvTLq+QjhZP1nFcECMNr9DX58yQJPsFSFS Zvtlpn//Jjw== X-Gm-Gg: AZFdTZdotBFQrSFxX/n2DPyIGjSxQERoVMdrh4IF05OPxOYE5ohnUPjCSWo5I2NUb9T fea0Ay1PWL5nDoEfSEldH1DwZreN1E20xnU+zybga3iVjWbomdBQU7JUk19bwbJJ6SWHaUkiZbY xFLysMi7ed3rWoLL2tiQ2XqF1A69rvnkgLkFrSHvE9C/IAVIvoJFDQvgwnwFYpBHSYuRIgbkl98 GjYnX2U++IBTiZ+SEztTaJ5IognR8InGGTzn+XTBGwS0ltsQMo3Van9l9M1iCrts08ZEDNCPZ5v Cz/lLZnmuEjIGI7yMreCL2cjsEjsMNWeh8aSG2J6qCz7OaZflqsnDI6kA5QohfEfpham3ybpgdu 2BTBN+vzumZAYjG89FQKEIT1XEwrdl4QCp9MRTFM5SpiRYnr26WYR/G+tsRJWNEevOEhucX5ZDx VceJzovgZfokvR0hK+uDaK8hgpLeN5CMEJTjNdvDY+qfMJ2vv4LOtn+mk6jRLRpG+oUWAprwhgK 9S5IiEd8BqJgPVLvBA2hEUOhrK99tS1saJ5LecAHrNYbI/TCVaw9l49SpX09V43HJ57nLFgQym3 63hbx7FS2Ujsj15lJ6Mc58czj7guWlB2IBsFAyb8Ddk2sbQtivjhQVWED73hqJTRg8RYzOqmO4e tQeYcaBqqzvmJ4zOQrxT2BodQyNNGWvxweFBnuDGQx4//Ugh88ZTqGJBXKBUw3VtX X-Received: by 2002:a05:7022:1113:b0:1b3:af3a:e784 with SMTP id a92af1059eb24-1b5d711236dmr7122749c88.32.1796543258399; Sat, 05 Dec 2026 23:47:38 -0800 (PST) Received: from iiitd-S2600STB.iiitd.edu.in ([103.25.231.160]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5d643dbd2sm23518546c88.6.2026.12.05.23.47.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 23:47:37 -0800 (PST) From: Piyus Kedia To: Carlos Maiolino , linux-xfs@vger.kernel.org Cc: "Darrick J . Wong" , linux-kernel@vger.kernel.org, Kapil Vaswani Subject: [BUG] xfs: slab-out-of-bounds past an attr node whose entry count exceeds its block Date: Sun, 6 Dec 2026 13:17:33 +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, xfs_da3_node_verify() bounds a dabtree node's entry count only by the larger of the directory and attr geometries: fs/xfs/libxfs/xfs_da_btree.c:246 (xfs_da3_node_verify) if (ichdr.count > mp->m_dir_geo->node_ents && ichdr.count > mp->m_attr_geo->node_ents) return __this_address; When directory blocks are larger than fs blocks, an attr node, one fs block, can claim more entries than it holds: with "mkfs.xfs -b size=1024 -n size=65536" an attr node holds (1024 - 64) / 8 = 120 entries and the verifier accepts up to (65536 - 64) / 8 = 8184. 3df5e5aaa3bc ("xfs: bound da-node entry count against the correct geometry") bounds the count by args->geo->node_ents in xfs_da3_node_lookup_int() (xfs_da_btree.c:1798), which covers attr lookups (getxattr, and the lookup before a set or remove). Three other walkers of an attr node's btree[] do not go through xfs_da3_node_lookup_int() and do not bound the count. With the count of an attr node raised to 121, its CRC recomputed and nothing else changed, each of them reads past the node's 1024-byte buffer, and two of them write past it. Our fuzzer found the first two; we found the third while checking the other walkers. (3df5e5aaa3bc gives "getxattr/listxattr" as the way in, but listing does not use xfs_da3_node_lookup_int(); see 1.) 1. Listing from a cursor: xfs_attr_node_list_lookup() fs/xfs/xfs_attr_list.c:270 for (i = 0; i < nodehdr.count; btree++, i++) { if (cursor->hashval <= be32_to_cpu(btree->hashval)) { A cursor hash above every hash in the node keeps the loop going to the count. XFS_IOC_ATTRLIST_BY_HANDLE takes the cursor from the caller (so do the GETPARENTS ioctls, on a filesystem with parent pointers; we did not run those). listxattr(2) starts from a zero cursor and stops at btree[0] on every level: on the crafted node it listed all 60 names, getxattr failed with EUCLEAN (3df5e5aaa3bc), and ATTRLIST_BY_HANDLE with cursor hash 0xffffffff gave BUG: KASAN: slab-out-of-bounds in xfs_attr_node_list_lookup+0x2ef/0x760 Read of size 4 at addr ffff888000a63c00 by task poc/9453 xfs_attr_node_list_lookup (fs/xfs/xfs_attr_list.c:271) xfs_attr_node_list (fs/xfs/xfs_attr_list.c:399) xfs_attr_list_ilocked (fs/xfs/xfs_attr_list.c:579) xfs_attr_list (fs/xfs/xfs_attr_list.c:596) xfs_ioc_attr_list (fs/xfs/xfs_handle.c:456) xfs_attrlist_by_handle (fs/xfs/xfs_handle.c:486) xfs_file_ioctl (fs/xfs/xfs_ioctl.c:1548) The buggy address is located 0 bytes to the right of allocated 1024-byte region [ffff888000a63800, ffff888000a63c00) (kmalloc-rcl-1k, allocated by xfs_buf_alloc() for xfs_da3_node_read() from xfs_attr_node_list_lookup()) 2. Inactivation: xfs_attr3_node_inactive() It takes each child from btree[0] and then drops that entry with xfs_attr3_node_entry_remove(*trans, dp, bp, 0) (xfs_attr_inactive.c:229), that is __xfs_da3_node_remove(): fs/xfs/libxfs/xfs_da_btree.c:1534 if (index < nodehdr.count - 1) { tmp = nodehdr.count - index - 1; tmp *= (uint)sizeof(xfs_da_node_entry_t); memmove(&btree[index], &btree[index + 1], tmp); ... } memset(&btree[index], 0, sizeof(xfs_da_node_entry_t)); For a count N the memmove() reads 8 * (N - 1) bytes from byte 72 of the node and writes them at byte 64, and the memset() clears the 8 bytes at 64 + 8 * (N - 1). With N = 121 that is a read ending 8 bytes past the buffer and an 8-byte write just past it. Unlinking the file: BUG: KASAN: slab-out-of-bounds in __xfs_da3_node_remove.isra.0+0x12d/0x270 Read of size 960 at addr ffff8880284d3048 by task kworker/0:2/812 Workqueue: xfs-inodegc/loop0 xfs_inodegc_worker __asan_memmove (mm/kasan/shadow.c:94) __xfs_da3_node_remove (fs/xfs/libxfs/xfs_da_btree.c:1537) xfs_attr3_node_entry_remove (fs/xfs/libxfs/xfs_da_btree.c:1585) xfs_attr3_node_inactive (fs/xfs/xfs_attr_inactive.c:229) xfs_attr3_root_inactive (fs/xfs/xfs_attr_inactive.c:285) (inlined) xfs_attr_inactive (fs/xfs/xfs_attr_inactive.c:371) xfs_inactive (fs/xfs/xfs_inode.c:1484) xfs_inodegc_worker (fs/xfs/xfs_icache.c:1945 fs/xfs/xfs_icache.c:1991) The buggy address is located 72 bytes inside of allocated 1024-byte region [ffff8880284d3000, ffff8880284d3400) and, with kasan_multi_shot, the memset() right after it: BUG: KASAN: slab-out-of-bounds in __xfs_da3_node_remove.isra.0+0x175/0x270 Write of size 8 at addr ffff8880284d3400 by task kworker/0:2/812 __asan_memset (mm/kasan/shadow.c:84) __xfs_da3_node_remove (fs/xfs/libxfs/xfs_da_btree.c:1542) The buggy address is located 0 bytes to the right of allocated 1024-byte region [ffff8880284d3000, ffff8880284d3400) Under KASAN neither of the two is carried out (__asan_memmove() and __asan_memset() return once their check fails), so our runs do not show what a kernel without KASAN does next. The loop has had this shape since b854e1c4eff3 ("xfs: close crash window in attr dabtree inactivation"), v7.0-rc6; before it, it re-read the parent for each child and took btree[i + 1].before, which passes the end of the node only after 120 children have been walked. 3. Shifting a path into the node: xfs_da3_path_shift() On its way down into a node it has not walked before: fs/xfs/libxfs/xfs_da_btree.c:2245 blk->hashval = be32_to_cpu(btree[nodehdr.count - 1].hashval); if (forward) blk->index = 0; else blk->index = nodehdr.count - 1; blkno = be32_to_cpu(btree[blk->index].before); It is called by the attr leaf and node joins (xfs_attr3_leaf_toosmall(), xfs_da3_node_toosmall()), by xfs_da3_node_lookup_int() when a leaf ends in the hash it looks for, and by scrub; the node it comes down into is one xfs_da3_node_lookup_int() did not read. We made a three-level attr tree with xfs_db on a 1 KiB-block filesystem (260 attrs with 300-byte values: a root over two level-1 nodes, A with 89 entries and B with 99), raised B's count to 121, and removed, as uid 65534, one of the two attrs in the last leaf under A. Joining that leaf with the next one shifts the path forward into B: BUG: KASAN: slab-out-of-bounds in xfs_da3_path_shift+0x801/0x8a0 Read of size 4 at addr ffff888052db0400 by task poc/9461 xfs_da3_path_shift (fs/xfs/libxfs/xfs_da_btree.c:2245) xfs_attr3_leaf_toosmall (fs/xfs/libxfs/xfs_attr_leaf.c:2275) xfs_da3_join (fs/xfs/libxfs/xfs_da_btree.c:1158) xfs_attr_node_remove_attr (fs/xfs/libxfs/xfs_attr.c:1552) xfs_attr_set_iter (fs/xfs/libxfs/xfs_attr.c:934) xfs_attr_finish_item (fs/xfs/xfs_attr_item.c:503) xfs_defer_finish_noroll (fs/xfs/libxfs/xfs_defer.c:709) xfs_trans_commit (fs/xfs/xfs_trans.c:923) xfs_attr_set (fs/xfs/libxfs/xfs_attr.c:1243) xfs_xattr_set (fs/xfs/xfs_xattr.c:186) vfs_removexattr (fs/xattr.c:601) __x64_sys_removexattr (fs/xattr.c:1109 fs/xattr.c:1106 fs/xattr.c:1106) The buggy address is located 0 bytes to the right of allocated 1024-byte region [ffff888052db0000, ffff888052db0400) (kmalloc-rcl-1k, allocated by xfs_buf_alloc() for xfs_da3_node_read() from xfs_da3_path_shift(), xfs_da_btree.c:2203) The join then drops B's btree[0] with xfs_da3_node_remove(), the same memmove() and memset() as in 2, and kasan_multi_shot reports both (a read of size 960 and a write of size 8, as above). removexattr(2) returned 0. Impact - who can trigger it: - A crafted XFS image has to be mounted. 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. The image picks its own geometry, so no one has to have made a filesystem with -n size larger than -b size. - 1 also needs CAP_SYS_ADMIN: xfs_attrlist_by_handle() and the GETPARENTS ioctls check capable(CAP_SYS_ADMIN), and listxattr(2) does not get past btree[0]. - 2 needs only the unlink of the file, i.e. write permission on its directory, which the image chooses. The accesses then happen in the xfs-inodegc worker, after unlink(2) has returned. We ran it as root. - 3 needs only the removal of a user xattr, i.e. write permission on the file, which the image chooses. We ran it as uid 65534 with no capabilities, after root had mounted the image. - What is accessed, for a count N (up to 8184 with 64 KiB directory blocks). 1 reads the 4-byte hash of each entry from btree[120] to btree[N - 1], up to 8 * (N - 120) - 4 bytes past the buffer; by the source the values only steer the walk: a hash at or above the cursor's sends it to that entry's child block, which then has to read as a block of this attr fork. 2 and 3: the memmove() reads 8 * (N - 120) bytes past the buffer and, for N > 121, writes 8 * (N - 121) bytes past it, the bytes that lay 8 further on; the memset() then zeroes 8 bytes at 8 * (N - 121) past the end. By the source, 2 repeats this for each child while the count is above 120. The buffer is a 1024-byte kmalloc-rcl-1k object (xfs_buf_alloc()), so what lies past it is the next object in that slab. We have not looked at what those writes could be made to do. - After the access, in our runs: 1 returned 0 with no entries; in 2 the walk went on to an entry past the real ones, XFS reported the corruption and shut the filesystem down; in 3 removexattr(2) returned 0 and the filesystem unmounted cleanly. Seen on 7.4.0-rc5 (1 and 2, two reports each) 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. The three files are also unchanged in mainline c3500c5ef648 (2026-12-04) and in xfs-linux for-next (ab1a77ab136c). Same config and image before and after, the patch the only change: without the patch 1 a KASAN read in xfs_attr_node_list_lookup() in 4 of 4 runs (the hunt's own program, count 200, and ours, count 121) 2 a KASAN read in __xfs_da3_node_remove() in 5 of 5 (the hunt's program and ours), and the write too in the 2 runs with kasan_multi_shot 3 a KASAN read in xfs_da3_path_shift() in 3 of 3, and the read and write in __xfs_da3_node_remove() in the 2 runs with kasan_multi_shot with the patch (kasan_multi_shot on): no report in 5, 5 and 4 runs 1 listxattr(2), getxattr(2) and both ATTRLIST_BY_HANDLE calls fail with EUCLEAN, and the kernel logs "Metadata corruption detected at xfs_attr_node_list_lookup" 2 unlink(2) returns 0; inactivation logs the corruption in xfs_attr3_node_inactive() and shuts the filesystem down 3 removexattr(2) fails with EUCLEAN; the kernel logs the corruption in xfs_da3_path_shift(), "deferred attr work failed, error -117", and shuts the filesystem down controls, the counts the images were built with (6, and 99 for B): both kernels list the 60 names, read them, unlink the file and remove the attr, with no KASAN report and no XFS error. At 120, the most such a node holds, the unpatched kernel gives no KASAN report in any of the three. A patch follows in reply to this mail. It bounds the count by the attr geometry in xfs_attr_node_list_lookup() and xfs_attr3_node_inactive(), and by args->geo in xfs_da3_path_shift(), as 3df5e5aaa3bc does in xfs_da3_node_lookup_int(). We looked at the other readers of node entries: scrub's xchk_da_btree_block() bounds the count already, xchk_xattr_find_leftmost_leaf() and xfs_da3_root_join() read only btree[0] of a node whose count is not 0, xfs_da3_node_toosmall() uses a sibling's count only to see whether it fits, and the remaining btree operations work on nodes that xfs_da3_node_lookup_int() or xfs_da3_path_shift() put in the path. A directory node is one directory block, and the directory node_ents is the larger of the two, so the verifier's bound already fits directory nodes. Bounding the count in xfs_da3_node_verify() by the buffer's own size, (BBTOB(bp->b_length) - header size) / 8 entries, would cover every walker at once, since an attr node buffer is one fs block and a directory node buffer one directory block. 3df5e5aaa3bc chose to leave the verifier alone, so the patch follows it; we can send it the other way instead. 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; what a kernel without KASAN does with the writes we have from the source only, as said. The reproducers are one program each, carry their filesystem images, and we are happy to send them on request. Kapil Vaswani Piyus Kedia