gsm_util_export_user_environment does not filter environment variables containing carriage return characters (CR or \r)
gnome-session version this issue has been seen with
gnome-session-3.38.0-1.fc33.x86_64
Used distribution
Fedora 33
Expected behaviour you didn't see
Working gnome session upon logging in from gdm
Unexpected behaviour you saw
After gdm login, a black screen with a stationary mouse pointer.
Steps to reproduce the problem
-
Put something like the following lines into
/etc/profile.d/trigger-the-bug.sh
or some test user's~/.bashrc
exporting environment variables which contain\r
characters. E.g. (using vi's way of displaying the carriage return character as^M
)CR="^M" export CR CRLF="^M " export CRLF
-
(For help with debugging, but not necessary to reproduce the issue:) As the test user in a virtual console, launch
busctl monitor --user > busctl-monitor--user.log
. -
From gdm, log in as that user into a "Gnome" or "Gnome on Xorg" session.
-
Screen goes black, mouse pointer stops moving, and nothing happens any more.
As @bberg has diagnosed on my system, the following now happens:
-
gdm
starts a login shell, which will pick up the environment variables containing\r
characters -
that login shell starts the
gnome-session
script -
the
gnome-session
script startsgnome-session-binary
-
gnome-session-binary
uploads the environment to the D-Bus bus nameorg.freedesktop.systemd1
usingUnsetAndSetEnvironment
, containing information essential for launching the Gnome session -
systemd detects
\r
characters somewhere in the new environment and therefore rejects the whole environment update, including those environment variables with essential information -
now the
gnome-session-binary
process asks systemd to launchgnome-session-binary --systemd-service --session=gnome
, which uses the environment which should have but does not have the environment variables with essential information -
gnome-session-binary --systemd-service --session=gnome
is now missing essential environment variables likeXDG_SESSION_TYPE
, so the/usr/lib/systemd/user/org.gnome.Shell@wayland.service
and/usr/lib/systemd/user/org.gnome.Shell@x11.service
checks forXDG_SESSION_TYPE
being equal to%I
fail -
No service has been launched, nothing is done further, the screen stays black. The End.
If gnome-session-binary
were to filter out more weird environment variables such as those containing \r
, systemd would never see them and therefore not reject the environment update with the environment variables essential to starting a Gnome session.