linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>
To: "glaubitz@physik.fu-berlin.de" <glaubitz@physik.fu-berlin.de>,
	"frank.li@vivo.com" <frank.li@vivo.com>,
	"slava@dubeyko.com" <slava@dubeyko.com>,
	"ssrane_b23@ee.vjti.ac.in" <ssrane_b23@ee.vjti.ac.in>
Cc: "khalid@kernel.org" <khalid@kernel.org>,
	"linux-kernel-mentees@lists.linux.dev"
	<linux-kernel-mentees@lists.linux.dev>,
	"syzbot+905d785c4923bea2c1db@syzkaller.appspotmail.com"
	<syzbot+905d785c4923bea2c1db@syzkaller.appspotmail.com>,
	"david.hunter.linux@gmail.com" <david.hunter.linux@gmail.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"skhan@linuxfoundation.org" <skhan@linuxfoundation.org>,
	"willy@infradead.org" <willy@infradead.org>,
	"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>
Subject: Re:  [PATCH v2] hfsplus: fix uninit-value in hfsplus_cat_build_record
Date: Thu, 20 Nov 2025 19:33:08 +0000	[thread overview]
Message-ID: <c53674bcc3ff1e9a6244d6a453653c86aeee1902.camel@ibm.com> (raw)
In-Reply-To: <20251120184610.28563-1-ssranevjti@gmail.com>

On Fri, 2025-11-21 at 00:16 +0530, ssrane_b23@ee.vjti.ac.in wrote:
> From: Shaurya Rane <ssrane_b23@ee.vjti.ac.in>
> 
> The root cause is in hfsplus_cat_build_record(), which builds catalog

Commit message sounds slightly confusing. The root cause of what?

> entries using the union hfsplus_cat_entry. This union contains three
> members with significantly different sizes:
> 
>   struct hfsplus_cat_folder folder;    (88 bytes)
>   struct hfsplus_cat_file file;        (248 bytes)
>   struct hfsplus_cat_thread thread;    (520 bytes)
> 
> The function was only zeroing the specific member being used (folder or
> file), not the entire union. This left significant uninitialized data:
> 
>   For folders: 520 - 88  = 432 bytes uninitialized
>   For files:   520 - 248 = 272 bytes uninitialized
> 
> This uninitialized data was then written to disk via hfs_brec_insert(),

I like the zeroing of whole union. But hfs_brec_insert() operates by key_len and
entry_len:

hfs_bnode_write(node, fd->search_key, data_off, key_len);
hfs_bnode_write(node, entry, data_off + key_len, entry_len);

This values should prevent from writing something out of size folder, file or
thread record. Even if we are zeroing the entire union, then we could write
something that not fit to the size of folder, file or thread record. It sounds
to me that we will corrupt the record anyway because it sounds that key_len and
entry_len are incorrect. And if they are incorrect, then we have much bigger
issue here.

So, I am not completely sure that it is complete fix of the issue. Could you
please justify that my point is incorrect here?

It will be good to be sure that FSCK tool is happy. However, if volume is
corrupted intentionally, then it's hard to use the FSCK tool.

Thanks,
Slava.

> read back through the loop device, and eventually copied to userspace
> via filemap_read(), resulting in a leak of kernel stack memory.
> Fix this by zeroing the entire union before initializing the specific
> member. This ensures no uninitialized bytes remain.
> 
> Reported-by: syzbot+905d785c4923bea2c1db@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=905d785c4923bea2c1db  
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Signed-off-by: Shaurya Rane <ssrane_b23@ee.vjti.ac.in>
> ---
> Changes in v2:
> - Corrected format of Fixes tag 
> - Removed extra blank line before Signed-off-by
>  fs/hfsplus/catalog.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/hfsplus/catalog.c b/fs/hfsplus/catalog.c
> index 02c1eee4a4b8..4d42e7139f3b 100644
> --- a/fs/hfsplus/catalog.c
> +++ b/fs/hfsplus/catalog.c
> @@ -111,7 +111,8 @@ static int hfsplus_cat_build_record(hfsplus_cat_entry *entry,
>  		struct hfsplus_cat_folder *folder;
>  
>  		folder = &entry->folder;
> -		memset(folder, 0, sizeof(*folder));
> +		/* Zero the entire union to avoid leaking uninitialized data */
> +		memset(entry, 0, sizeof(*entry));
>  		folder->type = cpu_to_be16(HFSPLUS_FOLDER);
>  		if (test_bit(HFSPLUS_SB_HFSX, &sbi->flags))
>  			folder->flags |= cpu_to_be16(HFSPLUS_HAS_FOLDER_COUNT);
> @@ -130,7 +131,8 @@ static int hfsplus_cat_build_record(hfsplus_cat_entry *entry,
>  		struct hfsplus_cat_file *file;
>  
>  		file = &entry->file;
> -		memset(file, 0, sizeof(*file));
> +		/* Zero the entire union to avoid leaking uninitialized data */
> +		memset(entry, 0, sizeof(*entry));
>  		file->type = cpu_to_be16(HFSPLUS_FILE);
>  		file->flags = cpu_to_be16(HFSPLUS_FILE_THREAD_EXISTS);
>  		file->id = cpu_to_be32(cnid);

      reply	other threads:[~2025-11-20 19:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-20 18:46 [PATCH v2] hfsplus: fix uninit-value in hfsplus_cat_build_record ssrane_b23
2025-11-20 19:33 ` 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=c53674bcc3ff1e9a6244d6a453653c86aeee1902.camel@ibm.com \
    --to=slava.dubeyko@ibm.com \
    --cc=david.hunter.linux@gmail.com \
    --cc=frank.li@vivo.com \
    --cc=glaubitz@physik.fu-berlin.de \
    --cc=khalid@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel-mentees@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=slava@dubeyko.com \
    --cc=ssrane_b23@ee.vjti.ac.in \
    --cc=syzbot+905d785c4923bea2c1db@syzkaller.appspotmail.com \
    --cc=willy@infradead.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;
as well as URLs for NNTP newsgroup(s).