From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.50 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796458900; b=bN/QrtF9vrqe8TKC9Am2a4on/BsQOo2Ud1pJz7fDLb6lYYzBRRRfgemQ2fhNBONKpUfR nhR5fTB08eQGvjRBIScpCpgAzGTZRepXvmMRU04yUqCEb+NiEgt9MUCzLt0BovfJQ4jnP 4M19LyK4asiz6sM0ykkgL4Rcb/2Mka4xs5rHZsdEDBKTNdpnq5hRgJdsMQOuUiEXK/GLV cc1V+TxMSqO7yY43JIsmziN5cjq1WIdT6zOzFIBk6ET1apPKgm0r4buvYPtxuLOYGBIjp J/ELE1y4ctu2/3RK0dKZ2gXohnh8AXTQdI3GaDWn+sBxBWmXcM7DrJj8ANVly3/6sXw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796458900; 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:MIME-Version: Content-Transfer-Encoding; bh=82TRM9zzm2RWwhcfSux7K7U+D5mqlf1Xc/cjBBfOwaI=; b=mVZ9gte6a9JOE1WH66bsTUAzUcYdSMO0WC1woFjTnvcnHYxk3h6uI5NcrZjSMTrChCVm YKBFtwnvO4Hl5NdqLxd91HCoykSdX9bB/MpwTjJDPNZkQKC9k2v4xnGifkhMaVudFwZ4D 88RaCQwzbKzksQ/hnKG7S/tuHkTu9EPMgu1NQ8ngsd1OUAeKAX01f9D2aCAWzW3kPtH9T k9KtGksTHrKyH/n3dULvkIid81kK78ggHNTOU53kvyNYqf2/zLnpmns/ioenIDGkDx7qN aJeMpGjHxnbDTEHXdIEH3rs8w6RagWxtbVRa3MG0DlSmJW5tHD/iU2YN5Jjfdr5PuSA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=y0jmafNt; arc=none smtp.remote-ip=74.125.82.50 Received: from mail-dl1-f50.google.com (mail-dl1-f50.google.com [74.125.82.50]) (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 BB403606A32F for ; Sat, 5 Dec 2026 08:21:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BB403606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=y0jmafNt Received: by mail-dl1-f50.google.com with SMTP id a92af1059eb24-1b5d5f0ba39so1964877c88.0 for ; Sat, 05 Dec 2026 00:21:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796458899; x=1797063699; 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=82TRM9zzm2RWwhcfSux7K7U+D5mqlf1Xc/cjBBfOwaI=; b=y0jmafNtMCYYklPyip8SWYFS2VpDd1EyenWucjDbKHNrQFx8bYWBQ6UAzaJ2Y+qo/2 uxpPkGC1TH1I5+FssF7LNlw1PWTUPxGcTma3cL3H8yTORqSGGLZIAcH+EMqwUnjwzPqW Ry2uxSfIj0PvsR8y6qeCeBCe9bbrHaaF9hqes2vRRuOwRojB4yEj9qAUDjwch02yd/7j syJLkefd8+R9RHdHAPgZSKvGM+VMBe1oe9eJ/WdQXaSAg12Q8h+O+lpOt21Gqy1lrqCe a070au4EiniLt+ykl5k99uL3qx9eiifdEKFfD70/XBcJ9Xj4pI3J+Svr5YtKO+Fz1Dxz ml8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796458899; x=1797063699; 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=82TRM9zzm2RWwhcfSux7K7U+D5mqlf1Xc/cjBBfOwaI=; b=D7JB9i6Is9h3F9vjrwuh7c5MskQRHlUpTTnBaxg3uHgcTQWYbkV74wm4F8SdHrFpmo dg7hy55LI+oV2Yxgsqj+Of6DdbQ25XoIPb//fDhxe91fTlvMt4x3JLh0fL1ncbzcUfxV 1PN3I2kWIP+WOzW4iWtRbhASLKBSD/+xWJzgY2jB0ly11MfspGodhr5k3Vx8gJT+5hSk dJlf7J61db09Lk6OFr9SFtSuyRQDXhqNRyvLLLTPWlWx06gm5NEpQkS+EjGZszTxab4x sLW3bHHxC7BBbAasdHCgzj5BCceJeveS1oRUYNce80ANW/bZoSJQth5ojHxeByGoszaG kgCg== X-Forwarded-Encrypted: i=1; AL+hErFyGWOMDlfaG8a94M9A7x8e5df61TVt7zYuL0GATokVhvq9LG/06dQr61OeFsPOtDsT7yL3QwuDXt/kHVU=@vger.kernel.org X-Gm-Message-State: APuU4Z/vWzJ4A0Nr8Y9WQ2xMaEZeiDDDDfYsgXNi+UqKsqD32vqoyCST uRTshexv8ueAFB0lG8ZV1RvWw3SBDK8+bJwZIqUiQExv7GHE5h+4ANJS X-Gm-Gg: AZFdTZfy4L9MArI7YPv1RJhzSBuaBS3bFVsBvG8fNPZUKzIladuahH7dwznATqQ4Cs0 GpS3VvCqfKoyj2MXqUVbIOya9bPruP+IZt/cWMOAe0cZS6fozBYyK1mTih4hqhH5RLRvaqkF7za 602Xf5Z1vkBT550xZhY92B79P7dYeOiBESCCV3Ex/FCGVt5IPp56i9liL/zJ8KtWqWWNjdThOth UrUzCaNMOStJ50jwdDkPUc1GGx/Gurc78ifgw3tsndomVYgxH+GX603+VLn7vFH4xuHH//CF1/G WYqH8m0fhyh0GSMULIDIpLyID7sTBpH6Nb2i5tr0ixntLB4uHO+5x+My6m0uj2oPpb0XYbx9CoS KJ3AAw5xhA4MEd90vYwsa3xKgnsrhYzP+cwttvJqiXH1DDbAdplm54BSZvSNYG59+XzkRT5G0we CME44Mn0VnwKvDKgkXsiIv2G6atV6Ogyjx17OxvQ0wt6z/cAjMHPWbMly3a7P/GVNC9VuaVQpsq JREzieGuyP6EmohswNbNg2jSzOj3+liVke6cACO8SCuYWv7RPZBkp9LJq7cMTX8BrFn4hyY6jy8 KnBwC9/SIsefqERiRp3oPLegzgMRyjuYBzWsoyohM11TGtxvG/6RRGhLlNS9hayhbPA= X-Received: by 2002:a05:7022:7f0e:b0:1b5:6441:a323 with SMTP id a92af1059eb24-1b5d70cea74mr4082389c88.9.1796458898851; Sat, 05 Dec 2026 00:21:38 -0800 (PST) Received: from d4082dd914b5.tail196be.ts.net (vldb.skku.ac.kr. [115.145.173.180]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5d644171bsm14023990c88.7.2026.12.05.00.21.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 00:21:38 -0800 (PST) From: Kyuwon Cho To: Theodore Ts'o , Andreas Dilger Cc: Jan Kara , Baokun Li , Ojaswin Mujoo , Ritesh Harjani , Zhang Yi , linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] ext4: validate dot entry before reading dotdot in htree readdir Date: Sat, 5 Dec 2026 17:21:34 +0900 Message-ID: <179637501338.1425433.8835682775805888953@gmail.com> 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 ext4_htree_fill_tree() locates the dotdot entry by advancing over the dot entry according to its on-disk record length. A corrupt record length can make that advance land outside the dx root block before the code reads the resulting entry. Require the advance to land at the fixed dotdot position in struct dx_root. Do this before storing either root entry because the readdir rb-tree persists across calls, and an error must not leave a partial entry queued there. The check only runs while the root entries are emitted by readdir and adds no work to indexed lookups. Fixes: ac27a0ec112a ("[PATCH] ext4: initial copy of files from ext3") Signed-off-by: Kyuwon Cho --- Changes in v2: - Validate the '.' rec_len before inserting '.' into the rb-tree, so an error cannot leave partial state for a later readdir. This addresses the Sashiko AI review: https://lore.kernel.org/all/sashiko-outbox-249274@kernel.org/ v1: https://lore.kernel.org/all/179636470936.1110822.11479118660789833770@gmail.com/ While testing v7.4-rc3 with an LLM-guided test generator that we are developing as a research prototype, we found this issue. A reproducer is available on request. fs/ext4/namei.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index b2753daad49f..95dd2d1a76c2 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -1041,9 +1041,19 @@ int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash, if (IS_ERR(frame)) return PTR_ERR(frame); + if (start_hash < 2 || (start_hash == 2 && start_minor_hash == 0)) { + de = (struct ext4_dir_entry_2 *)frames[0].bh->b_data; + if (unlikely(ext4_rec_len_from_disk(de->rec_len, + dir->i_sb->s_blocksize) != + offsetof(struct dx_root, dotdot))) { + EXT4_ERROR_INODE(dir, "Corrupt dir, invalid rec_len for '.'"); + err = -EFSCORRUPTED; + goto errout; + } + } + /* Add '.' and '..' from the htree header */ if (!start_hash && !start_minor_hash) { - de = (struct ext4_dir_entry_2 *) frames[0].bh->b_data; tmp_str.name = de->name; tmp_str.len = de->name_len; err = ext4_htree_store_dirent(dir_file, 0, 0, @@ -1053,7 +1063,6 @@ int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash, count++; } 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;