From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796548866; b=WKJOS/Tv90+NyoytsvJ7ShBpnhqw4e5rIifRrSwztYXbnEzpS9C4c7OFM4lOCNf78AR/ 9wNr2ex0A/RdkLZLy5vPXIh9AIGYgM2/vfM36h0mVZyKg8vXrVUysgZaRwsPsZANpEiGJ jBGlyyqGJwGgsV5MASvZRMAdAbtztdXaXj+/EqUcIEkpw7sa4Ti9jNszymOtECKp1w/KA v/kubH9+LaNJeK1r/gQRui/1H3qmAlCMeI8WWdZT3lCgCl5Z0xstT3Ap/JlKBM3Hdudnx 9GKiXzxgrDh2HAMOr7TdLU7f/GKMBwTklI67Ecvkxj3uEJrP6QsvMU575O0vPCyGL3Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796548866; 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=oOBGJ3/qJy1em+bIefnyEMTshJFCi8t1U+gcmP4gHh8=; b=urtseJlS7aA6vlvT3vjTCEWLIwLyFB5qeTchotnEYp1h9jfm8QbvCm9OP2aZ1dMFa4Xd 5Ddxd/4+KJPkmBQ60JGwh9+rErkgYEPdc/5MB17A6ZyqCPvogJNQ72LJS60FDgP6MHUbc S3bTtAA5GnqbWLZ0Aj9QJ9YTYFPzXtbQbpfDxaJuaDojIo/MoyzGxweiNHT8U33M1PTDt Z8VE33EFtZDNthO35zXDnPOBBknnJ5uZJGHVoSD/mcMawoulWeUIB8s1s0AGRtydVAmZ7 ofhw+ajZ4HxkHgayeBoyrEDDfGkRSxHChJOpMUon4Zuygj5GU0hecmlYXvgQFyw3plw== 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=j0f47yH7; arc=none smtp.remote-ip=74.125.82.53 Received: from mail-dl1-f53.google.com (mail-dl1-f53.google.com [74.125.82.53]) (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 0742B606A31F for ; Sun, 6 Dec 2026 09:21:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0742B606A31F 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=j0f47yH7 Received: by mail-dl1-f53.google.com with SMTP id a92af1059eb24-1a2761c69fbso5499400c88.0 for ; Sun, 06 Dec 2026 01:21:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iiitd.ac.in; s=google; t=1796548864; x=1797153664; 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=oOBGJ3/qJy1em+bIefnyEMTshJFCi8t1U+gcmP4gHh8=; b=j0f47yH7pcR2qdGkPD2/eu3uHmXB104ySFELjtx2WvRIWEZDFbUDVJF57Q7BilERiZ /EDvuM6tInxZHH/Q8sYKWrWx8sxPaAeB0nnyeDrM3WmEQIVFsAaDFX0WzFlMzRXBDfLo rRyYA5+gn1kzJ326VzesNPtdhkBDUNFlFy0aA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796548864; x=1797153664; 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=oOBGJ3/qJy1em+bIefnyEMTshJFCi8t1U+gcmP4gHh8=; b=0bpCTaYZREBUkyjQvk91tLTP7igCYh6sXgy8OtKNG80a7NIhnHkM3fOS5g70mWVddj aSK0LwVYbBKtSNQ4FG/r82DZJQr6dfzzvHsJ7lqVPVhzpHMH+UK0QJxw6riPJLxBOdiy lyqlgVLiEYGYe+zIKKTJZKJGSs8rajpuk1a/sm/hSQba1Qcgs05v0XRkC2KFI+ntHXl4 jPMQ2OstfSVvEz2tD/TkLDGWWH+IrwwPFW1Utn88ZNXY3uceBmWZEPp3QD9InE3BSrcy YsS6gNwfDCcv2jA7S99cJPYoBybBjDC44tOBQSP0Lnq3moyWedGHFJR4OovEVtHRJBfb JjZQ== X-Forwarded-Encrypted: i=1; AL+hErF/p7Cdbp4V7dIQw8VjrGUTzE/gNSyOXGhvRprVkW1DnXvv9Cc48GAcf1C5LBF4n+ApIRtFA8nGv+c=@vger.kernel.org X-Gm-Message-State: APuU4Z/4XsC7PM5n3T+ylB4a+E6lfbxvZtb1dihLYVawx59NQAXB3ohE qHIVfPeOr+408DOIOOmvd+mSBZvp4O0Bf5XE5JmPcEce9YxqygOez6QrxYIXgP/ENUk= X-Gm-Gg: AZFdTZdjg19WDwr7nA2KTOQpLCc65g7q3GW/oHlnnMifVfD2AFvJn0qWWTFasm73BXD OCP1kEdEWEXI72/fZv/ctLmMerv48s5apsKMoNLRRPhjg1w0Fa4nzblTZ4Rqh4NYQ3E1mWNLiei zEW3cvojaBZH/qTgDqmOX6R47W5+oTpLFUuktRcNWIv8vUVGjT6VrMBAxXgDj03yAJw+rAwkfEb 0Iu2OEqb74yzrQaaBJ01JNdXvP18UhRlCyZHTw/phy7hxe8sHNyrV5cxeJmjHdfNoHJdSRgYZjh H+XkokZk72Kg1kiUb9cZSl2tOdSqX2rpuu4ixCRugUocUWQ0l37bzRnIU5w/eyuEJlWSyG9P3A8 0rfmAIslo7zI/nv8PiQ/FvCNeua2QPnoTkuCSM5yCIM8SK5Ju0w1xDdIrlgSe0rtVl0SHa7Rh8A dVU4HG5HDbBkaNN2YaGqbpZb07IiSDcgjtg1rwaYs1DqTWK9xyfQ2GXQc1se4CW4D6SjvrIF21D LQouOjtEu47yISrtgaVAjFaEFKJIDnfPc2dGGrRoWz8TbbV6b4EhL0Za4s1z97a2aSTUsFV2vZQ ajtQNXZQSi5tsLbK8bAgd5jeMVIkARHJM2V8HinIM09V+ocK5kSOCm/t/oblBwEvEfy78PSijrZ 8QAIT0pfA1m8rjovbw0uDTnnkXj0Xqd8Sew3jemajtEqDtma36s1WTxr303Cmtffub5r1k5hcrN orphD3R9PmPw== X-Received: by 2002:a05:701b:240f:b0:177:9a5b:a89 with SMTP id a92af1059eb24-1b5d7103a66mr6924298c88.29.1796548863707; Sun, 06 Dec 2026 01:21:03 -0800 (PST) Received: from iiitd-S2600STB.iiitd.edu.in ([103.25.231.160]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5d64706d3sm23974638c88.13.2026.12.06.01.21.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Dec 2026 01:21:03 -0800 (PST) From: Piyus Kedia To: Carlos Maiolino , linux-xfs@vger.kernel.org Cc: "Darrick J . Wong" , Aldo Ariel Panzardo , Hongling Zeng , linux-kernel@vger.kernel.org, Kapil Vaswani Subject: [BUG] xfs: attr leaf join writes a name almost 64KiB past the leaf Date: Sun, 6 Dec 2026 14:50:58 +0530 Message-Id: X-Mailer: git-send-email 2.34.1 X-Mailing-List: linux-xfs@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 removexattr(2) leaves an attr leaf small, xfs_da3_join() asks xfs_attr3_leaf_toosmall() whether it can be joined with a sibling and then has xfs_attr3_leaf_unbalance() move one leaf's entries into the other. Both trust the leaf headers, and xfs_attr3_leaf_moveents() does not check where the names end up. On a crafted image the last name is copied 65500 bytes past the start of a 1024-byte buffer: BUG: KASAN: slab-out-of-bounds in xfs_attr3_leaf_moveents.constprop.0 Write of size 212 at addr ffff8880224777dc by task poc/9462 __asan_memmove (mm/kasan/shadow.c:95) xfs_attr3_leaf_moveents (fs/xfs/libxfs/xfs_attr_leaf.c:2815) xfs_attr3_leaf_unbalance (fs/xfs/libxfs/xfs_attr_leaf.c:2532) xfs_da3_join (fs/xfs/libxfs/xfs_da_btree.c:1163) 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_fremovexattr (fs/xattr.c:1120) The buggy address belongs to the object at ffff888022476000 which belongs to the cache kmalloc-4k of size 4096 The buggy address is located 2012 bytes to the right of allocated 4096-byte region [ffff888022476000, ffff888022477000) (ksmbd-for-next d70570cf8003 with KASAN; the "object" is a neighbour, not the leaf: the temporary leaf in this run is the kmalloc-1k object at ffff888022467800, and ffff8880224777dc is that + 65500.) What happens. xfs_attr3_leaf_moveents() places each name it moves below the destination's firstused, by the name's real size: fs/xfs/libxfs/xfs_attr_leaf.c:2808 ichdr_d->firstused -= tmp; ... entry_d->nameidx = cpu_to_be16(ichdr_d->firstused); ... memmove(xfs_attr3_leaf_name(leaf_d, desti), xfs_attr3_leaf_name(leaf_s, start_s + i), tmp); The in-core firstused is 32 bits, nameidx is 16. If the names do not fit, firstused wraps below zero, nameidx keeps its low 16 bits and xfs_attr3_leaf_name() puts the copy at the leaf + (firstused & 0xffff). The only checks are ASSERTs (:2813, :2825), compiled out without CONFIG_XFS_DEBUG or CONFIG_XFS_WARN. Whether the names fit is decided from the headers. xfs_attr3_leaf_toosmall() joins two leaves if their usedbytes and entry tables leave a quarter of a block spare: fs/xfs/libxfs/xfs_attr_leaf.c:2251 bytes = state->args->geo->blksize - (state->args->geo->blksize >> 2) - ichdr.usedbytes - ichdr2.usedbytes - xfs_attr_leaf_entries_end(ichdr.count + ichdr2.count, leaf); and xfs_attr3_leaf_unbalance() then moves both leaves' entries into a temporary leaf starting from firstused = blksize (:2498, :2512) if the kept leaf has holes, or else the dropped entries straight into the kept leaf, below its firstused (:2473). xfs_attr3_leaf_verify() checks that firstused lies between the header and the end of the block, and that each entry's name lies at or above firstused and inside the block (c84760659dcf, tightened this year by b7eea80be25f and 15ccd92a782a). Nothing ties usedbytes to the names, and nothing makes a leaf without holes have its names packed down from the end of the block to firstused, which is what the in-place join assumes. How it is reached. The fuzzer's image has 1 KiB blocks and a file with 40 user xattrs of 200 bytes, so its attr fork is a node over 16 leaves of two to four 212-byte local entries. In the first leaf (four entries, usedbytes 848, firstused 176) usedbytes is set to 212 and the block CRC recomputed; xfs_repair -n reports "would reset usedbytes cnt from 212 to 848" and nothing else. Removing one of its attrs leaves usedbytes 0 for three real entries, xfs_attr3_leaf_remove() asks for a join, and toosmall() joins it with its sibling, two entries with usedbytes 424: 768 - 0 - 424 - 120 >= 0. The kept leaf has a hole where the removed name was, so both go into a temporary leaf: four names take it from 1024 down to 176, and the fifth goes to 176 - 212 = -36, nameidx 0xffdc. The trace above is that copy, 212 bytes (the local name/value structure of the sibling's last attr, user.big_43: its lengths, the name and the 200-byte value from the image) to the temporary leaf + 65500, 64476 bytes past its end. removexattr(2) returns 0. The merged leaf, holding an entry with nameidx 65500, is logged, and at unmount the write verifier rejects it and shuts the filesystem down. The fuzzer saw this twice on 7.4-rc5, at xfs_attr_leaf.c:2815 both times, as "KASAN: slab-out-of-bounds Write in xfs_attr3_leaf_moveents" and "KASAN: slab-use-after-free Write in xfs_attr3_leaf_moveents": the title names whatever lies 64KiB past the temporary leaf, a redzone in one run and a freed kmalloc-4k buffer in the other. When that memory is not poisoned KASAN says nothing and the copy is done: in the fuzzer's console log two runs of the same image ended with the corrupt leaf at unmount and no KASAN report, and so did the first of our upstream runs (below). usedbytes is not the only way there. With every usedbytes right, take a leaf of two entries, move one of its names down to just above its entry table, lower firstused to that name and leave holes at 0; xfs_repair -n (xfsprogs 5.13) reports nothing on that image. When its higher-numbered neighbour is joined into it, the join is done in place, below that firstused, and the dropped name goes past the buffer in the same way: BUG: KASAN: use-after-free in xfs_attr3_leaf_moveents.constprop.0 Write of size 212 at addr ffff888028880f90 by task variant/9455 (the same stack; the destination this time is the kept leaf's own 1024-byte buffer at ffff888028871000, + 65424 = 100 - 212 as a u16. removexattr(2) returned 0, and the unmount shut the filesystem down as above.) 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. - After that it needs only the removal of a user xattr, i.e. write permission on the file, which the image chooses. Our reproducer makes the file mode 0666 in the image and removes the xattr as uid 65534 with no capabilities, after root has mounted it. - What is written: a whole name/value structure from the image, here 212 bytes, to the temporary leaf (kvzalloc(blksize), kmalloc-1k for 1 KiB blocks) + 65500, or, in the in-place case, to the kept leaf's buffer (an xfs_buf, kmalloc-rcl-1k) + 65424. Its contents, the name and value bytes, are the image's. The offset is (u16)(the in-core firstused after the wrap): almost 64KiB past the start of the leaf for 1 KiB to 32 KiB blocks, and further names of a larger excess go below it, 212 bytes at a time here. What lies there is whatever the allocator put there: in our upstream runs KASAN called it the redzone after a kmalloc-512 or a kmalloc-4k object, a freed kmalloc-8k object, or a freed page. We have not tried to aim it. - What follows: the merged leaf keeps an entry whose nameidx is past the block. Until it is written back, readers of the cached buffer follow it: in our first run, where KASAN had not flagged the write, a listxattr(2) after the removal got "KASAN: use-after-free Read of size 1 in xfs_attr3_leaf_list_int" 65502 bytes past the kept leaf. At writeback the verifier stops it and the filesystem shuts down, so the corrupt leaf does not reach the disk. Seen on 7.4.0-rc5 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_attr_leaf.c, xfs_attr_leaf.h and xfs_da_btree.c are also unchanged in mainline c3500c5ef648 (2026-12-04) and in xfs-linux for-next (ab1a77ab136c), and nothing in either touches this. On ksmbd-for-next, with KASAN, the same config and image before and after the patch below, the removal done as uid 65534: before the fuzzer's image (usedbytes 212 for 848): KASAN write of 212 bytes at the temporary leaf + 65500 in 5 of 5 runs, titled slab-out-of-bounds (2), slab-use-after-free (1) and use-after-free (2) after whatever lay there; before those, one run in which KASAN did not flag it and the copy was done; the fuzzer's own program, unchanged: 1 of 1. The second image (firstused lowered): KASAN write at the kept leaf + 65424, 1 of 1. removexattr(2) returned 0 each time. after no report in 5 runs of our program and 1 of the fuzzer's: "Internal error need > room" from xfs_attr3_leaf_unbalance(), removexattr(2) fails with EUCLEAN, nothing is moved, and the filesystem shuts down, since the removal had already changed the leaf in that transaction. The second image: the same, 1 of 1. control the fuzzer's image with usedbytes as built, removing three of the leaf's four attrs: the third removal joins it with its sibling through the temporary leaf, as above. No report and a clean unmount on either kernel, 2 runs each, and the merged leaf on disk holds 3 entries, usedbytes 636. A patch follows in reply to this mail. Before moving anything, xfs_attr3_leaf_unbalance() adds up the sizes of the names it is about to move, with xfs_attr_leaf_entsize() as xfs_attr3_leaf_moveents() does, and checks that they and the merged entry table fit below the kept leaf's firstused (in place) or in the block (temporary leaf); if not it reports corruption and returns -EFSCORRUPTED, which xfs_da3_join() passes up. A pair of consistent leaves always passes, since toosmall() keeps a quarter of the block spare. We put the check in the join rather than in the verifier. A verifier check that usedbytes is the sum of the entry sizes would reject the fuzzer's image, but not the second one, whose usedbytes is right; what is wrong there is the claim that a leaf without holes is packed, which neither the verifier nor xfs_repair -n checks, and only the join knows how much has to fit where. Unlike 3df5e5aaa3bc ("xfs: bound da-node entry count against the correct geometry") this is not about the verifier lacking fork context: an attr leaf is always an attr leaf, but whether two of them fit in one is a question about the pair. We can add the usedbytes check to the verifier as well if you prefer. Not covered by the patch: the same arithmetic in xfs_attr3_leaf_compact(), reached from setxattr(2), when names overlap. With a leaf whose largest local value was stretched over the next name and usedbytes set to the sum of the three entry sizes (1060, so a usedbytes check would pass it; xfs_repair -n reports the overlap), replacing an attr in that leaf compacts it and the stretched name goes to the leaf's own buffer + 65500 (KASAN: Write of size 636 in xfs_attr3_leaf_moveents, then eleven more reports at the same place from xfs_attr3_leaf_add_work(), which put the new entry there, among them a write of its 200-byte value, and from the lookups after it; setxattr(2) returned 0). The compaction path cannot return an error today; a verifier check that the names fit between firstused and the end of the block (which overlapping names fail) would cover it. We would send that separately. 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 other block sizes do we have from the source only, as said. The reproducer builds the fuzzer's image in place, runs as one program, and we are happy to send it on request. Kapil Vaswani Piyus Kedia