Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign updispVM halts prematurely with custom .desktop file involving `qrexec-client-vm` #3318
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
marmarek
Nov 18, 2017
Member
Just to be sure - have you checked the script isn't simply crashing? For example it should be subprocess.PIPE, not subprocess.Pipe. Have you tried running this in non-DisposableVM first?
|
Just to be sure - have you checked the script isn't simply crashing? For example it should be |
andrewdavidwong
added
the
C: other
label
Nov 18, 2017
andrewdavidwong
added this to the Release 4.0 milestone
Nov 18, 2017
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
joshuathayer
Nov 18, 2017
@marmarek, yes, I've run this on a non-dispVM (the "base" VM the dispVM is based on) and it runs without problem.
And right, subprocess.PIPE is correct... sorry for the typo here. It's correct in my script. This code is public (part of this SecureDrop project), so I'll commit the branch I'm working on tomorrow and link to the code in question here.
joshuathayer
commented
Nov 18, 2017
|
@marmarek, yes, I've run this on a non-dispVM (the "base" VM the dispVM is based on) and it runs without problem. And right, |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
joshuathayer
Nov 20, 2017
I've come up with a minimal example of this behavior. It seems to be triggered when making qrexec calls to a disposable target VM, where the target VM then makes its own RPC calls back to the source VM in the course of handling the initial RPC call.
In this example we're going to make an RPC call from personal to a disposable VM based on work. On personal, we'll run qrexec-client-vm work bug.PartOne, then the invoked script will call qrexec-client-vm personal bug.PartTwo. We'll see that while that process works fine on a non-disposable VM, it fails when the target VM is disposable.
On work, create /rw/config/bug.PartOne with the following, and chmod 0755 it:
#!/usr/bin/python
import subprocess
import sys
import time
sys.stderr.write("Hello from bug-part-one. Going to qrexec bug.PartTwo now\n")
subprocess.Popen(["qrexec-client-vm","personal","bug.PartTwo"])
i = 0
while i < 10:
time.sleep(1)
subprocess.Popen(["qrexec-client-vm","personal","bug.PartTwo"])
i += 1
Add the following to /rw/config/rc.local on work:
ln -s /rw/config/bug.PartOne /etc/qubes-rpc/
And also run that command in your running work VM.
On personal, create /rw/config/bug.PartTwo with the following, and chmod 0755 it:
#!/usr/bin/python
import sys
sys.stderr.write("Hello from bug part two!\n")
Although it's not strictly necessary for this demo, to /rw/config/rc.local on personal add:
ln -s /rw/config/bug.PartTwo /etc/qubes-rpc/
and also run that command on your running personal VM.
On dom0, create /etc/qubes-rpc/policy/bug.PartOne and /etc/qubes-rpc/policy/bug.PartTwo with the following:
$anyvm $anyvm allow
And allow work to be a dispvm template:
$ qvm-prefs work template-for-dispvms True
Now we'll all set up. On personal, run:
$ qrexec-client-vm 'work' bug.PartOne
You should see the expected output:
$ qrexec-client-vm 'work' bug.PartOne
Hello from bug-part-one. Going to qrexec bug.PartTwo now
Hello from bug part two!
Hello from bug part two!
Hello from bug part two!
Hello from bug part two!
Hello from bug part two!
Hello from bug part two!
Hello from bug part two!
Hello from bug part two!
Hello from bug part two!
Hello from bug part two!
Hello from bug part two!
$ _
OK, that's what we expect. Now run the same thing on a disposable VM using work as a template:
[user@personal ~]$ qrexec-client-vm '$dispvm:work' bug.PartOne
Hello from bug-part-one. Going to qrexec bug.PartTwo now
Hello from bug part two!
The call never returns, and the disposable VM that was created has crashed.
I believe that if bug.PartTwo is run from the disposable VM targeting a different VM from the initial source (devel, for example), the process runs fine.
joshuathayer
commented
Nov 20, 2017
|
I've come up with a minimal example of this behavior. It seems to be triggered when making In this example we're going to make an RPC call from On
Add the following to
And also run that command in your running On personal, create
Although it's not strictly necessary for this demo, to
and also run that command on your running On
And allow work to be a dispvm template:
Now we'll all set up. On
You should see the expected output:
OK, that's what we expect. Now run the same thing on a disposable VM using
The call never returns, and the disposable VM that was created has crashed. I believe that if |
added a commit
to marmarek/qubes-core-agent-linux
that referenced
this issue
Nov 21, 2017
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
marmarek
Nov 21, 2017
Member
I think this is about qrexec connection cleanup. When you execute two qrexec connections between the same domains (and those are the only connections), but in opposite directions, they will be assigned the same vchan port number. This is normally ok, because connection direction differs (different VM act as a server). But connection cleanup code got confused and report wrong connection being closed. The only code using that report in practice is cleanup of DispVM.
I've pushed preliminary attempt to fix this, but it doesn't work yet.
|
I think this is about qrexec connection cleanup. When you execute two qrexec connections between the same domains (and those are the only connections), but in opposite directions, they will be assigned the same vchan port number. This is normally ok, because connection direction differs (different VM act as a server). But connection cleanup code got confused and report wrong connection being closed. The only code using that report in practice is cleanup of DispVM. I've pushed preliminary attempt to fix this, but it doesn't work yet. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
joshuathayer
Nov 21, 2017
@marmarek thanks for your prompt attention! I suspected something along those lines, but had no idea where to start looking... I'll be interested to take a close look at your patch. Is there documentation anywhere about setting up a development environment for building and testing these core libraries? I'd rather be submitting patches than reporting bugs ;)
joshuathayer
commented
Nov 21, 2017
|
@marmarek thanks for your prompt attention! I suspected something along those lines, but had no idea where to start looking... I'll be interested to take a close look at your patch. Is there documentation anywhere about setting up a development environment for building and testing these core libraries? I'd rather be submitting patches than reporting bugs ;) |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
marmarek
Nov 21, 2017
Member
See here: https://www.qubes-os.org/doc/development-workflow/
For testing I suggest using cloned template (to not brick to many pieces at once).
There is also (really poor :/) documentation of qrexec internals: https://www.qubes-os.org/doc/qrexec3/#qrexec-protocol-details
As for the bug - the dom0 counterpart is here: https://github.com/QubesOS/qubes-core-admin-linux/blob/master/qrexec/qrexec-daemon.c#L387-L517 and https://github.com/QubesOS/qubes-core-admin-linux/blob/master/qrexec/qrexec-client.c#L713-L805. Unfortunately the logic about vchan port allocation is quite convoluted (the second link), mostly because dom0 is special - do not have own qrexec-agent/qrexec-daemon pair.
BTW if you want to install qrexec service in one VM only, you can use /usr/local/etc/qubes-rpc (which is part of /rw), instead of ln -s in rc.local.
|
See here: https://www.qubes-os.org/doc/development-workflow/ As for the bug - the dom0 counterpart is here: https://github.com/QubesOS/qubes-core-admin-linux/blob/master/qrexec/qrexec-daemon.c#L387-L517 and https://github.com/QubesOS/qubes-core-admin-linux/blob/master/qrexec/qrexec-client.c#L713-L805. Unfortunately the logic about vchan port allocation is quite convoluted (the second link), mostly because dom0 is special - do not have own qrexec-agent/qrexec-daemon pair. BTW if you want to install qrexec service in one VM only, you can use |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
joshuathayer
commented
Nov 21, 2017
|
Thanks so much, I'll spend some time with that tomorrow. |
joshuathayer commentedNov 17, 2017
Qubes OS version:
4.0rc2 (
dom0and templates up to date with testing repos)Affected TemplateVMs:
At least fedora-25
Steps to reproduce the behavior:
I have a situation where I'm trying to open a particular file format in a disposable VM, from a (Whonix-based) AppVM, eg:
In my
workVM I've configured xdg to associate.custom-extto a python script. That script processes the given file, and as a side effect there's a call toqrexec-client-vm, eg:Expected behavior:
I'd expect:
workVM to startActual behavior:
My script seems to run as far as the call to qrexec (which completes successfully), and then the entire VM gets shut down. While the machine is shutting down, my script is still running: based on writes to STDERR, it's able to make some inconsistent number of lines before the machine is down.
General notes:
Removing the
Popencall from my script allows it to run and complete normally.Running the command on a non-disposable VM allows the script to run and complete normally, eg:
works great.
I suspected the issue may have had something to do with my script's
STDIN/OUT/ERRbeing passed to the spawned child, but the following didn't change behavior at all:For debugging, i tried making other calls which involve a
fork()in my processing script, and those calls seemed to complete without error and without causing the VM to halt. Only the call toqrexec-client-vmcaused the machine to halt.Also for debugging I tried not using a pipe for
stdin(instead using the same/dev/nullfilehandle), and that also didn't change matters.I'm stumped. I'm not sure this is a Qubes bug as much as my not understanding something, but I do expect the behavior I noted above. Thanks for taking a look!
Related issues: