From: Viacheslav Dubeyko <slava@dubeyko.com>
To: Jiaming Zhang <r772577952@gmail.com>
Cc: frank.li@vivo.com, glaubitz@physik.fu-berlin.de,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
syzkaller@googlegroups.com, vdubeyko@coreweave.com
Subject: Re: [PATCH] hfsplus: validate extent record length before writing it back
Date: Mon, 10 Aug 2026 17:02:43 -0700 [thread overview]
Message-ID: <5f60c60a03b3d3e4b6d4adc2f241371b72977206.camel@dubeyko.com> (raw)
In-Reply-To: <20260810092422.1691377-1-r772577952@gmail.com>
On Mon, 2026-08-10 at 17:24 +0800, Jiaming Zhang wrote:
> __hfsplus_ext_write_extent() writes the cached extent record back
> into a
> B-tree node using fd->entrylength as the length, and fd->entrylength
> is
> derived in __hfs_brec_find() from two on-disk values:
>
> fd->entrylength = len - keylen;
>
> A crafted image can keep both len and keylen valid but make fd-
> >entrylength
> negative (keylen > len). __hfsplus_ext_write_extent() doesn't check
> fd->entrylength before consuming it, and hfs_bnode_write() takes the
> length
> as u32, so the negative value turns into a huge one. The copy then
> reads
> data past the end of hip->cached_extents, which is only
> sizeof(hfsplus_extent_rec) bytes long, and leaks kernel memory into
> the
> image.
>
> Reject an fd->entrylength that does not match
> sizeof(hfsplus_extent_rec) in
> __hfsplus_ext_write_extent(), mirroring the check already performed
> in
> __hfsplus_ext_read_extent().
>
> Link:
> https://lore.kernel.org/lkml/cbd7003314c530d4f910eacf019ff80adad6687e.camel@dubeyko.com/
> Signed-off-by: Jiaming Zhang <r772577952@gmail.com>
> ---
> fs/hfsplus/extents.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/fs/hfsplus/extents.c b/fs/hfsplus/extents.c
> index 813e68b8ecd6..eb7c11524d18 100644
> --- a/fs/hfsplus/extents.c
> +++ b/fs/hfsplus/extents.c
> @@ -110,6 +110,8 @@ static int __hfsplus_ext_write_extent(struct
> inode *inode,
> } else {
> if (res)
> return res;
> + if (fd->entrylength != sizeof(hfsplus_extent_rec))
> + return -EIO;
> hfs_bnode_write(fd->bnode, hip->cached_extents,
> fd->entryoffset, fd->entrylength);
> hip->extent_state &= ~HFSPLUS_EXT_DIRTY;
Looks good.
Reviewed-by: Viacheslav Dubeyko <slava@dubeyko.com>
Thanks,
Slava.
prev parent reply other threads:[~2026-08-11 0:02 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-25 8:53 [Linux Kernel Bug] INFO: task hung in hfsplus_write_inode Jiaming Zhang
2026-06-25 13:06 ` Matthew Wilcox
2026-06-30 14:06 ` Viacheslav Dubeyko
2026-07-01 5:50 ` [PATCH] hfsplus: validate B-tree record offset table Jiaming Zhang
2026-07-01 20:24 ` Viacheslav Dubeyko
2026-07-02 8:22 ` [PATCH v2 0/1] " Jiaming Zhang
2026-07-02 8:22 ` [PATCH v2 1/1] " Jiaming Zhang
2026-07-08 21:52 ` Viacheslav Dubeyko
2026-07-12 6:09 ` [PATCH v3] " Jiaming Zhang
2026-07-14 19:59 ` Viacheslav Dubeyko
2026-07-23 6:39 ` [PATCH v4] " Jiaming Zhang
2026-07-24 19:19 ` Viacheslav Dubeyko
2026-07-28 10:12 ` [PATCH v5] " Jiaming Zhang
2026-07-29 0:36 ` Viacheslav Dubeyko
2026-07-29 19:01 ` Viacheslav Dubeyko
2026-08-06 7:33 ` [PATCH v6] " Jiaming Zhang
2026-08-08 0:49 ` Viacheslav Dubeyko
2026-08-08 14:50 ` Jiaming Zhang
2026-08-10 0:22 ` Viacheslav Dubeyko
2026-08-10 9:24 ` [PATCH] hfsplus: validate extent record length before writing it back Jiaming Zhang
2026-08-11 0:02 ` Viacheslav Dubeyko [this message]
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=5f60c60a03b3d3e4b6d4adc2f241371b72977206.camel@dubeyko.com \
--to=slava@dubeyko.com \
--cc=frank.li@vivo.com \
--cc=glaubitz@physik.fu-berlin.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=r772577952@gmail.com \
--cc=syzkaller@googlegroups.com \
--cc=vdubeyko@coreweave.com \
/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®