Skip to content

Commit

Permalink
virtme-run: Don't panic if an unrecognized argument is passed to -a
Browse files Browse the repository at this point in the history
The kernel interprets:

  init=/bin/sh foobar -- baz quux

as a request to run /bin/sh foobar baz quux, unless foobar is a
known kernel parameter.  As a result, passing '-a foobar' to
virtme-run will panic the guest.  I think this is a bug or design
error in the kernel argument parser.

Fortunately, there's another counterbalancing quirk:

  foobar init=/bin/sh -- baz quux

will cause foobar to be ignored because init=/bin/sh resets
accumulated init arguments.

Reorder our argument generation to take advantage of this quirk and
avoid panicking if a bad argument is passed.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
  • Loading branch information
amluto committed May 1, 2016
1 parent a449fc2 commit ea58d42
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions virtme/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,6 @@ def main():
export_virtfs(qemu, arch, qemuargs, guest_tools_path,
'virtme.guesttools')

kernelargs.append('init=/bin/sh')

initargs = ['-c', 'mount -t tmpfs run /run;mkdir -p /run/virtme/guesttools;/bin/mount -n -t 9p -o ro,version=9p2000.L,trans=virtio,access=any virtme.guesttools /run/virtme/guesttools;exec /run/virtme/guesttools/virtme-init']

# Map modules
Expand Down Expand Up @@ -395,6 +393,12 @@ def do_script(shellcmd):
# Now that we're done setting up kernelargs, append user-specified args
# and then initargs
kernelargs.extend(args.kopt)

# Unknown options get turned into arguments to init, which is annoying
# because we're explicitly passing '--' to set the arguments directly.
# Fortunately, 'init=' will clear any arguments parsed so far, so make
# sure that 'init=' appears directly before '--'.
kernelargs.append('init=/bin/sh')
kernelargs.append('--')
kernelargs.extend(initargs)

Expand Down

0 comments on commit ea58d42

Please sign in to comment.