From: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>
To: "kartikey406@gmail.com" <kartikey406@gmail.com>
Cc: "glaubitz@physik.fu-berlin.de" <glaubitz@physik.fu-berlin.de>,
"frank.li@vivo.com" <frank.li@vivo.com>,
"slava@dubeyko.com" <slava@dubeyko.com>,
"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"syzbot+d80abb5b890d39261e72@syzkaller.appspotmail.com"
<syzbot+d80abb5b890d39261e72@syzkaller.appspotmail.com>
Subject: RE: [PATCH] hfsplus: fix uninit-value in hfsplus_strcasecmp
Date: Tue, 27 Jan 2026 23:21:24 +0000 [thread overview]
Message-ID: <eac09a9664142abbc801197041d34fef44b05435.camel@ibm.com> (raw)
In-Reply-To: <CADhLXY54yiFoqGghDQ9=p7PQXSo7caJ17pBrGS3Ck3uuRDOB5A@mail.gmail.com>
On Tue, 2026-01-27 at 13:50 +0530, Deepanshu Kartikey wrote:
> On Tue, Jan 27, 2026 at 2:07 AM Viacheslav Dubeyko
> <Slava.Dubeyko@ibm.com> wrote:
> >
>
>
> >
> > It looks like we can simply combined to check into one:
> >
> > if (fd->entrylength != rec_len)
> >
> > However, I am not completely sure that it's completely correct fix. Because, for
> > example, hfs_cat_find_brec() tries to read hfs_cat_rec union:
> >
> > hfs_cat_build_key(sb, fd->search_key, cnid, NULL);
> > res = hfs_brec_read(fd, &rec, sizeof(rec));
> > if (res)
> > return res;
> >
> > It means that we provide the bigger length that it is required for struct
> > hfs_cat_file or struct hfs_cat_dir. It sounds to me that the reading of these
> > records will be rejected. Am I wrong here?
> >
>
> Hi Slava,
>
> Thank you for the feedback! You're absolutely right - using != would break
> callers that read unions with different-sized members.
>
> Instead of validating in hfs_brec_read() (which is generic), I should validate
> specifically in hfsplus_find_cat() where we know we're reading a thread record.
>
First of all, we have several places where we call hfs_brec_read() [1-3]. And
all these places deserve correct logic. So, I am afraid, we need the generic
solution.
> Here's the corrected approach:
>
> ---
>
> int hfsplus_find_cat(struct super_block *sb, u32 cnid,
> struct hfs_find_data *fd)
> {
> hfsplus_cat_entry tmp = {0};
> int err;
> u16 type;
> u32 min_size;
>
> hfsplus_cat_build_key_with_cnid(sb, fd->search_key, cnid);
> err = hfs_brec_read(fd, &tmp, sizeof(hfsplus_cat_entry));
> if (err)
> return err;
>
> type = be16_to_cpu(tmp.type);
> if (type != HFSPLUS_FOLDER_THREAD && type != HFSPLUS_FILE_THREAD) {
> pr_err("found bad thread record in catalog\n");
> return -EIO;
> }
>
> ++ /* Validate we read a complete thread record */
> ++ min_size = offsetof(hfsplus_cat_entry, thread.nodeName) +
> ++ offsetof(struct hfsplus_unistr, unicode) +
> ++ be16_to_cpu(tmp.thread.nodeName.length) * 2;
Frankly speaking, I don't quite follow your logic of the check here. Complicated
logic introduces new bugs always. :)
> ++ if (fd->entrylength < min_size) {
> ++ pr_err("incomplete thread record read (got %u, need %u)\n",
> ++ fd->entrylength, min_size);
> ++ return -EIO;
> ++ }
>
> if (be16_to_cpu(tmp.thread.nodeName.length) > 255) {
> pr_err("catalog name length corrupted\n");
> return -EIO;
> }
>
> hfsplus_cat_build_key_uni(fd->search_key,
> be32_to_cpu(tmp.thread.parentID),
> &tmp.thread.nodeName);
> return hfs_brec_find(fd, hfs_find_rec_by_key);
> }
>
> ---
>
> This way:
> 1. hfs_brec_read() remains generic (doesn't break other callers)
> 2. We validate specifically for thread records where we know the
> expected structure
> 3. We calculate minimum required size based on the string length the
> record claims
> 4. We initialize tmp = {0} as defensive programming
>
> Does this look correct?
>
>
As far as I can see, hfs_brec_read() mostly used for operations with Catalog
File. And we always read hfsplus_cat_entry union. And you can see that it starts
from type field.
typedef union {
__be16 type;
struct hfsplus_cat_folder folder;
struct hfsplus_cat_file file;
struct hfsplus_cat_thread thread;
} __packed hfsplus_cat_entry;
So, you can use this field to make a decision which type of record is under
check. So, I think we need to implement generic logic, anyway.
Thanks,
Slava.
[1] https://elixir.bootlin.com/linux/v6.19-rc5/source/fs/hfsplus/super.c#L570
[2] https://elixir.bootlin.com/linux/v6.19-rc5/source/fs/hfsplus/dir.c#L52
[3] https://elixir.bootlin.com/linux/v6.19-rc5/source/fs/hfsplus/catalog.c#L202
next prev parent reply other threads:[~2026-01-27 23:21 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-20 5:11 Deepanshu Kartikey
2026-01-20 22:29 ` Viacheslav Dubeyko
2026-01-21 6:26 ` Deepanshu Kartikey
2026-01-21 20:11 ` Viacheslav Dubeyko
2026-01-23 1:48 ` Deepanshu Kartikey
2026-01-23 23:21 ` Viacheslav Dubeyko
2026-01-24 2:46 ` Deepanshu Kartikey
2026-01-26 20:37 ` Viacheslav Dubeyko
2026-01-27 8:20 ` Deepanshu Kartikey
2026-01-27 23:21 ` Viacheslav Dubeyko [this message]
2026-01-28 4:29 ` Deepanshu Kartikey
2026-01-29 20:56 ` 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=eac09a9664142abbc801197041d34fef44b05435.camel@ibm.com \
--to=slava.dubeyko@ibm.com \
--cc=frank.li@vivo.com \
--cc=glaubitz@physik.fu-berlin.de \
--cc=kartikey406@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=slava@dubeyko.com \
--cc=syzbot+d80abb5b890d39261e72@syzkaller.appspotmail.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®