mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>
To: "shardul.b@mpiricsoftware.com" <shardul.b@mpiricsoftware.com>,
	"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>
Cc: "janak@mpiric.us" <janak@mpiric.us>,
	"janak@mpiricsoftware.com" <janak@mpiricsoftware.com>,
	"shardulsb08@gmail.com" <shardulsb08@gmail.com>,
	"syzbot+1c8ff72d0cd8a50dfeaa@syzkaller.appspotmail.com"
	<syzbot+1c8ff72d0cd8a50dfeaa@syzkaller.appspotmail.com>
Subject: RE:  [PATCH v5 2/2] hfsplus: validate b-tree node 0 bitmap at mount time
Date: Mon, 9 Mar 2026 19:39:22 +0000	[thread overview]
Message-ID: <777135e49c8f44f1f9a023d88be9a55b7acf2426.camel@ibm.com> (raw)
In-Reply-To: <66104cc5521c69a4745b894be307eec25333eb09.camel@mpiricsoftware.com>

On Mon, 2026-03-09 at 17:16 +0530, Shardul Bankar wrote:
> On Mon, 2026-03-02 at 23:45 +0000, Viacheslav Dubeyko wrote:
> > On Sat, 2026-02-28 at 17:53 +0530, Shardul Bankar wrote:
> > > diff --git a/fs/hfsplus/btree.c b/fs/hfsplus/btree.c
> > > index 87650e23cd65..ee1edb03a38e 100644
> > > --- a/fs/hfsplus/btree.c
> > > +++ b/fs/hfsplus/btree.c
> > > @@ -239,15 +239,31 @@ static int hfs_bmap_clear_bit(struct
> > > hfs_bnode *node, u32 bit_idx)
> > >         return 0;
> > >  }
> > >  
> > > +static const char *hfs_btree_name(u32 cnid)
> > > +{
> > > +       static const char * const tree_names[] = {
> > > +               [HFSPLUS_EXT_CNID] = "Extents",
> > > +               [HFSPLUS_CAT_CNID] = "Catalog",
> > > +               [HFSPLUS_ATTR_CNID] = "Attributes",
> > > +       };
> > > +
> > > +       if (cnid < ARRAY_SIZE(tree_names) && tree_names[cnid])
> > > +               return tree_names[cnid];
> > > +
> > 
> > #define HFS_POR_CNID            1       /* Parent Of the Root */
> > #define HFSPLUS_POR_CNID        HFS_POR_CNID
> > #define HFS_ROOT_CNID           2       /* ROOT directory */
> > #define HFSPLUS_ROOT_CNID       HFS_ROOT_CNID
> > #define HFS_EXT_CNID            3       /* EXTents B-tree */
> > #define HFSPLUS_EXT_CNID        HFS_EXT_CNID
> > #define HFS_CAT_CNID            4       /* CATalog B-tree */
> > #define HFSPLUS_CAT_CNID        HFS_CAT_CNID
> > #define HFS_BAD_CNID            5       /* BAD blocks file */
> > #define HFSPLUS_BAD_CNID        HFS_BAD_CNID
> > #define HFS_ALLOC_CNID          6       /* ALLOCation file (HFS+) */
> > #define HFSPLUS_ALLOC_CNID      HFS_ALLOC_CNID
> > #define HFS_START_CNID          7       /* STARTup file (HFS+) */
> > #define HFSPLUS_START_CNID      HFS_START_CNID
> > #define HFS_ATTR_CNID           8       /* ATTRibutes file (HFS+) */
> > #define HFSPLUS_ATTR_CNID       HFS_ATTR_CNID
> > #define HFS_EXCH_CNID           15      /* ExchangeFiles temp id */
> > #define HFSPLUS_EXCH_CNID       HFS_EXCH_CNID
> > #define HFS_FIRSTUSER_CNID      16      /* first available user id */
> > #define HFSPLUS_FIRSTUSER_CNID  HFS_FIRSTUSER_CNID
> > 
> > What if cnid will be 1, 2, 5? How correctly will logic works? For may
> > taste, the
> > declaration looks slightly dangerous.
> > 
> > It will much easier simply introduce the string constants:
> > 
> > #define HFS_EXTENT_TREE_NAME  "Extents"
> > ...
> > #define HFS_UNKNOWN_BTREE_NAME  "Unknown"
> > 
> > Probably, simple switch will be simpler implementation here:
> > 
> > switch (cnid) {
> > case HFSPLUS_EXT_CNID:
> >     return HFS_EXTENT_TREE_NAME;
> > ...
> > default:
> >     return HFS_UNKNOWN_BTREE_NAME;
> > }
> > 
> > Or it needs to introduce array that will initialize all items from 0
> > - 15.
> > 
> > Maybe, I am too picky here. This logic should work. But I prefer to
> > have string
> > declarations outside of function.
> > 
> 
> I originally used the array based on your feedback from the v4 review,
> where you mentioned preferring an array of constant strings over a
> switch statement.
> 
> To address your concern about unlisted indices like 1, 2, and 5: I
> tested this case locally to be absolutely sure. Because of how the
> compiler initializes arrays, any index not explicitly defined is set to
> NULL (0). For example, I temporarily removed HFSPLUS_CAT_CNID from the
> array and triggered the bug. The if (tree_names[cnid]) condition
> successfully caught the NULL and the kernel safely logged:
> hfsplus: (loop0): Unknown Btree (cnid 0x4) bitmap corruption
> detected...
> 
> That being said, I agree that defining the strings as macros outside
> the function combined with a standard switch statement makes the
> definitions much more visible to the rest of the subsystem. I am more
> than happy to rewrite it using the #define and switch approach exactly
> as you suggested for v6. Let me know which approach you prefer.
> 
> 

I think we need to declare the strings outside of the method. I recommended the
strings array because it's nice to have. But I missed the point that we don't
have the contiguous sequence of indexes. Because, we have only three strings to
distinguish, then solution based on switch looks like more clean and simple one.
Do you agree? :)

Thanks,
Slava.

  reply	other threads:[~2026-03-09 19:39 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-28 12:23 [PATCH v5 0/2] hfsplus: prevent b-tree allocator corruption Shardul Bankar
2026-02-28 12:23 ` [PATCH v5 1/2] hfsplus: refactor b-tree map page access and add node-type validation Shardul Bankar
2026-03-02 23:25   ` Viacheslav Dubeyko
2026-03-09 11:46     ` Shardul Bankar
2026-03-09 19:28       ` Viacheslav Dubeyko
2026-02-28 12:23 ` [PATCH v5 2/2] hfsplus: validate b-tree node 0 bitmap at mount time Shardul Bankar
2026-03-02 23:45   ` Viacheslav Dubeyko
2026-03-09 11:46     ` Shardul Bankar
2026-03-09 19:39       ` Viacheslav Dubeyko [this message]
2026-03-09 19:56         ` Shardul Bankar

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=777135e49c8f44f1f9a023d88be9a55b7acf2426.camel@ibm.com \
    --to=slava.dubeyko@ibm.com \
    --cc=frank.li@vivo.com \
    --cc=glaubitz@physik.fu-berlin.de \
    --cc=janak@mpiric.us \
    --cc=janak@mpiricsoftware.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shardul.b@mpiricsoftware.com \
    --cc=shardulsb08@gmail.com \
    --cc=slava@dubeyko.com \
    --cc=syzbot+1c8ff72d0cd8a50dfeaa@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®