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=1796329278; b=CRbyARZpNvYFSynLauntlAEE60TZXc4BDXlNSCYrAPUCj0pyCwsm8N4j5iKMLChr/NKH n9WI+nGMKDLChAZf82biiE4JQ0EPdDSmLaiCvAU5a58SfHuOy5rkELzip0rc4JMnI84rW 1CadDOhwG0ODn0lgTmMzEdAuUZK08qmuZUQBLZl7n4Vvsc27jHslByHbzRiacxjYqFKpZ qrXD+PE8/djoVIR3BaRixcvc+jiDN6AAVFQBEg4EP5pexrAL+pHaM1NMdljr9y7WCdtc0 8o3ExIWLvVnwJYyAh/NvdPzv+9HRsxdLy4JlbxZ9Y8TqD3fni1xIhj+r5+yFYVm4XIA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796329278; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=Kz7FDQfvJfdmQknUmNeiEovkqk9F5HXaxCwj585kL8w=; b=3MsUwL+dVk48w2C2vsg4cvGcX3vvLFIRo9+/uecg77KnaDO2doR7O4+CHdID+AlSofmU kMt84+LyiAjl02Oce1bekHL/RlGI67iIle0SLs7aMhjPsynDRs15swnLQXrryBwLTkL/4 +NkkVM6RoQcUQzadOgP1iExNqfnTFtQyY5JswxlA/Ng5Ilrh6mVUaAqbJBHNlhc+N0HLX W0dSLYIo3LG+ffg1tDl19ayKrfIhvecSM9IjQMpOAIqMNdLO2OjBeRCcV56P4dxQBCUwL 2vckYVBk1b114Qdd08bp48GuLBnqo3FlJhOIKJKOrlQC6+fA/LU5DUR37B2uT10CcJw== 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=hNpe0oXc; 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 51928606A32C for ; Thu, 3 Dec 2026 20:21:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hNpe0oXc Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12A491F000C2; Thu, 3 Dec 2026 20:21:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796329278; bh=Kz7FDQfvJfdmQknUmNeiEovkqk9F5HXaxCwj585kL8w=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=hNpe0oXcQvo1CHPgBN+tB8Eit0yoU8Yzw9wajHH0r/wyRp+5mbkVKRx5TcCxHKujf iAM+/Wq0TM6GDunR9k/j6Tfj7ruXspKIdFbZ7GhnYQRigVVNqoS76gNeF0T7Q33h7E wF+X/UKfJTs7pOqO326p47/O1e5mxDGErMKjeO8dQAxoYbjjjJE5bsdOfGrcrutCRZ GTQIn6r7f2n3cLYmrwshJg0oMbbOOONCvAZRL/XCkb1sTkcRMaptm325snAltXgduU JUslQropm5SJQfjUyWYyecuOIqeO2fZ15TzHTG2+iDJmr5RJJ5t85eCUs+Csb7wkay SJ8UiDw9RctzA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v15 06/13] ext4: refactor dx_root to support variable dirent sizes Reply-To: sashiko-reviews@lists.linux.dev To: "Artem Blagodarenko" , linux-ext4@vger.kernel.org Cc: tytso@mit.edu In-Reply-To: <20261203184938.422849-7-ablagodarenko@thelustrecollective.com> References: <20261203184938.422849-1-ablagodarenko@thelustrecollective.com> <20261203184938.422849-7-ablagodarenko@thelustrecollective.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 20:21:17 +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 5 potential issues to consider: - [Medium] ext4: dx_get_dx_info() misses 4-byte alignment check on rec_len - [Medium] ext4: dx_get_dx_info() offset shifts after make_indexed_dir() updates dotdot - [Medium] ext4: ext4_dx_add_entry() mutates root before dx_get_dx_info() - [Low] ext4: unnecessary dir parameter and dx_get_dx_info() call in dx_release() - [Low] ext4: dx_probe() regresses ext4_warning_inode() to ext4_warning() with %d -- commit 8c7de95a1909ec95132a5dca0d865a06d32ff26e Author: Artem Blagodarenko ext4: refactor dx_root to support variable dirent sizes This commit splits struct dx_root_info out of struct dx_root and adds dx_get_dx_info() and ext4_dir_entry_len() so htree root blocks can locate dx_root_info when '.' and '..' have variable sizes. > diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c > index 8fc39c91b6ef8..edbe033b623e6 100644 > --- a/fs/ext4/namei.c > +++ b/fs/ext4/namei.c > @@ -443,6 +443,46 @@ static inline int ext4_handle_dirty_dx_node(handle_t= *handle, [ ... ] > +static struct dx_root_info *dx_get_dx_info(struct inode *dir, void *de_b= uf) > +{ > + unsigned int blocksize =3D dir->i_sb->s_blocksize; > + struct ext4_dir_entry_2 *de =3D de_buf; > + unsigned int off, rlen, need; > + > + rlen =3D ext4_rec_len_from_disk(de->rec_len, blocksize); > + if (rlen < EXT4_BASE_DIR_LEN || rlen + EXT4_BASE_DIR_LEN > blocksize || > + ext4_dir_entry_len(de, blocksize, NULL) > rlen) > + return ERR_PTR(-EFSCORRUPTED); > + off =3D rlen; > + > + de =3D (struct ext4_dir_entry_2 *)((char *)de_buf + off); > + rlen =3D ext4_rec_len_from_disk(de->rec_len, blocksize); > + if (rlen < EXT4_BASE_DIR_LEN || off + rlen > blocksize || > + ext4_dir_entry_len(de, blocksize, NULL) > rlen) > + return ERR_PTR(-EFSCORRUPTED); > + off +=3D ext4_dir_entry_len(de, blocksize, NULL); [Severity: Medium] Can an unaligned '.' rec_len cause dx_get_dx_info() to return a misaligned struct dx_root_info pointer? dx_probe() passes the raw root block directly to dx_get_dx_info() without running __ext4_check_dir_entry(). When blocksize is below 65536 and '.' has an unaligned rec_len (such as 13), rlen passes the checks here, leaving '..', dx_root_info, and the dx_entry array unaligned and causing alignment faults on strict-alignment architectures. Checking (rlen & EXT4_DIR_ROUND) would reject unaligned entries. Also, ext4_dir_entry_len(de, blocksize, NULL) is called twice on '..' and could be cached in a local variable. [ ... ] > @@ -640,23 +680,31 @@ dx_probe(struct ext4_filename *fname, struct inode = *dir, > if (IS_ERR(frame->bh)) > return (struct dx_frame *) frame->bh; > =20 > - root =3D (struct dx_root *) frame->bh->b_data; > - if (root->info.hash_version !=3D DX_HASH_TEA && > - root->info.hash_version !=3D DX_HASH_HALF_MD4 && > - root->info.hash_version !=3D DX_HASH_LEGACY && > - root->info.hash_version !=3D DX_HASH_SIPHASH) { > - ext4_warning_inode(dir, "Unrecognised inode hash code %u", > - root->info.hash_version); > + info =3D dx_get_dx_info(dir, (struct ext4_dir_entry_2 *)frame->bh->b_da= ta); > + if (IS_ERR(info)) > + goto fail; > + if (info->info_length !=3D sizeof(struct dx_root_info)) { > + ext4_warning_inode(dir, "corrupted htree: info_length %u", > + info->info_length); > + goto fail; > + } > + if (info->hash_version !=3D DX_HASH_TEA && > + info->hash_version !=3D DX_HASH_HALF_MD4 && > + info->hash_version !=3D DX_HASH_LEGACY && > + info->hash_version !=3D DX_HASH_SIPHASH) { > + ext4_warning(dir->i_sb, > + "Unrecognised inode hash code %d for directory #%llu", > + info->hash_version, dir->i_ino); > goto fail; > } [Severity: Low] Was switching ext4_warning_inode() back to ext4_warning() with %d intentional? This drops current->comm from the log message, formats unsigned u8 hash_version with %d instead of %u, and is inconsistent with the surrounding ext4_warning_inode() calls in dx_probe(). [ ... ] > @@ -783,7 +829,7 @@ dx_probe(struct ext4_filename *fname, struct inode *d= ir, > return ret_err; > } > =20 > -static void dx_release(struct dx_frame *frames) > +static void dx_release(struct inode *dir, struct dx_frame *frames) > { > struct dx_root_info *info; > int i; > @@ -792,7 +838,18 @@ static void dx_release(struct dx_frame *frames) > if (frames[0].bh =3D=3D NULL) > return; > =20 > - info =3D &((struct dx_root *)frames[0].bh->b_data)->info; > + info =3D dx_get_dx_info(dir, (struct ext4_dir_entry_2 *)frames[0].bh->b= _data); > + if (IS_ERR(info)) { > + /* Cannot determine indirect_levels; release all frame buffers > + * that may have been loaded to avoid leaking them. */ > + for (i =3D 0; i < EXT4_HTREE_LEVEL; i++) { > + if (!frames[i].bh) > + break; > + brelse(frames[i].bh); > + frames[i].bh =3D NULL; > + } > + return; > + } [Severity: Low] Does dx_release() need the dir parameter or dx_get_dx_info() at all? Every caller allocates frames[EXT4_HTREE_LEVEL] and zero-initializes it via dx_probe() or make_indexed_dir(). Using the bounded loop over EXT4_HTREE_LEVEL unconditionally avoids re-parsing the root block on every htree release and avoids adding the dir argument to all callers. [ ... ] > @@ -2096,17 +2165,22 @@ static int make_indexed_dir(handle_t *handle, str= uct ext4_filename *fname, > return retval; > } > =20 > - root =3D (struct dx_root *) bh->b_data; > - if (!ext4_check_dx_root(dir, root)) { > + dot_de =3D (struct ext4_dir_entry_2 *)bh->b_data; > + if (!ext4_check_dx_root(dir, dot_de, &dotdot_de, &de)) { > brelse(bh); > return -EFSCORRUPTED; > } > =20 > + /* Find room for the hashing info before the directory is changed */ > + dx_info =3D dx_get_dx_info(dir, dot_de); > + if (IS_ERR(dx_info)) { > + EXT4_ERROR_INODE(dir, "no room for htree root info"); > + brelse(bh); > + return PTR_ERR(dx_info); > + } [ ... ] > @@ -2137,24 +2211,26 @@ static int make_indexed_dir(handle_t *handle, str= uct ext4_filename *fname, > ext4_initialize_dirent_tail(bh2, blocksize); > =20 > /* Initialize the root; the dot dirents already exist */ > - de =3D (struct ext4_dir_entry_2 *) (&root->dotdot); > - de->rec_len =3D ext4_rec_len_to_disk( > - blocksize - ext4_dir_rec_len(2, NULL), blocksize); > - memset (&root->info, 0, sizeof(root->info)); > - root->info.info_length =3D sizeof(root->info); > + dotdot_de->rec_len =3D > + ext4_rec_len_to_disk(blocksize - le16_to_cpu(dot_de->rec_len), > + blocksize); [Severity: Medium] Can expanding dotdot_de->rec_len here shift the offset that later dx_get_dx_info() calls compute, corrupting the newly indexed directory? ext4_dir_entry_len() calls ext4_dirent_get_data_len() even without the dirdata feature. If '..' has an upper bit set in file_type and a byte >=3D 2 at offset 11, ext4_dirent_get_data_len() returns 0 while rec_len is 12, so make_indexed_dir() writes dx_root_info at offset 24. After dotdot_de->rec_len is expanded to cover the rest of the block, ext4_dirent_get_data_len() accepts that same byte and later dx_get_dx_info() calls resolve dx_root_info inside the dx_entry array. Guarding dirdata parsing on the dirdata feature would avoid this. [ ... ] > @@ -2472,11 +2548,17 @@ static int ext4_dx_add_entry(handle_t *handle, st= ruct ext4_filename *fname, > /* Set up root */ > dx_set_count(entries, 1); > dx_set_block(entries + 0, newblock); > - dxroot =3D (struct dx_root *)frames[0].bh->b_data; > - dxroot->info.indirect_levels +=3D 1; > + info =3D dx_get_dx_info(dir, (struct ext4_dir_entry_2 *) > + frames[0].bh->b_data); > + if (IS_ERR(info)) { > + err =3D PTR_ERR(info); > + brelse(bh2); > + goto journal_error; > + } > + info->indirect_levels +=3D 1; [Severity: Medium] Can mutating entries in frames[0].bh before calling dx_get_dx_info() leave the root block partially updated or shift info into entries[]? Because '..' spans the rest of the root block and ext4_dir_entry_len() parses dirdata unconditionally, stray upper bits in '..' file_type can make ext4_dirent_get_data_len() read into entries[0].block. Writing newblock can change a byte that was zero during dx_probe() to non-zero. dx_get_dx_info() then either returns -EFSCORRUPTED after frames[0].bh was modified and dir->i_size grown by ext4_append(), or returns a shifted pointer so info->indirect_levels +=3D 1 corrupts an index entry. Calling dx_get_dx_info() before ext4_append() and before mutating entries, as make_indexed_dir() does, would avoid both. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203184938.4228= 49-1-ablagodarenko@thelustrecollective.com?part=3D6