From: sashiko-bot@kernel.org
To: "Artem Blagodarenko" <artem.blagodarenko@gmail.com>,
linux-ext4@vger.kernel.org
Cc: tytso@mit.edu
Subject: Re: [PATCH v15 11/13] ext4: add dirdata set/get helpers
Date: Thu, 03 Dec 2026 22:30:05 +0000 [thread overview]
Message-ID: <sashiko-outbox-248742@kernel.org> (raw)
In-Reply-To: <20261203184938.422849-12-ablagodarenko@thelustrecollective.com>
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 <artem.blagodarenko@gmail.com>
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_head *bh,
> * Directory block splitting, compacting
> */
>
> +/*
> + * 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 =
> + (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 = disk_fid->df_header.ddh_length;
> + if (dlen == 0 ||
> + EXT4_BASE_DIR_LEN + data_offset + dlen > rec_len)
> + return ret;
> +
> + if (dfid) {
> + memcpy(dfid, disk_fid, dlen);
> + ret |= EXT4_DIRENT_LUFID;
> + }
> + data_offset += 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 = 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 = EXT4_DIRENT_HASH(de);
> + hinfo->minor_hash = 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 = 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 |= EXT4_DIRENT_LUFID;
> + data_offset += dlen;
> + }
> +
> + if (ext4_hash_in_dirent(dir)) {
> + if (ext4_has_feature_dirdata(dir->i_sb)) {
> + struct ext4_dirent_hash *dh =
> + (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 = sizeof(*dh);
> + dh->dh_hash = cpu_to_le32(hinfo->hash);
> + dh->dh_minor_hash = cpu_to_le32(hinfo->minor_hash);
> + de->file_type |= 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 = 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 = 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.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203184938.422849-1-ablagodarenko@thelustrecollective.com?part=11
next prev parent reply other threads:[~2026-12-03 22:30 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 18:49 [PATCH v15 00/13] Data in direntry (dirdata) feature, with KUnit tests Artem Blagodarenko
2026-12-03 18:49 ` [PATCH v15 01/13] ext4: validate count against limit in ext4_dx_csum_verify/_set Artem Blagodarenko
2026-12-03 19:03 ` sashiko-bot
2026-12-03 18:49 ` [PATCH v15 02/13] ext4: use the e2fsck limit for htree index nodes Artem Blagodarenko
2026-12-03 18:49 ` [PATCH v15 03/13] ext4: replace ext4_dir_entry with ext4_dir_entry_2 Artem Blagodarenko
2026-12-03 19:33 ` sashiko-bot
2026-12-03 18:49 ` [PATCH v15 04/13] ext4: add ext4_dir_entry_is_tail() Artem Blagodarenko
2026-12-03 18:49 ` [PATCH v15 05/13] ext4: add dirdata format definitions and access helpers Artem Blagodarenko
2026-12-03 19:59 ` sashiko-bot
2026-12-03 18:49 ` [PATCH v15 06/13] ext4: refactor dx_root to support variable dirent sizes Artem Blagodarenko
2026-12-03 20:21 ` sashiko-bot
2026-12-03 18:49 ` [PATCH v15 07/13] ext4: size the htree root from where its dx_entry array starts Artem Blagodarenko
2026-12-03 20:37 ` sashiko-bot
2026-12-03 18:49 ` [PATCH v15 08/13] ext4: rename ext4_dir_rec_len() and clarify dirdata usage Artem Blagodarenko
2026-12-03 21:05 ` sashiko-bot
2026-12-03 18:49 ` [PATCH v15 09/13] ext4: dirdata feature Artem Blagodarenko
2026-12-03 21:37 ` sashiko-bot
2026-12-03 18:49 ` [PATCH v15 10/13] ext4: add dirdata LUFID support for directory entry rename Artem Blagodarenko
2026-12-03 22:02 ` sashiko-bot
2026-12-03 18:49 ` [PATCH v15 11/13] ext4: add dirdata set/get helpers Artem Blagodarenko
2026-12-03 22:30 ` sashiko-bot [this message]
2026-12-03 18:49 ` [PATCH v15 12/13] ext4: Add EXT4_IOC_SET_LUFID ioctl for setting LUFID on directory entries Artem Blagodarenko
2026-12-03 23:01 ` sashiko-bot
2026-12-03 18:49 ` [PATCH v15 13/13] ext4: add KUnit tests for dirdata Artem Blagodarenko
2026-12-03 23:15 ` sashiko-bot
2026-12-03 23:15 ` [PATCH v15 00/13] Data in direntry (dirdata) feature, with KUnit tests sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-248742@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=artem.blagodarenko@gmail.com \
--cc=linux-ext4@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.