From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.174 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796562013; b=4IqH0lF3lqtL5sPRqKh4dOyp1ErAPcmNaRZ7R6zU9Gh18NFlJQVZKMwjHXEPj0UnWJo3 eBGnl5nJtAzvpS8zpnhfwrxaTWfu+rd/5xbnyV4HWojG2aPM67f2Da/Pdw/VF3d41JME3 tBRKaVNggjNZ2+RwAJqvE/C9pN88HGan3gozI/3hh1SvGTIKEtheUqowHjlJWfzEiI2w4 YW8hsflgdmtVsHHxCg1i6pWBNEDhKWNlbfwippN9b/BbJwpTh435h2lYBzpUFIdFZEY89 ngcfL631PazBGRr5IvE0e0pUdYz+SpTFoaBoJX91sTSBxec5KEt2c4d+ToCuPYCj8Iw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796562013; 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=b+oBjiGKnPzkfoOKA4vlzPGp3DMt3TmyXqjVPLJFuvY=; b=jwIbZrL7dSlpit1ZaIUxPUBUGo26I1i+NLeWp8nttakkKnN4QdN5Ms+X4E+DioGKveND Tx97ecocdKZE1G9xPhrWl2l3HU9PpdDN4IpW7jMhnKW9151JPwyk6c5UeWDjcjX9Oug9l I5Q3deTP1pLVTKoeAcq7+IBscd1qwoDTN6ohLaLD8E3Nxxt+onAvJxnmolA/1lZiP6WT3 85McNHMttyz5tuuPxTRaDKTq4Pr789N+ex7uZw5jsOLh7DUsIoJWFLr/tmtof4lXQZqA9 JP8rPDZGwzSST/yhywAE8rrrc7JgKrRI4LvwYbQC72D3ebVRyzNpWrEC8V/YLyPclWQ== 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=eofSirgd; arc=none smtp.remote-ip=74.125.82.174 Received: from mail-dy1-f174.google.com (mail-dy1-f174.google.com [74.125.82.174]) (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 580B5606A680 for ; Sun, 6 Dec 2026 13:00:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 580B5606A680 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=eofSirgd Received: by mail-dy1-f174.google.com with SMTP id 5a478bee46e88-386c336eab8so4248177eec.0 for ; Sun, 06 Dec 2026 05:00:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iiitd.ac.in; s=google; t=1796562012; x=1797166812; 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=b+oBjiGKnPzkfoOKA4vlzPGp3DMt3TmyXqjVPLJFuvY=; b=eofSirgdX+5kyCEsFSa+yStyplTx1dSfwK7eCOIM8MXLUqs6gDxRbCeQotkezm7x7/ ahy+Ir5bMpV92c2jQtEh1E0sP7VOUBkj1N9aGctDZsON1VkvbiJtevdmjyTIWSm2KWeI 0KxLCM1Q04FCzm6X6nU6MNEsMTe+0W9HrhyuA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796562012; x=1797166812; 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=b+oBjiGKnPzkfoOKA4vlzPGp3DMt3TmyXqjVPLJFuvY=; b=uDaQc6Tmzu6o5gzML/odTIoy+HuI2BRhW5U8UnKiK9qMxPVdDLCOJqaE6b5ary7c+9 nsxXl5kqy70CQffZEK4u9d9YYc8nnxxH1XTHGnaYWiEijMRA2EzEdPlPWj+p7rY7YcpF cL7wVfnUyFxRd18qMRZ263R7IJzXOp746n1yYnUWq3pAFwCuufbAQI0hEVBSdhV2QpQm FxO4jiCMP+6JJg1LZ67w9ON+VbskHhGMeMwdTn8BzK3CCNUeCYSnr7+6+cv1WB4vml/n R+MDxiyu36JikSlB6RzvKatNN7OQYpybagNC4L0/sXmhuJs4vb7QAsmfoWDPucaNLM3p Q5HA== X-Forwarded-Encrypted: i=1; AL+hErFy/lSygLnPXYvS0q+wjw4smYPl2kIdk8vShETOQ7J6Y5OTrjEfS7ZGkexJ4nKCWzBVQlzwnL1xLwBE1vQ=@vger.kernel.org X-Gm-Message-State: AB4q+uH5QRrw4kDHmh/uPc2Zydu/AaspwX4YMfG3OwmXWyaFJ7M5TrFi EUkrCgew4L/mbhK95C5oiKcvpWT/Bz38TyBeHAzpsFKFwGHV7QnMpRiUPOgxqoCgjqk= X-Gm-Gg: AZFdTZfyMfo2VS4lKcNT6ocAM3yZ+++S0gXbb4ajFWom2mdXc8JrX5XsIFL9eyfasGs ARCeMaQVPkrGnlqk6RzuzLN3907R6FBYY1fZ7zQuxwNcHb7wPSrEJfPh6lSbVF+SHhiNh6/zmsO /vUyJeR/C5N/dm6a/YHeKPhGGuxZYG984PGAaiejtRqpxYvEVW39I+zgya70Lqrwmhs32Kjk8vP gtz6Yz6aZMoVWkpwO/Uy/pBCMGmRrIk/FSkPbAy4cPor5VGVX/Jed8f3YqrNFJdeLm3LS/O6U+8 uhO5x+Dy3pEswPRMV3P5N6OdxVUM8RO4bs46Kelkic9c9Yn9ZkMeN2Cwcl0EBolzzt7osu1clEb dAwthlS/VqGwXRdvr09c0q0mCiecYduPXvpw8PY2MA0mnTH4eEpBLJx+FC8J/ho2yFT37IXeYw4 PTu1ENoOEYkeNMTJyuZGuHmIkC2Vf6BnobJh4cAkwaG8eaf6HrwUnxWK9puUZvXhUnO17Ww3FkK E9RYvCZlbKobC1uUuMI10R1SL6txCR91LGvXP27eXmNfHHwa+9X5+lVxCijR5i2lTNeC32IPTf8 qdoPwt+miuENFjH+8jnV04TvpiVrR1ufi3ZZeJqDsmy0oFmviENjY5/3KBkNvhIICBrS8m62w9q Ezf4+fQhgvObC88mONNI5spcGHj2R866WjgBVGPL0pCrpej8V84x0fOq4hO0dLlu2 X-Received: by 2002:a05:7301:160c:b0:386:ab85:a011 with SMTP id 5a478bee46e88-38742e09632mr9152147eec.27.1796562011190; Sun, 06 Dec 2026 05:00:11 -0800 (PST) Received: from iiitd-S2600STB.iiitd.edu.in ([103.25.231.160]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3875218c6a6sm31363491eec.5.2026.12.06.05.00.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Dec 2026 05:00:10 -0800 (PST) From: Piyus Kedia To: "Theodore Ts'o" , linux-ext4@vger.kernel.org Cc: Andreas Dilger , Baokun Li , Jan Kara , Ojaswin Mujoo , "Ritesh Harjani (IBM)" , Zhang Yi , linux-kernel@vger.kernel.org, Kapil Vaswani Subject: [BUG] ext4: readdir of an htree directory copies '..' from past the root block to user space Date: Sun, 6 Dec 2026 18:30:04 +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, For an indexed directory, readdir returns '.' and '..' from the htree root block, and ext4_htree_fill_tree() finds '..' by stepping over '.' by its rec_len: fs/ext4/namei.c:1055 (ext4_htree_fill_tree) if (start_hash < 2 || (start_hash ==2 && start_minor_hash==0)) { de = (struct ext4_dir_entry_2 *) frames[0].bh->b_data; de = ext4_next_entry(de, dir->i_sb->s_blocksize); tmp_str.name = de->name; tmp_str.len = de->name_len; err = ext4_htree_store_dirent(dir_file, 2, 0, de, &tmp_str); ext4_htree_store_dirent() copies de->inode, de->file_type and name_len bytes of de->name into the entry that getdents64() then returns (fs/ext4/dir.c:506-509). dx_probe(), which read the root just before, checks the dx_root_info and the index entries but neither directory entry, and nothing else on this path checks '.'.rec_len (with metadata_csum the root's checksum is found through it; see below). A '.'.rec_len of the block size puts '..' just past the root block, and its name_len, whatever byte lies there, becomes the length of the copy. The same two entries are checked before make_indexed_dir() uses them (ext4_check_dx_root(), 50ea741def58 "ext4: check dot and dotdot of dx_root before making dir indexed"), but not here. Our fuzzer made a filesystem with 4 KiB blocks, dir_index, no journal and no metadata_csum, a directory of 200 files (so it is indexed), set '.'.rec_len in its htree root to 0x1000, mounted the image again and called getdents64() on the directory: BUG: KASAN: slab-out-of-bounds in ext4_htree_store_dirent (fs/ext4/dir.c:509) Read of size 173 at addr ffff888019ff6008 by task syz-executor/11682 __asan_memcpy (mm/kasan/shadow.c:105) ext4_htree_store_dirent (fs/ext4/dir.c:509) ext4_htree_fill_tree (fs/ext4/namei.c:1060) ext4_dx_readdir (fs/ext4/dir.c:620) ext4_readdir (fs/ext4/dir.c:149) iterate_dir (fs/readdir.c:114) __do_sys_getdents64 (fs/readdir.c:404) The buggy address is located 8 bytes inside of allocated 88-byte region [ffff888019ff6000, ffff888019ff6058) (kmalloc-96) The root block is a page of the block device's page cache, so '..' is read from the start of whatever page follows it in memory: here an allocated kmalloc-96 object, whose byte 6 (173) became the length. What comes back to user space, measured upstream (4 KiB blocks, the root's '.'.rec_len 0x1000, getdents64() on the directory): - KASAN, when it reports, names the first poisoned access - in our runs the read of name_len (namei.c:1059) or the copy (dir.c:509) - after whatever object or page followed the block - a freed or allocated slab object (kmalloc-32, kmalloc-256, sgpool-16, names_cache) or a free page. It skips a memcpy() it reports, so that name comes back as zeros, but the loads of name_len, inode and file_type are done anyway: with kasan_multi_shot, d_ino came back as 0x47915500 and 0x43e387e0, the first 4 bytes of a freed sgpool-16 and a freed names_cache object. - KASAN reports once per boot. In a boot where it had already reported, ten fresh images read as root returned, as the name of '..': 255 bytes holding 5 to 14 kernel heap pointers (0xffff8880...) and up to 4 kernel text addresses (0xffffffff8.../9...) in 4 of 10, 248 bytes of 0xf8 in 3 (a KASAN shadow page, it appears: 0xf8 is what KASAN fills them with), one byte in 1, and getdents64() failed with EIO in 2 (name_len 0, rejected by verify_dirent_name()). For example, one name began 10 00 00 00 7a 00 88 06 40 36 79 1f 80 88 ff ff ... that is ffff88801f793640 at byte 8. d_ino came back with what look like the low halves of such pointers (0x1f793750, 0x272863c0, ...). - Read as uid 65534 (no groups, CapEff 0) in the same boot, 2 of 5 returned 255 and 173 bytes of kernel memory, with 3 and 5 heap pointers and 3 kernel text addresses each (ffffffff97841f20, ffffffff8808b380, ...); the other 3 failed with EIO. - Without KASAN nothing skips the copy; by the source every read returns the name_len bytes that follow the block, as in the runs above where KASAN no longer checked. Impact - who can trigger it: - A crafted ext4 image has to be mounted. ext4 is not FS_USERNS_MOUNT, so that 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. - Then anyone who can read the directory triggers it with getdents64() (ls, find, ...): measured as uid 65534 with no groups and CapEff 0, on a directory of mode 0755 - KASAN reported the same reads with "UID: 65534" in them, and the kernel memory above came back to that user. - The image needs dir_index and an indexed directory whose root's '.'.rec_len is changed; nothing else. With metadata_csum the root's dx checksum is located by '.'.rec_len (get_dx_countlimit()): 12, or the block size, in which case the count and limit are taken from byte 8 and the checksum from after them. A root with '.'.rec_len 4096 and a checksum written there passes (measured, 2 boots: no checksum error, the directory listed, and '..' read from past the block - 248 bytes of 0xf8 in one, the next page's own first entry in the other). So metadata_csum does not stop it; it only limits '.'.rec_len to the block size, which is enough. - Kernel memory disclosed to user space: up to 255 bytes as the name of '..' (from 8 bytes past the end of the root block) and 4 as its d_ino (from the first 4 bytes past it), out of whatever page follows the block in memory, read again by every readdir from the start of the directory. Measured: kernel heap pointers and kernel text addresses, as above (a text address gives away the KASLR offset). Without metadata_csum, '.'.rec_len can place '..' up to 64 KiB past the block, by the source; we ran 0x1000. Seen on 7.4.0-rc5 (the report above) and REPRODUCED ON UPSTREAM: on ksmbd-for-next (d70570cf8003, 2026-12-04), our upstream base, whose fs/ext4 is identical to mainline master (9437ee8b6cf6) and to the ext4 tree's dev branch (aceadbccd428, merged in 9437ee8b6cf6), with KASAN. fs/ext4/namei.c and fs/ext4/dir.c are also unchanged in mainline c3500c5ef648 (2026-12-04). Same config and image recipe before and after, the patch the only change, each run on a freshly made image: without the patch (6 boots, 29 readdirs of a crafted root, the fuzzer's program once): in all 29, '..' came back as something other than '..' - zeros (a copy KASAN had reported), kernel memory, 0xf8 bytes, another page's entry - or getdents64() failed with EIO (an empty name). KASAN reported in 4 of the 6 boots, the fuzzer's program's included; in the other 2 the memory after the block was not poisoned. with the patch (3 boots, one with kasan_multi_shot, 29 readdirs: the fuzzer's program, ours as root, as uid 65534 and with metadata_csum, and the fifteen-attempt loop): no KASAN report; getdents64() fails with EUCLEAN and the kernel logs EXT4-fs error (device loop0): ext4_htree_fill_tree:1063: inode #12: block 11: comm poc: bad entry in directory: '.' directory cannot be the last in data block - offset=0, inode=12, rec_len=4096, size=4096 fake=1 control, the root as written ('.'.rec_len 12; with the patch also with metadata_csum): 202 entries, '..' as on disk, on both kernels (2 boots each). A patch follows in reply to this mail. It checks '.' and then '..' with ext4_check_dir_entry() before ext4_htree_fill_tree() uses '..', as htree_dirblock_to_tree() checks the entries of the leaf blocks, and fails the readdir with -EFSCORRUPTED if either is bad. A '.' that passes ends at least 12 bytes before the end of the block, so '..' starts inside it, and a '..' that passes holds its name. The root the kernel and e2fsck write ('.' of 12 bytes, '..' to the end of the block) passes. Other places we read that use the root's '.' and '..': dx_probe() reads the dx_root_info at its fixed offset, not through '.'; the metadata_csum lookup of the root's checksum (get_dx_countlimit()) accepts only '.'.rec_len 12 or the block size and checks that what it then reads fits the block; a lookup of ".." searches block 0 with ext4_search_dir(), which bounds every entry by the block; ext4_get_first_dir_block() and ext4_empty_dir() check both entries with ext4_check_dir_entry(); make_indexed_dir() takes '..' at its fixed offset after ext4_check_dx_root() (we report a gap in that check separately: "ext4: make_indexed_dir() copies and wipes 4 GiB when '..' ends inside the dirent tail"). ext4_htree_fill_tree() is the only one that steps over '.' unchecked. 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 makes the image with mkfs.ext4 and edits it, and we are happy to send it on request. Kapil Vaswani Piyus Kedia