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=1796337006; b=jSnxLfTtq+qCssnAOx6gE6oaBdeXngJoxc2o+g4dJ4BsecpftSVxnxhO2ZKreyc637fv aO1YDfIiw96oOcNSwC1Wwx6Ur/J9D0wHE1y5IAMn8KoHLwf96Sq/JjeM3j41p+FIOYeew jVVzsWxqWT5fQIy8xRHOrlDpKlPViBKa9YRAIstSL2LohRmVIUg8hd4b8qnh1fSjTh1Pf 1/JZmsmLyizfn1IOiTOROpCJzkF8YdKRKRk4iAYayAqb/SQ38s0JzB8Y+aejDF7qyQyu8 q3qZw5Z9rqgBAkylINoAFbj7d6SfnVNWq1amaeNHBia2nN+8cYxB9yR5cUFyna0WEOA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796337006; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=2+7PFNsljxTMGfbwKHVkcbTZ2I82inOBLk88fV7vusg=; b=4e+PgPwQuh63dDD2mqv7RbKUGhBGAyCdcQQRjZZx7kP74rvVeXRUbMH3JXcwn/IT2d4l 0dJmwQO74Yp4SPCRgUc6airnU62Kf7wDN3VGrmI4jeqUjmwBt3Ur2kuntJvv2ibpq1NwK TcnlZ4lhG/k0ac1jtzSgcZ3UR/fTu/3Wk1K2WmIeNLE8aFKwgO9HW4ZvXkzgpcyBCWFlr IAhX4WFyLg6uCaXgW56aFlu47SbKaJw4JiHkvgxFf3c2dsLoZp8I2NxlIcRHLrDJZMw0S +cREOipIF8Y5/rR8mSJmmObcYMrO9e+jBAD55eEkqKtQQwV0hQIX+MmL2EZLxx1nhDw== 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=HQHmCiMb; 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 54DB6606A32D for ; Thu, 3 Dec 2026 22:30:06 +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=HQHmCiMb Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F9C21F000CE; Thu, 3 Dec 2026 22:30:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796337006; bh=2+7PFNsljxTMGfbwKHVkcbTZ2I82inOBLk88fV7vusg=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=HQHmCiMbFipj6oLlQBSqQigMjrcQxoBnSDekhzNfVlIZ3UXUIRsH5w/E2alY3fEfw ybvl+vCE/GxycPDmZ7MILUTBqe8lp3DENGdIcYxIQ3US0lrlTAcbfC4YH0P8lSiR2T dmMcJt5/5b05gZfts4CBoxYPru8V49EEKat3cqd28Nf7/lcS3XXMwcc6wJ2psVi0Ju rPwMWL1X9yaezHpqyyZxKMmbk8Ua2R1KlB47FQGOAnd6bfs8WGORd3jrELSCJtx6dR lWaZSdzYGeJoMsWRrOUpGklWwnoYgYrjdPM3fCBvH2z9SSsT3vOswJAn8ooSE8kCAj Yy978zah051BA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v15 11/13] ext4: add dirdata set/get helpers Reply-To: sashiko-reviews@lists.linux.dev To: "Artem Blagodarenko" , linux-ext4@vger.kernel.org Cc: tytso@mit.edu In-Reply-To: <20261203184938.422849-12-ablagodarenko@thelustrecollective.com> References: <20261203184938.422849-1-ablagodarenko@thelustrecollective.com> <20261203184938.422849-12-ablagodarenko@thelustrecollective.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 22:30:05 +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 4 potential issues to consider: - [Medium] ext4: unchecked FILETYPE dependency when writing dirdata flags - [Low] ext4: inconsistent legacy hash fallback in ext4_dirdata_get() and docs - [Low] ext4: dx_show_leaf() still reads EXT4_DIRENT_HASH() directly - [Low] ext4: ext4_dirdata_get() lacks dfid buffer size check and tail entry guard -- commit 9f42fb8c06ee8e0280f7f4685eb005c37759c828 Author: Artem Blagodarenko ext4: add dirdata set/get helpers This patch adds ext4_dirdata_get(), ext4_dirent_hash_get(), and ext4_dirdata_set() to read and write dirdata records in directory entries, and converts existing casefold+encrypted hash readers and ext4_insert_dentry_data() to use them. > diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c > index 8a1c292ddd2f4..ae58ce5120e1e 100644 > --- a/fs/ext4/namei.c > +++ b/fs/ext4/namei.c [ ... ] > @@ -1196,6 +1200,239 @@ static inline int search_dirblock(struct buffer_h= ead *bh, > * Directory block splitting, compacting > */ > =20 > +/* > + * ext4_dirdata_get() - Read dirdata fields from a directory entry. [ ... ] > +unsigned char ext4_dirdata_get(struct ext4_dir_entry_2 *de, struct inode= *dir, > + int buf_size, > + struct ext4_dirent_fid *dfid, > + struct dx_hash_info *hinfo) > +{ [ ... ] > + if (de->file_type & EXT4_DIRENT_LUFID) { > + struct ext4_dirent_fid *disk_fid =3D > + (struct ext4_dirent_fid *)((char *)de + > + EXT4_BASE_DIR_LEN + data_offset); > + unsigned int dlen; > + /* struct ext4_fid df_fid[] does not provide the array size. > + * First, verify that the header lies within the valid area, then > + * verify that the entire record fits within it. */ > + if (EXT4_BASE_DIR_LEN + data_offset + > + sizeof(disk_fid->df_header) > rec_len) > + return ret; > + > + dlen =3D disk_fid->df_header.ddh_length; > + if (dlen =3D=3D 0 || > + EXT4_BASE_DIR_LEN + data_offset + dlen > rec_len) > + return ret; > + > + if (dfid) { > + memcpy(dfid, disk_fid, dlen); > + ret |=3D EXT4_DIRENT_LUFID; > + } > + data_offset +=3D dlen; > + } [Severity: Low] Can memcpy(dfid, disk_fid, dlen) overflow a caller-supplied dfid buffer? ddh_length is an on-disk u8 (up to 255 bytes), and ext4_dirdata_get() takes no destination buffer size parameter (unlike ext4_lufid_snapshot(), which checks dlen against its buffer size). Also, ext4_dirdata_get() does not skip directory checksum tail entries via ext4_dir_entry_is_tail(de). Because EXT4_FT_DIR_CSUM (0xde) has EXT4_DIRENT_LUFID set, a call with a non-NULL dfid on a tail entry treats a byte of det_checksum as ddh_length and can copy checksum bytes into dfid. Adding a dfid_size parameter and returning 0 early when ext4_dir_entry_is_tail(de) is true would prevent both. [ ... ] > +bool ext4_dirent_hash_get(struct ext4_dir_entry_2 *de, struct inode *dir, > + int buf_size, struct dx_hash_info *hinfo) > +{ > + unsigned int rec_len =3D ext4_rec_len_from_disk(de->rec_len, buf_size); > + > + if (ext4_has_feature_dirdata(dir->i_sb) && > + (de->file_type & ~EXT4_FT_MASK)) > + return ext4_dirdata_get(de, dir, buf_size, NULL, hinfo) & > + EXT4_DIRENT_CFHASH; > + > + if (ext4_dirent_rec_len(de->name_len, dir) > rec_len) > + return false; > + hinfo->hash =3D EXT4_DIRENT_HASH(de); > + hinfo->minor_hash =3D EXT4_DIRENT_MINOR_HASH(de); > + return true; > +} > + > +/* > + * ext4_dirdata_set() - Write dirdata fields into a directory entry. > + * @de: directory entry (name must already be set) > + * @dir: directory inode > + * @data: LUFID data to store (or NULL) > + * @fname: filename info carrying the casefold hash [Severity: Low] Should ext4_dirdata_get() and ext4_dirent_hash_get() agree on whether pre-dirdata hashes are read once EXT4_FEATURE_INCOMPAT_DIRDATA is enabled? ext4_dirent_hash_get() falls back to EXT4_DIRENT_HASH(de) whenever no dirdata bits are set in de->file_type, even with dirdata enabled. ext4_dirdata_get() instead restricts that fallback to !ext4_has_feature_dirdata(dir->i_sb), and its compatibility comment states that pre-dirdata entries are misread as having no hash after dirdata is enabled. Separately, the doc comment above ext4_dirdata_set() documents @data while the parameter is named dfid. [ ... ] > + if (dfid) { > + unsigned int dlen =3D dfid->df_header.ddh_length; > + > + if (EXT4_BASE_DIR_LEN + data_offset + dlen > rec_len) { > + EXT4_ERROR_INODE(dir, "Can not insert FID"); > + return; > + } > + > + memcpy((char *)de + EXT4_BASE_DIR_LEN + data_offset, dfid, dlen); > + de->file_type |=3D EXT4_DIRENT_LUFID; > + data_offset +=3D dlen; > + } > + > + if (ext4_hash_in_dirent(dir)) { > + if (ext4_has_feature_dirdata(dir->i_sb)) { > + struct ext4_dirent_hash *dh =3D > + (struct ext4_dirent_hash *)((char *)de + > + EXT4_BASE_DIR_LEN + data_offset); > + > + if (EXT4_BASE_DIR_LEN + data_offset + sizeof(*dh) > rec_len) { > + EXT4_ERROR_INODE(dir, "Can not insert dhash dirdata"); > + return; > + } > + > + dh->dh_header.ddh_length =3D sizeof(*dh); > + dh->dh_hash =3D cpu_to_le32(hinfo->hash); > + dh->dh_minor_hash =3D cpu_to_le32(hinfo->minor_hash); > + de->file_type |=3D EXT4_DIRENT_CFHASH; [Severity: Medium] Does ext4_dirdata_set() assume EXT4_FEATURE_INCOMPAT_FILETYPE is enabled? Dirdata flags live in the upper bits of de->file_type, which is the upper byte of name_len when filetype is disabled. ext4_feature_set_ok() does not reject mounting a filesystem with EXT4_FEATURE_INCOMPAT_DIRDATA and without EXT4_FEATURE_INCOMPAT_FILETYPE, while ext4_setent() gates its rename LUFID maintenance on ext4_has_feature_filetype(), leaving stale LUFID records after a rename. Should ext4_feature_set_ok() require EXT4_FEATURE_INCOMPAT_FILETYPE when EXT4_FEATURE_INCOMPAT_DIRDATA is set? [ ... ] > @@ -1219,11 +1456,13 @@ static int dx_make_map(struct inode *dir, struct = buffer_head *bh, > ((char *)de) - base)) > return -EFSCORRUPTED; > if (de->name_len && de->inode) { > - if (ext4_hash_in_dirent(dir)) > - h.hash =3D EXT4_DIRENT_HASH(de); > - else { > + if (ext4_hash_in_dirent(dir)) { > + if (!ext4_dirent_hash_get(de, dir, blocksize, > + &h)) > + return -EFSCORRUPTED; > + } else { > int err =3D ext4fs_dirhash(dir, de->name, > - de->name_len, &h); > + de->name_len, &h); > if (err < 0) > return err; > } [Severity: Low] Was dx_show_leaf() missed when converting EXT4_DIRENT_HASH(de) callers to ext4_dirent_hash_get()? Under DX_DEBUG and CONFIG_FS_ENCRYPTION, dx_show_leaf() still reads EXT4_DIRENT_HASH(de) directly (before its entry bounds check), which reads the wrong offset on dirdata-enabled casefolded+encrypted directories. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203184938.4228= 49-1-ablagodarenko@thelustrecollective.com?part=3D11