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 09/13] ext4: dirdata feature
Date: Thu, 03 Dec 2026 21:37:37 +0000 [thread overview]
Message-ID: <sashiko-outbox-248702@kernel.org> (raw)
In-Reply-To: <20261203184938.422849-10-ablagodarenko@thelustrecollective.com>
Thank you for your contribution! Sashiko AI review found 8 potential
issues to consider:
- [Medium] ext4: ext4_dir_entry_len() parses dirdata flags without
INCOMPAT_DIRDATA
- [Medium] ext4: allow mounting INCOMPAT_DIRDATA without
INCOMPAT_FILETYPE
- [Medium] ext4: missing rlen alignment and dirdata checks in
get_dx_countlimit()
- [Medium] ext4: ext4_feature_set_ok() allows dirdata without filetype
feature
- [Medium] ext4: enable EXT4_FEATURE_INCOMPAT_DIRDATA before dirdata
handlers exist
- [Low] ext4: misplaced bounds check and unchecked rec_len in
dx_show_leaf()
- [Low] ext4: unused data1/data2 parameters in ext4_init_new_dir_data()
- [Low] ext4: commit message omits feature enablement, LUFID, and API
changes
--
commit 9524cb5f9f3b3666d39ad56c5cf72650999c906d
Author: Artem Blagodarenko <artem.blagodarenko@gmail.com>
> ext4: dirdata feature
>
> When fscrypt and casefold are enabled together for a directory,
> all ext4_dir_entry[_2] in that directory store a n 8-byte hash
> of the filename after 'name' between 'name_len' and 'rec_len'.
>
> However, there is no clear indication there is important data
> stored in these bytes, which are only for padding and alignment
> in other directory entries. This adds complexity to code handling
> the on-disk directory entries, and there is no provision for other
> metadata to be stored in each dir entry after 'name'.
>
> The dirdata feature adds a mechanism to store multiple metadata
> entries in each dir entry after 'name' (including the fchash).
> The unused high 4 bits of 'file_type' are used to indicate whether
> additional data fields are stored after 'name'. If a bit is set,
> the corresponding dirdata record is present, starting after a NUL
> filename terminator. If present, a record starts with a 1-byte
> length (including the length byte itself) and the data immediately
> follows the length byte without any alignment.
>
> This allows up to four different dirdata records to be stored in
> each entry, and allows unhandled record bytes to be skipped without
> having to process the contents, providing forward compatibility.
>
> If and when the fourth and last dirdata record is needed, it is
> recommended to further subdivide it into sub-records, with
> the first byte being the total length, and then there being a
> second byte that gives the sub-record length, etc. as long as
> the total record length is less than 255 bytes. However, this
> would not affect compatibility with the current code since the
> record length would allow it to be skipped without processing.
>
> Signed-off-by: Pravin Shelar <pravin.shelar@sun.com>
> Signed-off-by: Artem Blagodarenko <artem.blagodarenko@gmail.com>
> Assisted-by: Claude:claude-opus-5-5
[Severity: Low]
This isn't a bug, but the commit message only describes the generic on-disk
dirdata format and fchash motivation, which were already introduced in
commit "ext4: add dirdata format definitions and access helpers". It omits
the actual changes made here: enabling EXT4_FEATURE_INCOMPAT_DIRDATA in
EXT4_FEATURE_INCOMPAT_SUPP and sysfs, adding ext4_dirent_data_corrupt() and
variable-size dot/dotdot handling in htree helpers, interpreting
dentry->d_fsdata as struct ext4_dentry_param via ext4_dentry_get_fid(),
marking fast-commit ineligible via EXT4_FC_REASON_DIRDATA, and introducing
ext4_insert_dentry_data() and ext4_init_new_dir_data().
[ ... ]
> diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
> index e34d91cd63ece..98014749e5d43 100644
> --- a/fs/ext4/ext4.h
> +++ b/fs/ext4/ext4.h
> @@ -2385,6 +2385,7 @@ EXT4_FEATURE_INCOMPAT_FUNCS(casefold, CASEFOLD)
> EXT4_FEATURE_INCOMPAT_FLEX_BG| \
> EXT4_FEATURE_INCOMPAT_EA_INODE| \
> EXT4_FEATURE_INCOMPAT_MMP | \
> + EXT4_FEATURE_INCOMPAT_DIRDATA | \
> EXT4_FEATURE_INCOMPAT_INLINE_DATA | \
> EXT4_FEATURE_INCOMPAT_ENCRYPT | \
> EXT4_FEATURE_INCOMPAT_CASEFOLD | \
[Severity: Medium]
Does adding EXT4_FEATURE_INCOMPAT_DIRDATA here allow mounting a dirdata
filesystem without EXT4_FEATURE_INCOMPAT_FILETYPE?
Dirdata stores its presence flags in the upper 4 bits of de->file_type,
which is the high byte of a 16-bit name_len when FILETYPE is disabled, yet
ext4_feature_set_ok() does not reject that combination. As a result,
ext4_dirdata_set() (added later in the series) unconditionally sets dirdata
bits in de->file_type while ext4_setent() gates file_type and LUFID updates
on ext4_has_feature_filetype(), skipping LUFID updates on overwriting
renames and leaving the overwritten inode's LUFID attached to the renamed
entry.
[Severity: Medium]
Can mounting EXT4_FEATURE_INCOMPAT_DIRDATA without
EXT4_FEATURE_INCOMPAT_FILETYPE also cause newly allocated directory blocks
to fail validation as corrupted?
Because ext4_feature_set_ok() permits this combination and
ext4_set_de_type() is a no-op without FILETYPE, ext4_init_dirblock() leaves
stale bytes in de->file_type for '.' and '..' when ext4_append() reuses an
already-uptodate buffer. ext4_dirent_data_corrupt() then interprets
non-zero upper bits in those stale bytes as dirdata flags and reports
corruption. Rejecting dirdata without filetype in ext4_feature_set_ok()
would prevent both issues.
[ ... ]
> @@ -4509,6 +4538,28 @@ static inline int ext4_dirent_get_data_len(struct ext4_dir_entry_2 *de,
> return dlen;
> }
>
> +/*
> + * ext4_dirent_data_corrupt() - check the dirdata records of an entry
> + * @sb: super block
> + * @de: directory entry
> + * @rec_len: the record length of the directory entry (decoded)
> + *
> + * On a dirdata filesystem every record flagged in the high bits of
> + * de->file_type must fit inside the entry. ext4_dirent_get_data_len()
> + * returns 0 when one does not, which would make the length of the entry
> + * depend on its current rec_len; callers treat that as corruption
> + * instead. Without the feature the flags are not interpreted.
> + */
> +static inline bool ext4_dirent_data_corrupt(struct super_block *sb,
> + struct ext4_dir_entry_2 *de,
> + unsigned int rec_len)
> +{
> + if (!ext4_has_feature_dirdata(sb) || ext4_dir_entry_is_tail(de) ||
> + !(de->file_type & ~EXT4_FT_MASK))
> + return false;
> + return ext4_dirent_get_data_len(de, rec_len) == 0;
> +}
[Severity: Medium]
Does ext4_dir_entry_len() still interpret dirdata flags when
EXT4_FEATURE_INCOMPAT_DIRDATA is disabled, contradicting
ext4_dirent_data_corrupt()?
fs/ext4/ext4.h:ext4_dir_entry_len() {
unsigned int rec_len = ext4_rec_len_from_disk(de->rec_len, blocksize);
unsigned int dirdata = ext4_dirent_get_data_len(de, rec_len);
return max(ext4_dirent_rec_len(de->name_len + dirdata, NULL),
ext4_dirent_rec_len(de->name_len, dir));
}
On a non-dirdata filesystem, if a 1-block directory has a '..' entry with
rec_len == 12, a non-zero upper nibble in file_type, and a non-zero padding
byte (for example 4), make_indexed_dir() passes validation because
ext4_dirent_get_data_len(dotdot_de, 12) returns 0, writes dx_root_info at
offset 24, and expands dotdot_de->rec_len to blocksize - 12. Subsequent
calls to get_dx_countlimit() and dx_get_dx_info() then see the expanded
rec_len, compute a larger dotdot_rec_len (16), and read dx_root_info at
offset 28 instead of 24, failing checksum generation and breaking the
directory with ERR_BAD_DX_DIR. Gating ext4_dirent_get_data_len() in
ext4_dir_entry_len() on ext4_has_feature_dirdata() would avoid this.
[ ... ]
> diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
> index 6050dbfd9f786..12ffd34cf46d0 100644
> --- a/fs/ext4/namei.c
> +++ b/fs/ext4/namei.c
> @@ -329,23 +329,33 @@ static struct dx_countlimit *get_dx_countlimit(struct inode *inode,
> {
> struct ext4_dir_entry_2 *de;
> struct dx_root_info *root;
> - int count_offset;
> + int count_offset, dotdot_rec_len;
> int blocksize = EXT4_BLOCK_SIZE(inode->i_sb);
> unsigned int rlen = ext4_rec_len_from_disk(dirent->rec_len, blocksize);
>
> - if (rlen == blocksize)
> + if (rlen == blocksize) {
> count_offset = sizeof(struct dx_node);
> - else if (rlen == 12) {
> - de = (struct ext4_dir_entry_2 *)(((void *)dirent) + 12);
> - if (ext4_rec_len_from_disk(de->rec_len, blocksize) != blocksize - 12)
> + } else {
> + if (rlen < EXT4_BASE_DIR_LEN ||
> + rlen + EXT4_BASE_DIR_LEN > blocksize)
> + return NULL;
> + de = (struct ext4_dir_entry_2 *)(((char *)dirent) + rlen);
> + if (ext4_rec_len_from_disk(de->rec_len, blocksize) !=
> + (unsigned int)(blocksize - rlen))
> + return NULL;
> + /* de->rec_len covers whole dx_root block, calculate actual length.
> + * This is the '..' entry, which never carries the casefold+fscrypt
> + * hash, so pass NULL for dir regardless of the directory's flags */
> + dotdot_rec_len = ext4_dir_entry_len(de, blocksize, NULL);
> + if (rlen + dotdot_rec_len + sizeof(struct dx_root_info) +
> + sizeof(struct dx_countlimit) > blocksize)
> return NULL;
> - root = (struct dx_root_info *)(((void *)de + 12));
> + root = (struct dx_root_info *)(((char *)de + dotdot_rec_len));
> if (root->reserved_zero ||
> root->info_length != sizeof(struct dx_root_info))
> return NULL;
> - count_offset = 32;
> - } else
> - return NULL;
> + count_offset = root->info_length + rlen + dotdot_rec_len;
> + }
>
> if (offset)
> *offset = count_offset;
[Severity: Medium]
Can an unaligned dot rec_len in get_dx_countlimit() cause unaligned
accesses to dx_root_info, dx_countlimit, dx_entry, and dx_tail?
Previously get_dx_countlimit() only accepted rlen == blocksize or
rlen == 12, guaranteeing 4-byte alignment. Now a corrupted root block with
an unaligned rlen (such as 9) passes and produces unaligned pointers (and
dx_get_dx_info() is missing the same (rlen & EXT4_DIR_ROUND) check).
Unlike dx_get_dx_info(), get_dx_countlimit() also omits
ext4_dirent_data_corrupt() on '.' and '..' and the
ext4_dir_entry_len(dirent, blocksize, NULL) > rlen check, so corrupt
dirdata causes ext4_dirent_get_data_len() to return 0 and silently compute
the wrong count_offset instead of returning NULL.
[ ... ]
> @@ -586,7 +598,9 @@ static struct stats dx_show_leaf(struct inode *dir,
> (unsigned) ((char *) de - base));
> #endif
> }
> - space += ext4_dirent_rec_len(de->name_len, dir);
> + if ((char *)de + EXT4_BASE_DIR_LEN > base + size)
> + break;
> + space += ext4_dir_entry_len(de, size, dir);
> names++;
> }
> de = ext4_next_entry(de, size);
[Severity: Low]
Is this bounds check in dx_show_leaf() too late and incomplete for a
corrupted leaf block?
In DX_DEBUG builds, the loop already dereferences de->inode (and, when
show_names is set, de->name_len, de->name, and EXT4_DIRENT_HASH(de)) before
reaching this check. When de->inode == 0, the check is bypassed before
ext4_next_entry(de, size) reads de->rec_len, and ext4_dir_entry_len() is
also called without verifying (char *)de + rec_len <= base + size, allowing
an out-of-bounds read past the leaf buffer.
[ ... ]
> @@ -2930,8 +2961,9 @@ int ext4_init_dirblock(handle_t *handle, struct inode *inode,
> }
> EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_init_dirblock);
>
> -int ext4_init_new_dir(handle_t *handle, struct inode *dir,
> - struct inode *inode)
> +int ext4_init_new_dir_data(handle_t *handle, struct inode *dir,
> + struct inode *inode,
> + const void *data1, const void *data2)
> {
> struct buffer_head *dir_block = NULL;
> ext4_lblk_t block = 0;
[Severity: Low]
Are data1 and data2 in ext4_init_new_dir_data() unused? Neither parameter
is referenced in the function body, and even at the end of the series the
function still ignores them with no direct in-tree callers (only the
ext4_init_new_dir() wrapper passing NULL, NULL); similarly, __ext4_link()
forwards dentry->d_fsdata even though no in-tree link caller sets it.
[ ... ]
> diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c
> index faa76f0210991..a433418a8182b 100644
> --- a/fs/ext4/sysfs.c
> +++ b/fs/ext4/sysfs.c
> @@ -362,6 +362,7 @@ EXT4_ATTR_FEATURE(verity);
> #endif
> EXT4_ATTR_FEATURE(metadata_csum_seed);
> EXT4_ATTR_FEATURE(fast_commit);
> +EXT4_ATTR_FEATURE(dirdata);
> #if IS_ENABLED(CONFIG_UNICODE) && defined(CONFIG_FS_ENCRYPTION)
> EXT4_ATTR_FEATURE(encrypted_casefold);
> #endif
[Severity: Medium]
Does advertising dirdata in sysfs and adding EXT4_FEATURE_INCOMPAT_DIRDATA
to EXT4_FEATURE_INCOMPAT_SUPP in this commit allow read-write mounts of
dirdata filesystems before the dirdata read, write, and rename handlers
exist?
At this commit, ext4_insert_dentry_data() ignores its data parameter and
writes casefold+fscrypt hashes at the legacy fixed offset, hash readers
such as ext4_match() and ext4_readdir() still read the legacy offset, and
ext4_setent() copies de->file_type verbatim on rename without adjusting
dirdata payloads, corrupting entries on disk because
__ext4_check_dir_entry() already enforces ext4_dirent_data_corrupt().
These handlers are added later by commit "ext4: add dirdata LUFID support
for directory entry rename" and commit "ext4: add dirdata set/get helpers",
so deferring EXT4_FEATURE_INCOMPAT_SUPP and sysfs enablement until after
those patches would keep the series bisectable.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203184938.422849-1-ablagodarenko@thelustrecollective.com?part=9
next prev parent reply other threads:[~2026-12-03 21:37 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 [this message]
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
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-248702@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.