mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ardb@kernel.org>
To: Jonathan Marek <jonathan@marek.ca>
Cc: linux-efi@vger.kernel.org,
	 Kuppuswamy Sathyanarayanan
	<sathyanarayanan.kuppuswamy@linux.intel.com>,
	Ingo Molnar <mingo@kernel.org>,
	 open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/3] efi/libstub: fix efi_parse_options() ignoring the default command line
Date: Sat, 12 Oct 2024 15:15:34 +0200	[thread overview]
Message-ID: <CAMj1kXFfsjPy9UxtC4f6n+FBBYRdyGw6h0b9fkn3_NDxTL7nPg@mail.gmail.com> (raw)
In-Reply-To: <5364ea9f-9042-3fba-5cb1-c42ae94b0d4b@marek.ca>

On Sat, 12 Oct 2024 at 13:58, Jonathan Marek <jonathan@marek.ca> wrote:
>
> On 10/12/24 3:46 AM, Ard Biesheuvel wrote:
> > Hi Jonathan,
> >
> > Please use a cover letter when sending more than a single patch.
> >
> > On Sat, 12 Oct 2024 at 00:51, Jonathan Marek <jonathan@marek.ca> wrote:
> >>
> >> efi_convert_cmdline() always returns a size of at least 1 because it counts
> >> the NUL terminator, so the "cmdline_size == 0" condition is not possible.
> >>
> >> Change it to compare against 1 to get the intended behavior: to use
> >> CONFIG_CMDLINE when load_options_size is 0.
> >>
> >> Fixes: 60f38de7a8d4 ("efi/libstub: Unify command line param parsing")
> >> Signed-off-by: Jonathan Marek <jonathan@marek.ca>
> >> ---
> >>   drivers/firmware/efi/libstub/efi-stub.c | 2 +-
> >>   1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi/libstub/efi-stub.c
> >> index 958a680e0660d..709ae2d41a632 100644
> >> --- a/drivers/firmware/efi/libstub/efi-stub.c
> >> +++ b/drivers/firmware/efi/libstub/efi-stub.c
> >> @@ -129,7 +129,7 @@ efi_status_t efi_handle_cmdline(efi_loaded_image_t *image, char **cmdline_ptr)
> >>
> >>          if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) ||
> >>              IS_ENABLED(CONFIG_CMDLINE_FORCE) ||
> >> -           cmdline_size == 0) {
> >> +           cmdline_size == 1) {
> >
> > I'd prefer it if we could keep the weirdness local to
> > efi_convert_cmdline(). Would the below fix things too?
> >
> > --- a/drivers/firmware/efi/libstub/efi-stub-helper.c
> > +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c
> > @@ -395,9 +395,7 @@
> >                  }
> >          }
> >
> > -       options_bytes++;        /* NUL termination */
> > -
> > -       status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, options_bytes,
> > +       status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, options_bytes + 1,
> >                               (void **)&cmdline_addr);
> >          if (status != EFI_SUCCESS)
> >                  return NULL;
> >
> > Note that the only other caller of efi_convert_cmdline() in x86-stub.c
> > ignores this value entirely.
> >
>
> Just changing this would just make things more broken, the following
> snprintf would remove the last character of the command line because it
> uses options_bytes.
>

Ugh, you're right. So just use options_bytes - 1 in the assignment then.

> Since this patch has a Fixes: tag, I wanted to make the fix as simple as
> possible. If you think comparing the size to 1 is "weird", the fix could
> instead check if cmdline[0] is non-NUL (or just strlen(cmdline)==0 if
> you don't like that either).
>

Checking the value of the first byte is reasonable I think.

> And then my followup cleanup patch can just remove the cmd_line_len
> argument from efi_convert_cmdline().

Yes that would be fine - it is not really useful in any case.

      reply	other threads:[~2024-10-12 13:15 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-11 22:48 Jonathan Marek
2024-10-11 22:48 ` [PATCH 2/3] efi/libstub: remove uneccessary cmdline_size init/check Jonathan Marek
2024-10-12  7:49   ` Ard Biesheuvel
2024-10-11 22:48 ` [PATCH 3/3] efi/libstub: consider CONFIG_CMDLINE for initrd= and dtb= options Jonathan Marek
2024-10-12  7:54   ` Ard Biesheuvel
2024-10-12 12:00     ` Jonathan Marek
2024-10-12 13:36       ` Ard Biesheuvel
2024-10-12 14:07         ` Jonathan Marek
2024-10-12 14:50           ` Ard Biesheuvel
2024-10-12 15:00             ` Jonathan Marek
2024-10-15  0:13   ` kernel test robot
2024-10-15  2:08   ` kernel test robot
2024-10-12  7:46 ` [PATCH 1/3] efi/libstub: fix efi_parse_options() ignoring the default command line Ard Biesheuvel
2024-10-12 11:55   ` Jonathan Marek
2024-10-12 13:15     ` Ard Biesheuvel [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=CAMj1kXFfsjPy9UxtC4f6n+FBBYRdyGw6h0b9fkn3_NDxTL7nPg@mail.gmail.com \
    --to=ardb@kernel.org \
    --cc=jonathan@marek.ca \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=sathyanarayanan.kuppuswamy@linux.intel.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®