QubesOS / qubes-issues

The Qubes OS Project issue tracker
https://www.qubes-os.org/doc/issue-tracking/
532 stars 46 forks source link

qvm-run -p: “; exit” is sometimes prepended to the stdin #4937

Open v6ak opened 5 years ago

v6ak commented 5 years ago

Qubes OS version R4.0

Affected component(s) or functionality qvm-run -p in dom0

Brief summary Sometimes, I get “; exit” prepended to the pipe passed to a domU.

To Reproduce

  1. Run this in dom0:

    echo hello | qvm-run -p some-linux-qube 'cat x'

  2. See the output

Expected behavior Text hello is echoed back (with newline). Then, I expect to get an error message about unknown command x.

Actual behavior

I actually get this:

d; exit
hello

Additional context

I have tried to grep ; exit in Qubes sources. I have found that this text comes from prepare_input_for_vmshell, which mixes command and input that is later passed to qubes.VMShell RPC endpoint. I am not sure if I understand the reason behind adding the ; exit. Maybe all the input (including the command) is passed to sh (through qubes.VMShell) through stdin, so the “; exit” is a hack for ensuring that command ends there. It seems to work well in many cases, but not always.

BTW, there are also some other rough edges:

$ echo "world'" | qvm-run -p some-linux-qube "echo 'hello "
hello ; exit
world

This one is a wrong behavior for an invalid command, which does not matter so much. The original issue is about a wrong behavior for a valid command, which is worse.

Solutions you've tried

Sometimes, just trimming trailing whitespace solves the problem, even for multi-line command. (It is not the case of the command there.)

Relevant documentation you've consulted

qvm-run --help

Related, non-duplicate issues

https://github.com/QubesOS/qubes-issues/issues/4165

DemiMarie commented 1 year ago

Simplest fix would be to reimplement this in terms of qubes.VMExec, which does not have this problem.