Linux filesystem development
 help / color / mirror / Atom feed
From: Viacheslav Dubeyko <vdubeyko@redhat.com>
To: Tristan Madani <tristmd@gmail.com>
Cc: slava@dubeyko.com, linux-fsdevel@vger.kernel.org,
	 linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] hfs/hfsplus: zero-initialize buffer in hfs_bnode_read
Date: Thu, 07 May 2026 14:59:16 -0700	[thread overview]
Message-ID: <170c26138376d15553437c2edd57ba74d4267855.camel@redhat.com> (raw)
In-Reply-To: <177817187847.3894093.14769331709936824605@gmail.com>

On Thu, 2026-05-07 at 16:37 +0000, Tristan Madani wrote:
> On Wed, 2026-05-06 at 12:23 -0700, Viacheslav Dubeyko wrote:
> > We are returning back to the same my question. What if the caller of
> > hfs_bnode_read() provides the len == 0 somehow but the buffer has not zero size
> > on the caller side? I assume that memset() will do nothing and the buffer still
> > be not initialized. Am I correct here?
> 
> You are correct that memset(buf, 0, 0) is a no-op. But if the caller
> passes len == 0, it is asking to read zero bytes -- it should not
> expect the function to initialize anything beyond that.
> 
> The bug this fixes is different: callers pass a non-zero len (e.g.
> hfs_bnode_read_u16 passes 2, hfs_bnode_read_u8 passes 1), but
> check_and_correct_requested_length() internally reduces the effective
> read to 0 due to a corrupted image. The memset runs with the original
> caller-supplied len before any internal validation, so the buffer is
> already zeroed by the time the early-return happens.
> 
> No current caller passes len == 0 -- hfs_bnode_read_u16() always
> passes 2, hfs_bnode_read_u8() always passes 1, and hfs_bnode_read_key()
> passes a key_len that is validated against the btree key size.
> 

OK. I think I can agree with you. If we have len == 0 as input argument, then we
have:

if (len == 0) {
<skipped>
   return;
}

And if check_and_correct_requested_length() corrects the len to 0:

len = check_and_correct_requested_length(node, off, len);

then loop will do nothing because of len == 0:

for (bytes_read = 0; bytes_read < len; bytes_read += bytes_to_read) {
<skipped>
}

Thanks,
Slava.


  reply	other threads:[~2026-05-07 21:59 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-01 11:02 [PATCH 1/3] hfs/hfsplus: fix u32 overflow in check_and_correct_requested_length Tristan Madani
2026-05-01 11:02 ` [PATCH 2/3] hfs/hfsplus: initialize data buffer in hfs_bnode_read_u16 and hfs_bnode_read_u8 Tristan Madani
2026-05-04 23:29   ` Viacheslav Dubeyko
2026-05-01 11:02 ` [PATCH 3/3] hfsplus: fix null pointer dereference in hfsplus_create_attributes_file Tristan Madani
2026-05-04 23:31   ` Viacheslav Dubeyko
2026-05-04 23:27 ` [PATCH 1/3] hfs/hfsplus: fix u32 overflow in check_and_correct_requested_length Viacheslav Dubeyko
2026-05-05 11:12 ` [PATCH v2 0/2] hfs/hfsplus: fix OOB access and uninit-value in bnode operations Tristan Madani
2026-05-05 11:12   ` [PATCH v2 1/2] hfs/hfsplus: fix u32 overflow in check_and_correct_requested_length Tristan Madani
2026-05-07 22:02     ` Viacheslav Dubeyko
2026-05-05 11:12   ` [PATCH v2 2/2] hfs/hfsplus: zero-initialize buffer in hfs_bnode_read Tristan Madani
2026-05-06 19:23     ` Viacheslav Dubeyko
2026-05-07 16:37       ` Tristan Madani
2026-05-07 21:59         ` Viacheslav Dubeyko [this message]
2026-05-07 22:00     ` 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=170c26138376d15553437c2edd57ba74d4267855.camel@redhat.com \
    --to=vdubeyko@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=slava@dubeyko.com \
    --cc=tristmd@gmail.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