puzzleos / stubby

UEFI bootloader stub
GNU Lesser General Public License v2.1
13 stars 8 forks source link

Add support for runtime command lines. #21

Closed smoser closed 2 years ago

smoser commented 2 years ago

Fixes https://github.com/puzzleos/stubby/issues/20.

If a stubby executable has a builtin command line that includes the "marker" string STUBBY_RT_CLI1 as a whole token, then any runtime command line will be placed in that position in the kernel's command line.

As an example:

builtin: foo=bar root=wark STUBBY_RT_CLI console=tty0
runtime: console=ttyS0
result: foo=bar root=wark console=ttyS0 console=tty0

Some things to note:

smoser commented 2 years ago

fixes #20

smoser commented 2 years ago

So 2 things todo here:

  1. reject '--' followed by key=value as serge suggested
  2. actually test this. I've done almost all of it with LINUX_TEST, so... actual test would be good.

For 2, i have a test harness in reasonable shape and wlil poke a bit at that now.

hallyn commented 2 years ago

Thanks! Is there anything more you wanted to do before we merge?

smoser commented 2 years ago

Just like to say that we decided to not bother with special handling on -- because anything in the runtime command line is checked against the allowed list. If the user puts the marker after --, then they're probably getting what they expected.

smoser commented 2 years ago

Just some notes on -- that I made from another discussion with serge that may be helpful later.

from kernel-parameters.html:

The kernel parses parameters from the kernel command line up to --; if it doesn’t recognize a parameter and it doesn’t contain a ‘.’, the parameter gets passed to init: parameters with ‘=’ go into init’s environment, others are passed as command line arguments to init. Everything after -- is passed as an argument to init.

My understanding is that systemd doensn't really care much what is on its command line versus what it fishes out of /proc/cmdline. Also, it seems that when an initrd is used, the statement above is simply not true. In that case, the kernel does not pass any arguments to /init, so it would be up to /init to implement policy on what goes through to /sbin/init (probably by reading /proc/cmdline).

My understanding is that initrds do not do what the kernel describes.

In my c-i-boot-test for #13, I added code to the initramfs that we build to show the parameters that /init is provided with.