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=1796562014; b=QTXjh3R+djkrwgFJWNGU09y3TgnL6ZFiM6s+OVbt7WfA8KlRZ+WtztwGLHcM4JxK9JO7 rtWvcJySipBnesRHSV2+MTGFrpTjBIiLj11tu/yc2y9D4zoqU6SHvwCdLvshlf1JJ3yrs cfoHfp45lr4ibFtv0g/KovTl3o3nW7FbjUlGDcwuFFTT3rVuqgBVU/M+NHugHys+Mick7 XxAYohLmgvWdNsnauElyaOxhx5oe/Uib+RUqoYE1fbZYiTulKHHCynlHVL0EpP8cXFff1 zweJkzsVpa6CZuocj2+DDVcigEMvxTRqd1Ftfu4miK74a08hP1PDEjxF/QoClaDxsyA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796562014; 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=FXX2ABl9VICixG+GVRlZPXWzNw0DSAnvgj1UBQvwC1EaNhzAhCH67Bu2Yj+YMGH/I7Q8 ru90yJr5lHA9M+baRr0HozLlsHNz/ULgUd8x2wTDaF4Jtu0YYbZtx7/l1ikXHRtroJnOk utaoKR7S5y2dOcRnzdWnKdO859bHUjGAZ9gLPjR6h1oTBjXF4VT2W5P1bkOyQGN1i4Bna qWuYmCuEiCwXHqXDfmrk9YNqFa85+bNa4EEQfvSmqm15su5xSccvwDDwIpfFMbSu0YoBo uK+scIKcj0hVLEWHDd46IMX/QBYIcV2CF3YTpzdNiV5tqKh8FmpMJgi/SSgiEUB0wOw== 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=fGHc67a9; 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 2B1D4606A683 for ; Sun, 6 Dec 2026 13:00:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2B1D4606A683 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=fGHc67a9 Received: by mail-dy1-f178.google.com with SMTP id 5a478bee46e88-386c336eab8so4248185eec.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=1796562013; x=1797166813; 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=fGHc67a9hmVQRYMtogIOJ43oIEsVRIuHOUNa79L/XTGEOZy26pef+RjqI+C6nnJeCf GaFnHvoCiE/GE89Ns1lEjerEk8zHQQtjwANPtpF0ctba+3fhWkxMui7r5t6uyhIRlSJ7 XldPw8iP07FsKPPdMGC2fTKr07y9zmbmmuw5g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796562013; x=1797166813; 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=tU7SjJ3iXsRkL2GOBFaAwongDp55HCC/AinvGWdBrMrcU9+4/oaEJuLlcGKpifdnBx l1483t/mC9thhsdw14J3SR3idJJGgg2ktsgYpExjCcoeHM+/J6m2t5qI7GMiCsG2a487 RsVOsO6r1ALdMlOCbyrZfssTir4iRlc5HHDXLsFd+PmrHWTU/vnnyQKhh8ShPNzvjgKw mwClb0UFkw2QABjOu7SrHz+6smG7abr5FBRd3EOJzsQptYGFUn5s6zxrfQmwbt5RH9be ywuFQ3ne6kSqa+M5KDmLCHaPrrnOUu4wkEmtZspwEVehPzsfHTtQMB5NqRzXdd9V19+A EjeA== X-Forwarded-Encrypted: i=1; AL+hErFoRx3X2p2vxNVGJWKE6oxEjd5OyqG9XNYP89NXGalaYPh5X/E1L/UWsoRJs9CBh49l4vavonPH6Dud@vger.kernel.org X-Gm-Message-State: AB4q+uEa56uGjDSGy9QAsn9JGXTqRDCb96mVVX6VqeXzjPReUfXQc1HF Q57B4yr9A/3fYrIQPmka0Jp+rVNJ+LBZN9Vp0FaYDaysCSARbIb0MPI0yDhj3NsMZoc= X-Gm-Gg: AZFdTZc4ZrhWiKGTx8juvfYvnbcLWXBB9389+PFtBWh2AuUuAyBMb33BgpkfSCvm1Kh /275zG/bK3gq+6bG2THNqXQV7fYdkksT382YCBF64kwzRS1PTgYJ1i1UOKkpFkHAPuh40u7JbQg z5dXioB7oJ9eaPTWIVfGRYwwDKHrUHg3J+T2CchkBPh/fpjlfOefTUTC+L60Dp5/IFNuTwdQTZT x15J5Pz+BPz8akJCo8GZXHrXD2DadoP3ReE8S+XGzhJEaE93EPTmAUH1xGPHmV8kY8hPWBoVtHg H5echfWdLkPO7tSBEUOS8whHRe411zlsAeQNW1ybTbeFADzBQWbfyzmCDk1z7nXF8MuSvbYc5UJ oxbeoZuOS6eZadnD8wYn2HrOEBMS48sGyVlRNWBu8pj8jp6x2btrJuweLc2Q6pqes0tO7BIKWjz kb2Jweqex3/kYpjvU/h4mIfu1E2lp9b1myuosxjYxfPbx4o2yi37MN/coJu6Jy50ZfEOVWVSEuU Dd9zIoqHxCPKIogzg5mrjBMud8J8xdQ+zLkvbxr3l2K8RLeNOHj0dtbL4TdsjoU50y8tB6ZOPHD VKm/jZ4qilTNe3BnDvJ83qf2HretEs0TcZoWGove/HrESs/Bsnit6lcjBCa5BNKlFrL57mFFUWn Wp4IKbEno9RvWmRR0vTetrEKkS+QU9dr1b/OgIkvn7z/zmPtFd0QRhyJwxs0ybIkv 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-ext4@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