Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

could not connect to display :99.0 #3357

Closed
bjoern-tantau opened this issue Jan 8, 2020 · 9 comments · Fixed by #5034
Closed

could not connect to display :99.0 #3357

bjoern-tantau opened this issue Jan 8, 2020 · 9 comments · Fixed by #5034

Comments

@bjoern-tantau
Copy link

bjoern-tantau commented Jan 8, 2020

Linux distribution and version

Kubuntu 18.04

I'm running Xorg and not Wayland. On Wayland it works, but unfortunately Wayland is not stable for me.

I have this issue running both on an Nvidia card and the integrated Intel one.

Flatpak version

1.6.0

Description of the problem

I cannot run any flatpak application. I always get (Authenticator:2): Gtk-WARNING **: 14:02:31.983: cannot open display: :99.0 or similar. This does not seem to be the same issue as #1821 because running xhost + does not help.

Trying to run Authenticator, a GTK app:

bjoern@Jaina:~$ xhost +
access control disabled, clients can connect from any host
bjoern@Jaina:~$ /usr/bin/flatpak run -v --branch=stable --arch=x86_64 --command=authenticator com.github.bilelmoussaoui.Authenticator
F: No installations directory in /etc/flatpak/installations.d. Skipping
F: Opening system flatpak installation at path /var/lib/flatpak
F: Opening user flatpak installation at path /home/bjoern/.local/share/flatpak
F: Opening user flatpak installation at path /home/bjoern/.local/share/flatpak
F: Opening system flatpak installation at path /var/lib/flatpak
F: Opening user flatpak installation at path /home/bjoern/.local/share/flatpak
F: Opening system flatpak installation at path /var/lib/flatpak
F: Cleaning up unused container id 3330391466
F: Allocated instance id 1393021074
F: Add values in dir '/com/github/bilelmoussaoui/Authenticator/', prefix is '/com/github/bilelmoussaoui/Authenticator/'
F: Add defaults in dir /com/github/bilelmoussaoui/Authenticator/
F: Add locks in dir /com/github/bilelmoussaoui/Authenticator/
F: writing D-Conf values to /home/bjoern/.var/app/com.github.bilelmoussaoui.Authenticator/config/glib-2.0/settings/keyfile
F: Allowing wayland access
F: Allowing x11 access
F: Running '/usr/libexec/flatpak-bwrap --args 33 /usr/libexec/flatpak-dbus-proxy --args=35'
F: Running '/usr/libexec/flatpak-bwrap --args 32 authenticator'
Invalid MIT-MAGIC-COOKIE-1 keyUnable to init server: Could not connect: Connection refused
Invalid MIT-MAGIC-COOKIE-1 keyUnable to init server: Verbindung ist gescheitert: Connection refused
Invalid MIT-MAGIC-COOKIE-1 keyUnable to init server: Verbindung ist gescheitert: Connection refused

(Authenticator:2): Gtk-WARNING **: 14:02:31.983: cannot open display: :99.0

Trying to run Kube, a QT app:

bjoern@Jaina:~$ /usr/bin/flatpak run -v --branch=master --arch=x86_64 --command=kube com.kubeproject.kube
F: No installations directory in /etc/flatpak/installations.d. Skipping
F: Opening system flatpak installation at path /var/lib/flatpak
F: Opening user flatpak installation at path /home/bjoern/.local/share/flatpak
F: Opening user flatpak installation at path /home/bjoern/.local/share/flatpak
F: Opening user flatpak installation at path /home/bjoern/.local/share/flatpak
F: Cleaning up unused container id 1393021074
F: Allocated instance id 1073698659
F: Add defaults in dir /com/kubeproject/kube/
F: Add locks in dir /com/kubeproject/kube/
F: Allowing dri access
F: Allowing host-fs access
F: Allowing wayland access
F: Allowing x11 access
F: Running '/usr/libexec/flatpak-bwrap --args 31 /usr/libexec/flatpak-dbus-proxy --args=33'
F: Running '/usr/libexec/flatpak-bwrap --args 31 kube'
Invalid MIT-MAGIC-COOKIE-1 keyqt.qpa.xcb: could not connect to display :99.0
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: eglfs, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, xcb.

SIGABRT received
1       0x56303bf85175 kube(+0xa175) [0x56303bf85175]
2       0x7f64606095e0 /usr/lib/x86_64-linux-gnu/libc.so.6(+0x385e0) [0x7f64606095e0]
3       0x7f646060955f gsignal + 271
4       0x7f64605f3855 abort + 295
5       0x7f6460b6f8db /app/lib/libQt5Core.so.5(+0x918db) [0x7f6460b6f8db]
6       0x7f6469a4bf7b QGuiApplicationPrivate::createPlatformIntegration() + 4587
7       0x7f6469a4c41d QGuiApplicationPrivate::createEventDispatcher() + 45
8       0x7f6460d72435 QCoreApplicationPrivate::init() + 2869
9       0x7f6469a4dc2f QGuiApplicationPrivate::init() + 47
10      0x7f6468037089 QApplicationPrivate::init() + 9
11      0x56303bf85744 kube(+0xa744) [0x56303bf85744]
12      0x7f64605f53e3 __libc_start_main + 243
13      0x56303bf84a9e _start + 46
Sleeping for 10s to attach a debugger: gdb attach 2
@TingPing
Copy link
Member

TingPing commented Jan 8, 2020

Invalid MIT-MAGIC-COOKIE-1

XAuthority isn't getting picked up for some reason.

@bjoern-tantau
Copy link
Author

Removing ~/.Xauthority gives this output:

$ /usr/bin/flatpak run -v --branch=stable --arch=x86_64 --command=authenticator com.github.bilelmoussaoui.Authenticator
F: No installations directory in /etc/flatpak/installations.d. Skipping
F: Opening system flatpak installation at path /var/lib/flatpak
F: Opening user flatpak installation at path /home/bjoern/.local/share/flatpak                                                                                                                                                                                                 
F: Opening user flatpak installation at path /home/bjoern/.local/share/flatpak                                                                                                                                                                                                 
F: Opening system flatpak installation at path /var/lib/flatpak                                                                                                                                                                                                                
F: Opening user flatpak installation at path /home/bjoern/.local/share/flatpak                                                                                                                                                                                                 
F: Opening system flatpak installation at path /var/lib/flatpak                                                                                                                                                                                                                
F: Allocated instance id 3904306276                                                                                                                                                                                                                                            
F: Add values in dir '/com/github/bilelmoussaoui/Authenticator/', prefix is '/com/github/bilelmoussaoui/Authenticator/'                                                                                                                                                        
F: Add defaults in dir /com/github/bilelmoussaoui/Authenticator/                                                                                                                                                                                                               
F: Add locks in dir /com/github/bilelmoussaoui/Authenticator/                                                                                                                                                                                                                  
F: writing D-Conf values to /home/bjoern/.var/app/com.github.bilelmoussaoui.Authenticator/config/glib-2.0/settings/keyfile                                                                                                                                                     
F: Allowing wayland access                                                                                                                                                                                                                                                     
F: Allowing x11 access                                                                                                                                                                                                                                                         
F: Running '/usr/libexec/flatpak-bwrap --args 32 /usr/libexec/flatpak-dbus-proxy --args=34'                                                                                                                                                                                    
F: Running '/usr/libexec/flatpak-bwrap --args 32 authenticator'                                                                                                                                                                                                                
No protocol specified                                                                                                                                                                                                                                                          
Unable to init server: Could not connect: Connection refused                                                                                                                                                                                                                   
No protocol specified                                                                                                                                                                                                                                                          
Unable to init server: Verbindung ist gescheitert: Connection refused                                                                                                                                                                                                          
No protocol specified                                                                                                                                                                                                                                                          
Unable to init server: Verbindung ist gescheitert: Connection refused                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                               
(Authenticator:2): Gtk-WARNING **: 15:04:15.131: cannot open display: :99.0                  

@alexlarsson
Copy link
Member

Typically flatpak accessess the host display by bind-mounting in the unix domain socket for the xserver, which is generally /tmp/.X11-unix/X0. It also uses libxauth to try to import the magic cookie, but generally this is not needed as modern xserver use getpeercreds to do authentication.

Is the X socket still there? Sometimes it happens that it gets cleaned up by tmp cleaners, but other x apps keep working because there is also an abstract socket you can use (but not in a network namespace, so doesn't work for flatpak).

@bjoern-tantau
Copy link
Author

I think I found the culprit. For some reason (I'm still trying to figure it out) I had Xvfb running and taking up display :99.0. After killing it I have no problems starting up the flatpak application.

So I guess we can change the ticket to stop flatpaks from refusing to work when Xvfb is running. The command Xvfb was running with was

Xvfb :99 -screen 0 640x480x16 -nolisten tcp -auth /tmp/xvfb-run.fH3v3c/Xauthority

@smcv
Copy link
Collaborator

smcv commented Jan 23, 2020

It also uses libxauth to try to import the magic cookie, but generally this is not needed as modern xserver use getpeercreds to do authentication

[citation needed], unfortunately. gdm does the equivalent of xhost +si:localuser:$(id -nu), and so do most (all?) display managers on Debian, but at least Plasma Desktop (sddm) on Manjaro relies on MIT magic cookie (XAUTHORITY) authentication, and does not use si:localuser.

I discovered this when I made a Flatpak-like container environment unshare the UTS namespace and set a custom hostname, which I thought would be a nice way to tell at a glance which environment you're in. It worked fine on Debian + GNOME, but broke Manjaro + Plasma Desktop, because the magic cookie records in the XAUTHORITY file include a hostname, and the container and X server disagreed on which hostname they were looking for.

@smcv
Copy link
Collaborator

smcv commented Jan 23, 2020

For some reason (I'm still trying to figure it out) I had Xvfb running and taking up display :99.0.

I believe X servers on Linux normally listen on both the filesystem-based socket /tmp/.X11-unix/X99 and the abstract socket @/tmp/.X11-unix/X99. Abstract sockets are shared across a sandbox boundary (unless you unshare the network namespace, which Flatpak can't do, because most applications want Internet access), so the application inside the sandbox was probably connecting to Xvfb's abstract socket outside the sandbox.

Abstract sockets seemed like a great idea in the 1990s - they're sockets, but you don't have to delete them from the filesystem when you've finished with them! - but they interoperate really badly with containers. D-Bus is gradually moving away from abstract sockets, and ideally X11 would too.

So I guess we can change the ticket to stop flatpaks from refusing to work when Xvfb is running

More specifically, "when Xvfb is running and is using display :99". If your Xvfb was :1 or :98 then it would probably work fine.

I'm not sure how Flatpak would achieve that. The only way I can think of would be to choose a display number and create a pair of (path-based, abstract) sockets on the host system just like Xvfb does (to see whether Xvfb is using it, and if not, claim it so that Xvfb cannot use it)... but then the application in the container would try to connect to the abstract socket on the host system, and we'd have to have a proxy to connect to the real X server and pass data backwards and forwards?

If X displays have some sort of locking mechanism, then we could maybe claim a display number with that locking mechanism, but not actually create an abstract socket for it?

Or perhaps just pick a very large number and hope nobody else uses it? (gdm does that: its "greeter" (login prompt) is on :1024.)

@smcv
Copy link
Collaborator

smcv commented Aug 8, 2022

Another possible way to deal with this would be to use the same display number as on the host system, instead of 99. For instance, suppose your real display is :42. Then we'd get this behaviour:

  • if there's an abstract socket @/tmp/.X11-unix/X42, then apps with --share=network would bypass Flatpak's X11 mediation and connect to that;
  • or if that abstract socket doesn't exist, or the app doesn't have --share=network, then it'll connect to /tmp/.X11-unix/X42 inside the container, which is just a bind-mount of the real /tmp/.X11-unix/X42 outside the container

@alexlarsson, do you remember a reason why that approach couldn't be used?

The only problem I can immediately see with this is that if, at some point in future, we wanted to put a proxy (like xdg-dbus-proxy) between the app and the real X server, then apps with --share=network would bypass the proxy by using the abstract socket. But they can do that anyway if they want to (even if they have to brute-force the real display number by just trying them all), so trying to use an X11 proxy for security would just be security theatre and not something we can actually rely on anyway.

I think the long-term solution is for X11 on Linux to stop listening on abstract sockets, or possibly for X11 to disappear completely in favour of Wayland; but X11 has several decades of backwards-compat to consider, so that isn't going to happen any time soon.

@yshui
Copy link

yshui commented Aug 8, 2022

this can also be solved (mitigated) by runtime provides by removing abstract socket support from libxcb.

need to remove this line here:

https://gitlab.freedesktop.org/xorg/lib/libxcb/-/blob/master/configure.ac#L148

@TingPing
Copy link
Member

TingPing commented Aug 9, 2022

@yshui If you believe that should be done open an issue here describing in a bit of detail: https://gitlab.com/freedesktop-sdk/freedesktop-sdk

smcv added a commit to smcv/flatpak that referenced this issue Aug 9, 2022
Suppose the user's "real" X11 display on the host is Xorg or Xwayland
listening on :42, but they also have an Xvfb server listening on :99.

If we change the X11 display number to the arbitrary value :99, and
the Flatpak sandbox shares its network namespace with the host, then
clients inside the Flatpak sandbox will prefer to connect to the
abstract socket @/tmp/.X11-unix/X99 (which is Xvfb), rather than the
filesystem-backed socket /tmp/.X11-unix/X99 in the sandbox (which is
really /tmp/.X11-unix/X42 on the host, i.e. Xorg or Xwayland).

If they're relying on Xauthority (MIT-MAGIC-COOKIE-1) for access
control (as many display managers do), then this will fail, because
we gave the sandboxed app access to the cookies for Xorg/Xwayland
(rewriting their display number from 42 to 99 as we did so), but
Xvfb does not accept those cookies.

If we're relying on `xhost +"si:localuser:$(id -nu)"` for access control
(as gdm does), then the Flatpak app will successfully (!) connect to
whatever is on :99, for example Xvfb or Xephyr, which is rarely what
anyone wants either.

Resolves: flatpak#3357
Signed-off-by: Simon McVittie <smcv@collabora.com>
alexlarsson pushed a commit that referenced this issue Aug 16, 2022
Suppose the user's "real" X11 display on the host is Xorg or Xwayland
listening on :42, but they also have an Xvfb server listening on :99.

If we change the X11 display number to the arbitrary value :99, and
the Flatpak sandbox shares its network namespace with the host, then
clients inside the Flatpak sandbox will prefer to connect to the
abstract socket @/tmp/.X11-unix/X99 (which is Xvfb), rather than the
filesystem-backed socket /tmp/.X11-unix/X99 in the sandbox (which is
really /tmp/.X11-unix/X42 on the host, i.e. Xorg or Xwayland).

If they're relying on Xauthority (MIT-MAGIC-COOKIE-1) for access
control (as many display managers do), then this will fail, because
we gave the sandboxed app access to the cookies for Xorg/Xwayland
(rewriting their display number from 42 to 99 as we did so), but
Xvfb does not accept those cookies.

If we're relying on `xhost +"si:localuser:$(id -nu)"` for access control
(as gdm does), then the Flatpak app will successfully (!) connect to
whatever is on :99, for example Xvfb or Xephyr, which is rarely what
anyone wants either.

Resolves: #3357
Signed-off-by: Simon McVittie <smcv@collabora.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants