From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796562843; b=pgin5H+IX+qNbos8vLQwevTsmuOFqftQDfhXoyNSoKJWRkksGBLmKOr0G+KGgs3B2dxO rxwO+NkN/F0Rfi9Xu12Sntmnth9GRkBp3Q2spxZIHi7WCPehDuP+QzSg7XMbvk8+XXB+R yRXIR4vQ2XSCEdRqAB0jMaHTnkOcOWcddH7yMfuPwTKNobPPHWgRR5zHHcMhJ1+Kxkhur EZZOQUkkAjUqIqjWK2q2jlyJNNl9DvIzq8ITysd4MsQcQ47FQpqBp88kIyDN6pIh6Gxz6 VMKIRclAB5SHEPZIiz+I2qjmfA3RYjIja9zeGw7S37Onnh2iRepqi27SDDGmXHSNE4w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796562843; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=rgyASbCfFtsHxpj6rvFKFKQmBRzABaVQVX45qwgSKEI=; b=pXftwFFwLaJe7nXT/PFiucBJifcOI5CWDTeX6X7MQMH9Pe5w0M28KHLcV9XF54jE3tfN U1ng20EqAZhNzHnSdAAnHIYS+OB3Ucjr+2L6UNKlmoQGJ+FMVTVR3fM7zTaZvewWNpUXM NrVYDH/YBMLHh/4fjdgJQfQkGUwx6ZmlzFfFyEDXSCTrbR5ScaXgvUoYK8aaYLzO0bW5+ LMAny+4YwS+jU9HndR8v27aBb625sXefd8qqwyvqBgDBFstq1cGLrxRKaZ5ae34cSNYoo 9t14ddWrjHBZfg3BCxIm2L2ezRIVzN9nC1DSN5/8b7S1U+wUBHNDnFapF41L4Hd9QFQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=fldS3si9; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 41B22606A31F for ; Sun, 6 Dec 2026 13:14:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=fldS3si9 Received: by smtp.kernel.org (Postfix) with ESMTPSA id A09731F0092B; Sun, 6 Dec 2026 13:14:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796562842; bh=rgyASbCfFtsHxpj6rvFKFKQmBRzABaVQVX45qwgSKEI=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=fldS3si9relpYR9rEk0Yz8WXHS5lGe959zKeV7LXysw1Zu1CBwH3h3d564wp0wHFw iP1qV8vNy27WYUsSC1cpkn9y8hD/wFzBzm7nYRk9mA1nU1ecvY+o+UgD6MOEdfC0OS qlXHC10Cq91KxuNwhybGUbMBkmosUvjkI7Nw/B4wK7pAfHLgMpn/wCG36jx7TwT9HP JW5pnJbl5KcHK2uvwpnFHDNzA0tzlH4RTEPdWschUdTdxTJ0cx5jWtxS5AzjxLel+n 7B/4MST61iVI0cP4Wg67LH4BoQgym0Y1KlpVKl1A97sLZf+McoH90vwm/rxWjnNjVc YpHp8cVFFEQ5w== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] ext4: check dot and dotdot of the htree root before readdir uses them Reply-To: sashiko-reviews@lists.linux.dev To: "Piyus Kedia" , linux-ext4@vger.kernel.org Cc: tytso@mit.edu In-Reply-To: <20261206130012.1327058-1-piyus@iiitd.ac.in> References: <20261206130012.1327058-1-piyus@iiitd.ac.in> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 06 Dec 2026 13:14:02 +0000 X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] ext4: OOB read in ext4_htree_fill_tree() when entry 0 is not dot - [Medium] ext4: ext4_htree_fill_tree() stores unvalidated dot entry before checking it -- commit 8909302584683de8683d0cfae7c7f0e4a46d181d Author: Piyus Kedia ext4: check dot and dotdot of the htree root before readdir uses them This commit validates the '.' and '..' entries in an indexed directory's root block with ext4_check_dir_entry() in ext4_htree_fill_tree() before storing '..' for readdir. > diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c > index b2753daad49f4..5ca84f600c9b0 100644 > --- a/fs/ext4/namei.c > +++ b/fs/ext4/namei.c > @@ -1053,8 +1053,24 @@ int ext4_htree_fill_tree(struct file *dir_file, __= u32 start_hash, > count++; > } > if (start_hash < 2 || (start_hash =3D=3D2 && start_minor_hash=3D=3D0)) { > - de =3D (struct ext4_dir_entry_2 *) frames[0].bh->b_data; > + struct buffer_head *bh =3D frames[0].bh; > + > + /* > + * '..' is found by stepping over '.' by its rec_len, which > + * dx_probe() does not look at: check both entries first. > + */ > + de =3D (struct ext4_dir_entry_2 *)bh->b_data; > + if (ext4_check_dir_entry(dir, NULL, de, bh, bh->b_data, > + bh->b_size, 0)) { > + err =3D -EFSCORRUPTED; > + goto errout; > + } [Severity: Medium] Can this leave an unvalidated '.' entry stranded in dir_file's rbtree when ext4_check_dir_entry() fails? When start_hash and start_minor_hash are both zero, the preceding block has already inserted entry 0 into info->root via ext4_htree_store_dirent(). If either check here then returns -EFSCORRUPTED, ext4_dx_readdir() exits without calling free_rb_tree_fname(&info->root) and leaves next_hash at 0. On a subsequent getdents64() on the same fd, ext4_dx_readdir() picks up that node via rb_first(&info->root), emits the unvalidated entry, and loops at f_pos =3D=3D 0 because getdents64() returns the positive byte count inst= ead of -EFSCORRUPTED once an entry has been copied out. Validating '.' and '..' before the if (!start_hash && !start_minor_hash) block would prevent storing an unvalidated entry. > de =3D ext4_next_entry(de, dir->i_sb->s_blocksize); > + if (ext4_check_dir_entry(dir, NULL, de, bh, bh->b_data, > + bh->b_size, (char *)de - bh->b_data)) { > + err =3D -EFSCORRUPTED; > + goto errout; > + } [Severity: High] Can the second ext4_check_dir_entry() still read past the end of bh->b_data if entry 0 is not named '.'? __ext4_check_dir_entry() only rejects next_offset =3D=3D size when the entr= y is named '.': fs/ext4/dir.c:__ext4_check_dir_entry() { ... else if (unlikely(next_offset =3D=3D size && de->name_len =3D=3D 1 && de->name[0] =3D=3D '.')) error_msg =3D "'.' directory cannot be the last in data block"; else return 0; } If entry 0 has rec_len =3D=3D blocksize and any other name (e.g. name_len = =3D=3D 0), it passes the first check and get_dx_countlimit() even with metadata_csum. ext4_next_entry() then sets de to bh->b_data + bh->b_size, so the second ext4_check_dir_entry() reads past the buffer via de->rec_len and de->inode. Checking (char *)de >=3D bh->b_data + bh->b_size (or verifying that entry 0 is '.') before the second ext4_check_dir_entry() call would close this. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261206130012.1327= 058-1-piyus@iiitd.ac.in?part=3D1