Skip to contentSkip to conversation

kvm tools: Export DISPLAY ENV as our default host ip address

PATCH In review Asias He 4 participants 19 messages Aug 24, 2012 – Sep 10, 2012 KVM

lore
Share & tools
lore

Asias He

author
#0 lore raw

PATCH 1/2 kvm tools: Export DISPLAY ENV as our default host ip address

It is useful to run a X program in guest and display it on host.

1) Make host's x server listen to localhost:6000

   host_shell$ socat -d -d TCP-LISTEN:6000,fork,bind=localhost \
               UNIX-CONNECT:/tmp/.X11-unix/X0

2) Start the guest and run X program
host_shell$ lkvm run -k /boot/bzImage
guest_shell$ xlogo

---
 tools/kvm/guest/init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/kvm/guest/init.c +1 -1
index 6a2e1cd..44e7db8 100644
@@ -12,7 +12,7 @@
 static int run_process(char *filename)
 {
 	char *new_argv[] = { filename, NULL };
-	char *new_env[] = { "TERM=linux", NULL };
+	char *new_env[] = { "TERM=linux", "DISPLAY=192.168.33.1:0", NULL };
 
 	return execve(filename, new_argv, new_env);
 }
Signature · 1 line
1.7.11.4
author
#1 lore raw

PATCH 2/2 kvm tools: Mount devpts to /dev/pts

I'm seeing this in guest due to lacking of /dev/pts:

sh-4.2# xterm
xterm: Error 32, errno 28: No space left on device
Reason: get_pty: not enough ptys

---
 tools/kvm/guest/init.c | 2 ++
 1 file changed, 2 insertions(+)
tools/kvm/guest/init.c +2 -0
index 44e7db8..e1f377f 100644
@@ -31,6 +31,8 @@ static void do_mounts(void)
 	mount("", "/sys", "sysfs", 0, NULL);
 	mount("proc", "/proc", "proc", 0, NULL);
 	mount("devtmpfs", "/dev", "devtmpfs", 0, NULL);
+	mkdir("/dev/pts", 0755);
+	mount("devpts", "/dev/pts", "devpts", 0, NULL);
 }
 
 int main(int argc, char *argv[])
Signature · 1 line
1.7.11.4
#2 lore raw
In reply to Asias He
Quoted 10 lines · Asias He

It is useful to run a X program in guest and display it on host.

1) Make host's x server listen to localhost:6000

   host_shell$ socat -d -d TCP-LISTEN:6000,fork,bind=localhost \
               UNIX-CONNECT:/tmp/.X11-unix/X0

2) Start the guest and run X program
host_shell$ lkvm run -k /boot/bzImage
guest_shell$ xlogo

Note, this is insecure, don't do this with untrusted guests.

Signature · 1 line
error compiling committee.c: too many arguments to function
author
#3 lore raw
Quoted 7 lines · Avi Kivity
Quoted 6 lines · Asias He

It is useful to run a X program in guest and display it on host.

1) Make host's x server listen to localhost:6000

   host_shell$ socat -d -d TCP-LISTEN:6000,fork,bind=localhost \
               UNIX-CONNECT:/tmp/.X11-unix/X0
Quoted 6 lines
Quoted 4 lines

2) Start the guest and run X program
host_shell$ lkvm run -k /boot/bzImage
guest_shell$ xlogo

Note, this is insecure, don't do this with untrusted guests.

In this use case, the user on the host side should trust the guest.

Btw, any attack the untrusted guests can do with the X port which host listens?

Signature · 1 line
Asias He
#4 lore raw
Quoted 13 lines · Asias He
Quoted 12 lines · Avi Kivity
Quoted 10 lines · Asias He

It is useful to run a X program in guest and display it on host.

1) Make host's x server listen to localhost:6000

   host_shell$ socat -d -d TCP-LISTEN:6000,fork,bind=localhost \
               UNIX-CONNECT:/tmp/.X11-unix/X0

2) Start the guest and run X program
host_shell$ lkvm run -k /boot/bzImage
guest_shell$ xlogo

Quoted 5 lines
Quoted 1 line

Note, this is insecure, don't do this with untrusted guests.

In this use case, the user on the host side should trust the guest.

Btw, any attack the untrusted guests can do with the X port which host listens?

Steal the entire display, record user keystrokes, present false information.

btw, how did it work? The you need the xauth cookie for this to work, or disable authentication.

Signature · 1 line
error compiling committee.c: too many arguments to function
#15 lore raw
In reply to Avi Kivity
Quoted 9 lines · Asias He
Quoted 9 lines

It is useful to run a X program in guest and display it on host.

1) Make host's x server listen to localhost:6000

   host_shell$ socat -d -d TCP-LISTEN:6000,fork,bind=localhost \
               UNIX-CONNECT:/tmp/.X11-unix/X0

2) Start the guest and run X program
host_shell$ lkvm run -k /boot/bzImage
guest_shell$ xlogo

Quoted 1 line · Avi Kivity

Note, this is insecure, don't do this with untrusted guests.

Asias, can we add a command line argument that enables this? It'd be safer to keep it disabled by default.

#16 lore raw
Quoted 11 lines · Pekka Enberg
Quoted 9 lines · Asias He
Quoted 9 lines

It is useful to run a X program in guest and display it on host.

1) Make host's x server listen to localhost:6000

   host_shell$ socat -d -d TCP-LISTEN:6000,fork,bind=localhost \
               UNIX-CONNECT:/tmp/.X11-unix/X0

2) Start the guest and run X program
host_shell$ lkvm run -k /boot/bzImage
guest_shell$ xlogo

Quoted 5 lines
Quoted 1 line · Avi Kivity

Note, this is insecure, don't do this with untrusted guests.

Asias, can we add a command line argument that enables this? It'd be safer to keep it disabled by default.

It might also be prudent to name the option in a way that signals that the user of it understands the security implications:

	--X11-trusted-guest 1

or so.

Thanks,

Ingo

author
#18 lore raw
In reply to Pekka Enberg
Quoted 11 lines · Pekka Enberg
Quoted 9 lines · Asias He
Quoted 9 lines

It is useful to run a X program in guest and display it on host.

1) Make host's x server listen to localhost:6000

   host_shell$ socat -d -d TCP-LISTEN:6000,fork,bind=localhost \
               UNIX-CONNECT:/tmp/.X11-unix/X0

2) Start the guest and run X program
host_shell$ lkvm run -k /boot/bzImage
guest_shell$ xlogo

Quoted 5 lines
Quoted 1 line · Avi Kivity

Note, this is insecure, don't do this with untrusted guests.

Asias, can we add a command line argument that enables this? It'd be safer to keep it disabled by default.

Step 1) is not started by lkvm, if user does not run the socat cmd in host side, the remote display for guest will not work at all.

This patch only set DISPLAY env to host IP. if user runs the socat cmd in host side, even if without the exporting DISPLAY env, the untrusted guest can also do the attack.

Signature · 1 line
Asias He
author
#17 lore raw
In reply to Ingo Molnar
Quoted 17 lines · Ingo Molnar
Quoted 14 lines · Pekka Enberg
Quoted 9 lines · Asias He
Quoted 9 lines

It is useful to run a X program in guest and display it on host.

1) Make host's x server listen to localhost:6000

   host_shell$ socat -d -d TCP-LISTEN:6000,fork,bind=localhost \
               UNIX-CONNECT:/tmp/.X11-unix/X0

2) Start the guest and run X program
host_shell$ lkvm run -k /boot/bzImage
guest_shell$ xlogo

Quoted 1 line · Avi Kivity

Note, this is insecure, don't do this with untrusted guests.

Quoted 9 lines
Quoted 2 lines

Asias, can we add a command line argument that enables this? It'd be safer to keep it disabled by default.

It might also be prudent to name the option in a way that signals that the user of it understands the security implications:

        --X11-trusted-guest 1

Yes. If we do something like the socat cmd does in step 1) above in lkvm, we need a option to enable that explicitly.

Signature · 1 line
Asias He
author
#5 lore raw
In reply to Avi Kivity
Quoted 14 lines · Avi Kivity
Quoted 13 lines · Asias He
Quoted 12 lines · Avi Kivity
Quoted 10 lines · Asias He

It is useful to run a X program in guest and display it on host.

1) Make host's x server listen to localhost:6000

   host_shell$ socat -d -d TCP-LISTEN:6000,fork,bind=localhost \
               UNIX-CONNECT:/tmp/.X11-unix/X0

2) Start the guest and run X program
host_shell$ lkvm run -k /boot/bzImage
guest_shell$ xlogo

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Note, this is insecure, don't do this with untrusted guests.

In this use case, the user on the host side should trust the guest.

Btw, any attack the untrusted guests can do with the X port which host listens?

Steal the entire display, record user keystrokes, present false information.

OK.

Quoted 2 lines

btw, how did it work? The you need the xauth cookie for this to work, or disable authentication.

The trick here is just listening tcp x11 port(only on localhost) and forwarding the tcp x11 data to local socket.
The auth sutff should be done by the host side normal X11 setup.

Signature · 1 line
Asias He
#6 lore raw
Quoted 23 lines · Asias He
Quoted 14 lines · Avi Kivity
Quoted 13 lines · Asias He
Quoted 12 lines · Avi Kivity
Quoted 10 lines · Asias He

It is useful to run a X program in guest and display it on host.

1) Make host's x server listen to localhost:6000

   host_shell$ socat -d -d TCP-LISTEN:6000,fork,bind=localhost \
               UNIX-CONNECT:/tmp/.X11-unix/X0

2) Start the guest and run X program
host_shell$ lkvm run -k /boot/bzImage
guest_shell$ xlogo

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Note, this is insecure, don't do this with untrusted guests.

In this use case, the user on the host side should trust the guest.

Btw, any attack the untrusted guests can do with the X port which host listens?

Steal the entire display, record user keystrokes, present false information.

Quoted 9 lines

OK.

Quoted 2 lines

btw, how did it work? The you need the xauth cookie for this to work, or disable authentication.

The trick here is just listening tcp x11 port(only on localhost) and forwarding the tcp x11 data to local socket.
The auth sutff should be done by the host side normal X11 setup.

Ok. Then the socat command not only exposes the display to the guest, but also to any local process with access to localhost:6000.

Signature · 1 line
error compiling committee.c: too many arguments to function
author
#7 lore raw
Quoted 29 lines · Avi Kivity
Quoted 28 lines · Asias He
Quoted 14 lines · Avi Kivity
Quoted 13 lines · Asias He
Quoted 12 lines · Avi Kivity
Quoted 10 lines · Asias He

It is useful to run a X program in guest and display it on host.

1) Make host's x server listen to localhost:6000

   host_shell$ socat -d -d TCP-LISTEN:6000,fork,bind=localhost \
               UNIX-CONNECT:/tmp/.X11-unix/X0

2) Start the guest and run X program
host_shell$ lkvm run -k /boot/bzImage
guest_shell$ xlogo

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Note, this is insecure, don't do this with untrusted guests.

In this use case, the user on the host side should trust the guest.

Btw, any attack the untrusted guests can do with the X port which host listens?

Steal the entire display, record user keystrokes, present false information.

OK.

Quoted 2 lines

btw, how did it work? The you need the xauth cookie for this to work, or disable authentication.

Quoted 7 lines
Quoted 4 lines

The trick here is just listening tcp x11 port(only on localhost) and forwarding the tcp x11 data to local socket.
The auth sutff should be done by the host side normal X11 setup.

Ok. Then the socat command not only exposes the display to the guest, but also to any local process with access to localhost:6000.

Yes. It is a trick for people with 'Xorg -nolisten tcp' enabled.

Signature · 1 line
Asias He
#8 lore raw
Quoted 4 lines · Asias He
Quoted 2 lines

Ok. Then the socat command not only exposes the display to the guest, but also to any local process with access to localhost:6000.

Yes. It is a trick for people with 'Xorg -nolisten tcp' enabled.

Which is hopefully everyone.

Signature · 1 line
error compiling committee.c: too many arguments to function
author
#9 lore raw
Quoted 7 lines · Avi Kivity
Quoted 4 lines · Asias He
Quoted 2 lines

Ok. Then the socat command not only exposes the display to the guest, but also to any local process with access to localhost:6000.

Yes. It is a trick for people with 'Xorg -nolisten tcp' enabled.

Which is hopefully everyone.

Yup. That's why I want the socat trick ;-d

Signature · 1 line
Asias He
#10 lore raw
Quoted 10 lines · Asias He
Quoted 7 lines · Avi Kivity
Quoted 4 lines · Asias He
Quoted 2 lines

Ok. Then the socat command not only exposes the display to the guest, but also to any local process with access to localhost:6000.

Yes. It is a trick for people with 'Xorg -nolisten tcp' enabled.

Which is hopefully everyone.

Yup. That's why I want the socat trick ;-d

No, it's horribly insecure.

One option is to generate a temporary keypair and use ssh. Or you can make the guest talk to an internal unix-domain socket, tunnel that through virtio-serial, terminate virtio-serial in lkvm, and direct it towards the local X socket. It's more work than exposing X11 via tcp, but if the user said -nolisten tcp, you must respect it.

Signature · 1 line
error compiling committee.c: too many arguments to function
author
#11 lore raw
Quoted 8 lines · Avi Kivity
Quoted 7 lines · Asias He
Quoted 6 lines · Avi Kivity
Quoted 4 lines · Asias He
Quoted 2 lines

Ok. Then the socat command not only exposes the display to the guest, but also to any local process with access to localhost:6000.

Yes. It is a trick for people with 'Xorg -nolisten tcp' enabled.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Which is hopefully everyone.

Yup. That's why I want the socat trick ;-d

No, it's horribly insecure.

One option is to generate a temporary keypair and use ssh.

ssh X11 forwarding need a ssh connection from host to guest. This requires a port forwarding from host to guest.
lkvm's user mode network does not support this forwarding atm.

Quoted 4 lines

Or you can
make the guest talk to an internal unix-domain socket, tunnel that through virtio-serial, terminate virtio-serial in lkvm, and direct it towards the local X socket.

Doesn't this require some user agent or config modification to the guest? Instead using a non-standard transport like virito-serial, maybe we can listen guest's x11 tcp data and forward ( may need some kind of conversion) to the local X socket.

Quoted 2 lines

It's more work than exposing X11 via tcp,
but if the user said -nolisten tcp, you must respect it.

Signature · 1 line
Asias He
#12 lore raw
Quoted 13 lines · Asias He
Quoted 12 lines · Avi Kivity
Quoted 10 lines · Asias He
Quoted 7 lines · Avi Kivity
Quoted 4 lines · Asias He
Quoted 2 lines

Ok. Then the socat command not only exposes the display to the guest, but also to any local process with access to localhost:6000.

Yes. It is a trick for people with 'Xorg -nolisten tcp' enabled.

Which is hopefully everyone.

Yup. That's why I want the socat trick ;-d

Quoted 7 lines
Quoted 3 lines

No, it's horribly insecure.

One option is to generate a temporary keypair and use ssh.

ssh X11 forwarding need a ssh connection from host to guest. This requires a port forwarding from host to guest.
lkvm's user mode network does not support this forwarding atm.

That's actually a very useful feature.

Quoted 7 lines
Quoted 5 lines

Or you can
make the guest talk to an internal unix-domain socket, tunnel that through virtio-serial, terminate virtio-serial in lkvm, and direct it towards the local X socket.

Doesn't this require some user agent or config modification to the guest?

It does, a daemon that listens locally and forwards data over virtio-serial. But you build your own initrd anyway, don't you?

Another option is ppp-over-virtio-serial.

Quoted 3 lines

Instead using a non-standard transport like virito-serial, maybe we can listen guest's x11 tcp data and forward ( may need some kind of conversion) to the local X socket.

Sure, you can terminate the connection in lkvm (in effect lkvm becomes an X server) and forward all traffic to the local unix-domain socket.

Signature · 1 line
error compiling committee.c: too many arguments to function
author
#13 lore raw
Quoted 16 lines · Avi Kivity
Quoted 15 lines · Asias He
Quoted 14 lines · Avi Kivity
Quoted 10 lines · Asias He
Quoted 7 lines · Avi Kivity
Quoted 4 lines · Asias He
Quoted 2 lines

Ok. Then the socat command not only exposes the display to the guest, but also to any local process with access to localhost:6000.

Yes. It is a trick for people with 'Xorg -nolisten tcp' enabled.

Which is hopefully everyone.

Yup. That's why I want the socat trick ;-d

No, it's horribly insecure.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

One option is to generate a temporary keypair and use ssh.

ssh X11 forwarding need a ssh connection from host to guest. This requires a port forwarding from host to guest.
lkvm's user mode network does not support this forwarding atm.

That's actually a very useful feature.

Yes, exactly.

Quoted 11 lines
Quoted 8 lines
Quoted 6 lines

Or you can
make the guest talk to an internal unix-domain socket, tunnel that through virtio-serial, terminate virtio-serial in lkvm, and direct it towards the local X socket.

Doesn't this require some user agent or config modification to the guest?

It does, a daemon that listens locally and forwards data over virtio-serial. But you build your own initrd anyway, don't you?

Using our custom init file is one use case. User may use distro disk image as guest also.

Quoted 1 line

Another option is ppp-over-virtio-serial.

Seems this still uses tcp where the link layer changes from ethernet to serial.

Quoted 6 lines
Quoted 3 lines

Instead using a non-standard transport like virito-serial, maybe we can listen guest's x11 tcp data and forward ( may need some kind of conversion) to the local X socket.

Sure, you can terminate the connection in lkvm (in effect lkvm becomes an X server) and forward all traffic to the local unix-domain socket.

Signature · 1 line
Asias He
#14 lore raw
Quoted 7 lines · Asias He
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

Or you can
make the guest talk to an internal unix-domain socket, tunnel that through virtio-serial, terminate virtio-serial in lkvm, and direct it towards the local X socket.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Doesn't this require some user agent or config modification to the guest?

It does, a daemon that listens locally and forwards data over virtio-serial. But you build your own initrd anyway, don't you?

Using our custom init file is one use case. User may use distro disk image as guest also.

We could push it into the distros, it should be useful for qemu as well.
This could be done even more properly by adding support for
virtio-serial in X itself (is anything really needed on the client side?)

The only problem is that it is insecure, but maybe
http://www.nsa.gov/research/_files/selinux/papers/x11/t1.shtml can help.
I don't know if it's integrated yet.

Quoted 4 lines
Quoted 2 lines

Another option is ppp-over-virtio-serial.

Seems this still uses tcp where the link layer changes from ethernet to serial.

Right, you have to terminate it on the host side without routing.

Signature · 1 line
error compiling committee.c: too many arguments to function