Repository navigation
Conversation
platformquirks_test.cpp calls access() and uses F_OK without declaring
them. It only compiled because an included Qt header pulled in
<unistd.h> on Qt 6.9. With qt6-base 6.12 the target fails to build:
error: 'F_OK' was not declared
error: 'access' was not declared
On Linux the elevated instance is started through pkexec or sudo and then adds "si:localuser:root" to the X server's host access list, because the AppImage only ships the xcb platform plugin and root has no other way to reach the user's display. That was done by running `xhost +SI:localuser:root`, and the result of that call was never checked. xhost(1) is an optional package (xorg-xhost on Arch and derivatives, for example). Where it is missing, the elevated instance silently gets no access and aborts right after the authentication dialog with "qt.qpa.xcb: could not connect to display". Do the same X11 exchange in process instead: connect to the display as the original user, send ChangeHosts(Insert, FamilyServerInterpreted, "localuser\0root\0") and verify the entry by reading the list back. That needs nothing beyond POSIX sockets, so no runtime dependency is added. The exchange runs in the forked child as before, after dropping back to the original user. All parsing and allocation happens in the parent before fork(); the child reports what it saw through a pipe, so a failure is now logged instead of being swallowed. Remote and TCP displays are declined explicitly: host access lists only apply to local connections there. Tests drive the exchange against a fake X server on a unix socket, so they need no display. With X11HOSTACCESS_TEST_DISPLAY set, a read-only case also lists the host access list of a real X server.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On Linux, M5 Imager 3.0.0 (AppImage) aborts right after the polkit authentication when
xhost(1)is not installed: no window appears, and the elevated instance dies withSIGABRT.This replaces the
xhost +SI:localuser:rootsubprocess with the same X11 exchange done in process, so the elevated instance no longer depends on an optional package. The result is unchanged wherexhostexists.Background
What happens on a system without
xhost:pkexec <AppImage> --install-elevation-policy, then re-executes itself throughpkexecas root.PlatformQuirks::applyQuirks()callsgrantRootDisplayAccess(), which forks, drops back to the original user and runsxhost +SI:localuser:root. The result is never checked: thewaitpidstatus is ignored and a missing binary ends in_exit(127).qt.qpa.xcb: could not connect to display).xhostis an optional package (xorg-xhoston Arch and derivatives).AppRun.wrappedhas a second attempt, but guarded bycommand -v xhostand|| true, so on such systems nothing grants access and nothing says why.Observed on CachyOS with Hyprland and Xwayland,
xhostnot installed:Changes
src/linux/x11hostaccess.{h,cpp}: speaks the three pieces of the X11 protocol that are needed (connection setup,ChangeHosts,ListHosts) and sends whatxhost +SI:localuser:<user>sends:ChangeHosts(Insert, FamilyServerInterpreted, "localuser\0root\0"). It then reads the list back to confirm the entry. POSIX sockets only, no new dependency.grantRootDisplayAccess()uses it in the forked child, as before aftersetgid/setuidto the original user. All parsing and allocation happens in the parent beforefork(); the child reports through a pipe, so the outcome is logged instead of swallowed (Granted root access to X11 display :0 (...)orWARNING: could not grant root access to X11 display :0: <reason>).xhostdoes; otherwise the connection relies on the host access list.Compatibility
si:localuser:root, added by a process running as the original user.$DISPLAYnaming a remote or TCP display is declined with a log line; host access lists only apply to local connections.AppRun.wrappedstill triesxhostwhen it is present. That is now redundant but harmless, so I left the packaging alone.Testing
[x11hostaccess]cases inplatformquirks_testdrive the exchange against a fake X server on a unix socket, so they need no display: insert and read back, cookie selection, access control disabled, refusedChangeHosts, refused connection, server closing, stalling and trickling bytes,DISPLAYparsing, outcome messages.X11HOSTACCESS_TEST_DISPLAYset, a read-only case lists the host access list of a real X server. Ran against Xwayland 24.1.15.platformquirks_testpasses on qt6-base 6.12 / GCC 16 (253 assertions, 23 test cases), with and without the real display.The first commit (
test: include <unistd.h> for access()/F_OK) is an unrelated one-line fix:platformquirks_testdoes not build with Qt 6.12 without it. Happy to drop it from this PR.raspberrypi/rpi-imagerhas the samexhostcall insrc/linux/platformquirks_linux.cpp. I can open the same PR there if you would rather it went upstream first.