[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: grub2 not using linux cmdline as verbatim

From: Jiri Jaburek
Subject: Re: grub2 not using linux cmdline as verbatim
Date: Fri, 12 Jun 2015 18:06:40 +0200

On 06/12/2015 05:34 PM, Andrei Borzenkov wrote:
> В Fri, 12 Jun 2015 16:58:29 +0200
> Jiri Jaburek <address@hidden> пишет:
>> I understand that the logic is simply trying to do what the user
>> *probably* wants, it just gets in the way when the user wants something
>> different.
> OK, let's start from the beginning.
> We are not speaking about arbitrary strings here. We are speaking about
> Linux kernel command line. Let's make it clear from the start.
> Kernel does not get array of arguments as happens in Unix user level
> programs. Kernel gets single string that it has to parse to extract
> individual arguments and their values. That means this single string
> *must* include some delimiters to separate individual arguments as
> well as some way to quote these delimiters so they can be used as
> part of argument (values).
> So Linux kernel is using white spaces as delimiters between individual
> arguments and quotes to escape white spaces inside of argument.
> Now back to grub. First GRUB script is parsed. At this point we have
> standard shell grammar without any special knowledge. It means that
> command
> linux /foo/bar arg1 arg2="parm1 parm2" arg3
> Will be parsed as *five* words
> linux
> /foo/bar
> arg1
> arg2=parm1 parm2
> arg3
> First word is command, subsequent words are arguments to this
> command. Now GRUB command linux sees 4 arguments. It assumes that user
> intends each argument to also be interpreted as single argument by
> Linux kernel and *not* be split into multiple arguments. So it checks
> each argument whether it includes spaces and if yes, it quotes them
> *for Linux kernel*. Then it concatenates them separating by space.
> Thus kernel sees the following - single - command line
> arg1 "arg2=parm1 parm2" arg3
> Which actually does the right thing. It allows user to write GRUB
> command using the same semantic as kernel would see.
> Does it finally make it clear?

Yes, thanks. I kind of realized that *something* is quoting the line
specifically for the linux kernel, but wasn't sure if it's the shell
itself or something else above/below.
grub-core/lib/cmdline.c makes it pretty clear.

Now this is something worth documenting.

>>> Note that in case of Linux kernel it is simply impossible to pass lone
>>> `"' to kernel - it will slurp up all remaining characters as a single
>>> argument.
>> Indeed, linux/kernel/params.c is quite simple, but that's not exactly
>> my concern.
> Sure, but then it is not GRUB concern that you cannot pass garbage. You
> still need to provide good arguments why you must pass garbage.

I believe that would be worth further discussion on grub-devel,
whether the bootloader should care about / check / interfere with
possible garbage being passed to the kernel.
(Or rather whether it should help with passing "garbage".)

Note that the cmdline might contain what appears to be garbage, but
isn't - if the (however weird) init implementation needs single quote
as an argument, it can be passed after `--', at which
linux/kernel/params.c stops, which is something grub/cmdline.c could
check for.

> That said, I suspect fixing overquoting would be enough to solve your
> problem.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]