From: Viacheslav Dubeyko <slava@dubeyko.com>
To: Davy Felipe <davyfelipe34@gmail.com>
Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>,
Yangtao Li <frank.li@vivo.com>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5] hfs: handle extent B-tree write errors
Date: Fri, 25 Sep 2026 11:52:58 -0700 [thread overview]
Message-ID: <3a15e99669fa36e3456e59920061be03bd7a06b2.camel@dubeyko.com> (raw)
In-Reply-To: <20260924231054.2175660-1-davyfelipe34@gmail.com>
On Thu, 2026-09-24 at 20:10 -0300, Davy Felipe wrote:
> hfs_brec_insert() may fail while inserting a new extent record, but
> __hfs_ext_write_extent() currently ignores its return value and
> clears
> HFS_FLG_EXT_DIRTY and HFS_FLG_EXT_NEW as if the insertion had
> succeeded.
>
> Propagate errors returned by hfs_brec_insert() and only clear the
> extent flags after a successful insertion.
>
> When updating an existing extent record, hfs_bnode_write() returns
> void. Validate the extent write parameters before calling it so an
> invalid update is reported as -EIO instead of being treated as
> successful.
>
> Use a reusable B-tree node range helper that takes the find data and
> the expected record size. The helper validates the bnode and tree
> pointers, entry offset and entry length, and ensures that the write
> range fits within the node.
>
> Negative-path testing in QEMU confirmed that an insertion error is
> propagated to the caller. Testing the existing-record path also
> confirmed that invalid write parameters are rejected before
> HFS_FLG_EXT_DIRTY is cleared.
>
> Signed-off-by: Davy Felipe <davyfelipe34@gmail.com>
___
> Thanks for the feedback. I updated the helper to take struct
> hfs_find_data and the expected entry size so the bnode/tree,
> entry offset and entry length validation stay in one place.
>
> Changes in v5:
> - Pass struct hfs_find_data to hfs_bnode_is_valid_range().
> - Validate the bnode and tree pointers in the helper.
> - Pass the expected entry size and validate fd->entrylength there.
> - Simplify the extent write path to a single validation helper call.
>
> ---
> fs/hfs/btree.h | 19 +++++++++++++++++++
> fs/hfs/extent.c | 10 ++++++++--
> 2 files changed, 27 insertions(+), 2 deletions(-)
>
> diff --git a/fs/hfs/btree.h b/fs/hfs/btree.h
> index b4c3f2a31471..ab7a7c65a126 100644
> --- a/fs/hfs/btree.h
> +++ b/fs/hfs/btree.h
> @@ -84,6 +84,25 @@ struct hfs_find_data {
> int entryoffset, entrylength;
> };
Mostly, I like the patch. But I have some cosmetic remarks for
discussion because I don't want to change the patch without your
consent.
>
> +static inline bool hfs_bnode_is_valid_range(struct hfs_find_data
Current name sounds slightly not natural. :) We can consider
is_hfs_bnode_range_valid(). What do you think? Maybe you have something
better in mind?
> *fd, int expected_len)
Do we really need to use integer for expected_len? Why not size_t? Any
particular reason?
> +{
> + struct hfs_bnode *node;
> +
> + if (!fd)
> + return false;
> +
> + node = fd->bnode;
> + if (!node || !node->tree)
> + return false;
> +
> + if (expected_len <= 0 || fd->entryoffset < 0 ||
If we have size_t, then we don't need to check that expected_len < 0.
> + fd->entrylength != expected_len)
Do we need to check that expected_len == 0? Should fd->entrylength !=
expected_len be enough?
> + return false;
> +
> + return (u64)fd->entryoffset + fd->entrylength <=
> + node->tree->node_size;
> +}
> +
>
> /* btree.c */
> extern struct hfs_btree *hfs_btree_open(struct super_block *sb, u32
> id,
> diff --git a/fs/hfs/extent.c b/fs/hfs/extent.c
> index f066a99a863b..4d65943d1117 100644
> --- a/fs/hfs/extent.c
> +++ b/fs/hfs/extent.c
> @@ -121,12 +121,18 @@ static int __hfs_ext_write_extent(struct inode
> *inode, struct hfs_find_data *fd)
> res = hfs_bmap_reserve(fd->tree, fd->tree->depth +
> 1);
> if (res)
> return res;
> - hfs_brec_insert(fd, HFS_I(inode)->cached_extents,
> sizeof(hfs_extent_rec));
> + res = hfs_brec_insert(fd, HFS_I(inode)-
> >cached_extents,
> + sizeof(hfs_extent_rec));
> + if (res)
> + return res;
> HFS_I(inode)->flags &=
> ~(HFS_FLG_EXT_DIRTY|HFS_FLG_EXT_NEW);
> } else {
> if (res)
> return res;
> - hfs_bnode_write(fd->bnode, HFS_I(inode)-
> >cached_extents, fd->entryoffset, fd->entrylength);
> + if (!hfs_bnode_is_valid_range(fd,
> sizeof(hfs_extent_rec)))
> + return -EIO;
I am started to guess. Is -EIO correct error code here? It is still
operation in memory and we are checking the correctness of struct
hfs_find_data content. Maybe, we need to consider another error code
here? What's about -ERANGE? What is your preference?
Thanks,
Slava.
> + hfs_bnode_write(fd->bnode, HFS_I(inode)-
> >cached_extents,
> + fd->entryoffset, fd->entrylength);
> HFS_I(inode)->flags &= ~HFS_FLG_EXT_DIRTY;
> }
> return 0;
next prev parent reply other threads:[~2026-09-25 18:53 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-20 16:02 [PATCH] hfs: propagate extent B-tree insertion errors Davy Felipe
2026-09-21 21:19 ` Viacheslav Dubeyko
2026-09-23 23:08 ` [PATCH v3] hfs: handle extent B-tree write errors Davy Felipe
2026-09-22 23:40 ` [PATCH v2] " Davy Felipe
2026-09-23 19:37 ` Viacheslav Dubeyko
2026-09-23 22:14 ` Davy Felipe
2026-09-24 0:16 ` [PATCH v4] " Davy Felipe
2026-09-24 19:23 ` Viacheslav Dubeyko
2026-09-24 20:53 ` Davy Felipe
2026-09-24 23:10 ` [PATCH v5] " Davy Felipe
2026-09-25 18:52 ` Viacheslav Dubeyko [this message]
2026-09-26 1:09 ` [PATCH v4] " Davy Felipe
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=3a15e99669fa36e3456e59920061be03bd7a06b2.camel@dubeyko.com \
--to=slava@dubeyko.com \
--cc=davyfelipe34@gmail.com \
--cc=frank.li@vivo.com \
--cc=glaubitz@physik.fu-berlin.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®