mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 v6] hfsplus: validate B-tree record offset table
Date: Sun, 09 Aug 2026 17:22:03 -0700	[thread overview]
Message-ID: <0720c3ba6399c11a0a328e8d8eef99a19e6999c8.camel@dubeyko.com> (raw)
In-Reply-To: <CANypQFZ-kejru9P3D7rvCzDp5hP-xqM9okq7LpiHEobbU=oQpw@mail.gmail.com>

On Sat, 2026-08-08 at 22:50 +0800, Jiaming Zhang wrote:
> > 

<skipped>

> > I've realized that we have additional issue in HFS+ logic.
> > Potentially,
> > keylen and len could be not invalid but we could have negative
> > value
> > later in the logic:
> > 
> > done:
> >         fd->record = e;
> >         fd->keyoffset = off;
> >         fd->keylength = keylen;
> >         fd->entryoffset = off + keylen;
> >         fd->entrylength = len - keylen; <-- negative value here.
> > 
> > The negative value of fd->entrylength is checked in multiple
> > places.
> > However, there is extents tree logic that has no such check [1]:
> > 
> > static int __hfsplus_ext_write_extent(struct inode *inode,
> >                 struct hfs_find_data *fd)
> > {
> > <skipped>
> > 
> >         } else {
> >                 if (res)
> >                         return res;
> >                 hfs_bnode_write(fd->bnode, hip->cached_extents,
> >                                 fd->entryoffset, fd->entrylength);
> >                 hip->extent_state &= ~HFSPLUS_EXT_DIRTY;
> >         }
> > 
> > <skipped>
> > }
> > 
> > Could you please double check my conclusion? We can fix the issue
> > in
> > another patch. Could you please fix the issue?
> > 
> 
> I agree with your conclusion. A crafted image can keep both len and
> keylen valid but make fd->entrylength negative (i.e. keylen > len),
> which may lead to out-of-bound read and kernel memory leaking.
> 
> To fix this issue, we can check validity of fd->entrylength in
> __hfsplus_ext_write_extent() like the check in
> __hfsplus_ext_read_extent(). For example:
> 
> 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;
> 
> Do you think this fix is acceptable? If so, I'm happy to send another
> patch.
> 

As far as I can see, the fix makes sense.

Thanks,
Slava.

  reply	other threads:[~2026-08-10  0:22 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 [this message]
2026-08-10  9:24                                   ` [PATCH] hfsplus: validate extent record length before writing it back Jiaming Zhang
2026-08-11  0:02                                     ` Viacheslav Dubeyko

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=0720c3ba6399c11a0a328e8d8eef99a19e6999c8.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®