From: "Darrick J. Wong" <djwong@kernel.org>
To: Eric Sandeen <sandeen@sandeen.net>
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH 4/4] mkfs: terminate getsubopt arrays properly
Date: Wed, 13 Jul 2022 18:59:24 -0700 [thread overview]
Message-ID: <Ys94fFgxLGyGb/W4@magnolia> (raw)
In-Reply-To: <2a452d57-9e2e-7908-b3f5-0444b6a62761@sandeen.net>
On Wed, Jul 13, 2022 at 08:39:24PM -0500, Eric Sandeen wrote:
> On 7/12/22 8:09 PM, Darrick J. Wong wrote:
> > From: Darrick J. Wong <djwong@kernel.org>
> >
> > Having not drank any (or maybe too much) coffee this morning, I typed:
> >
> > $ mkfs.xfs -d agcount=3 -d nrext64=0
> > Segmentation fault
> >
> > I traced this down to getsubopt walking off the end of the dopts.subopts
> > array. The manpage says you're supposed to terminate the suboptions
>
> (the getsubopt(3) manpage for those following along at home)
>
> > string array with a NULL entry, but the structure definition uses
> > MAX_SUBOPTS/D_MAX_OPTS directly, which means there is no terminator.
> >
> > Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> > ---
> > mkfs/xfs_mkfs.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> >
> > diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
> > index 61ac1a4a..9a58ff8b 100644
> > --- a/mkfs/xfs_mkfs.c
> > +++ b/mkfs/xfs_mkfs.c
> > @@ -141,7 +141,7 @@ enum {
> > };
> >
> > /* Just define the max options array size manually right now */
> > -#define MAX_SUBOPTS D_MAX_OPTS
> > +#define MAX_SUBOPTS (D_MAX_OPTS + 1)
>
> Hah, I had not noticed this before. So this relies on there being more
> suboptions for -d than anything else, I guess. What could go wrong?
>
> OK, so this fixes it because opt_params is a global, and it contains
> subopt_params[MAX_SUBOPTS];, so the last array entry will be null
> (by virtue of globals being zeroed) and that's all perfectly clear :D
<nod>
> Well, it fixes it for now. I'd like to add i.e.
>
> @@ -251,6 +251,7 @@ static struct opt_params bopts = {
> .ini_section = "block",
> .subopts = {
> [B_SIZE] = "size",
> + [B_MAX_OPTS] = NULL,
> },
>
> etc to each suboption array to be explicit about it, sound ok? I can do
> that on commit if it seems ok.
Oh, that /is/ a good idea, in case B_MAX_OPTS > D_MAX_OPTS ever happens.
--D
> Reviewed-by: Eric Sandeen <sandeen@sandeen.net>
>
> Thanks,
> -Eric
>
> >
> > #define SUBOPT_NEEDS_VAL (-1LL)
> > #define MAX_CONFLICTS 8
> >
next prev parent reply other threads:[~2022-07-14 1:59 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-13 1:09 [PATCHSET 0/4] xfsprogs: random fixes Darrick J. Wong
2022-07-13 1:09 ` [PATCH 1/4] xfs_repair: ignore empty xattr leaf blocks Darrick J. Wong
2022-07-13 1:09 ` [PATCH 2/4] xfs_repair: Search for conflicts in inode_tree_ptrs[] when processing uncertain inodes Darrick J. Wong
2022-07-13 1:09 ` [PATCH 3/4] mkfs: complain about impossible log size constraints Darrick J. Wong
2022-07-14 1:17 ` Eric Sandeen
2022-07-14 2:03 ` Darrick J. Wong
2022-07-13 1:09 ` [PATCH 4/4] mkfs: terminate getsubopt arrays properly Darrick J. Wong
2022-07-14 1:39 ` Eric Sandeen
2022-07-14 1:59 ` Darrick J. Wong [this message]
2022-07-14 2:03 ` Eric Sandeen
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=Ys94fFgxLGyGb/W4@magnolia \
--to=djwong@kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=sandeen@sandeen.net \
/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