Skip to content

csm-xsmp-server.c: fix a use-after-free when an XSMP client fails during setup - #220

Open
NeiroNext wants to merge 1 commit into
linuxmint:masterfrom
NeiroNext:fix-xsmp-close-once
Open

NeiroNext wants to merge 1 commit into
linuxmint:masterfrom
NeiroNext:fix-xsmp-close-once

Conversation

@NeiroNext

Copy link
Copy Markdown

On Ubuntu Unity 26.04 (cinnamon-session 6.4.2) the session manager crashed at login, and the user was sent back to
the greeter, when a client's XSMP connection failed during setup:

#0 _IceTransClose
#1 _IceFreeConnection
#2 IceCloseConnection
#3 disconnect_ice_connection    csm-xsmp-server.c:103
#4 auth_iochannel_watch         csm-xsmp-server.c:156

ice_error_handler() closes the connection from inside IceProcessMessages(), and auth_iochannel_watch() then
closes the freed connection again. With this change the error handler only logs, as xfce4-session's does, and
each connection has one owner that closes it. This part of csm-xsmp-server.c is unchanged on master; the patch
applies and builds there.

What was observed. The crash above happened once, on its own, at the first login after a package upgrade,
in a normal session. It is a use-after-free: a connection that failed during setup was closed twice. That part
is proven.

Security impact. Reading libICE 1.1.1, the error handler is called while the connection is still in the
pending state, i.e. before the client has authenticated: IceProcessMessages() dispatches an incoming fatal
ICE_Error with no connection-status check, and IceCloseConnection() frees a pending (not-yet-accepted)
connection in place. The MIT-MAGIC-COOKIE check only runs during connection setup, which this path never
reaches, and the listening socket is a local one any local process can connect to. So a local process of
another user (or a sandboxed app that can reach the socket) can drive the session manager onto the freed
connection and end the user's session. We did not run this against a live session and did not assess whether the
use-after-free allows anything beyond a crash. The same code is in mate-session-manager.

Tested on 6.4.2 in Unity sessions: login, logout, and a client killed with SIGKILL. Each connection is closed and
freed exactly once.

The change was prepared with the help of an AI assistant; I have reviewed it.

…ils during setup

ice_error_handler() closed the connection itself on a fatal ICE error,
from inside IceProcessMessages(), while auth_iochannel_watch(), the
caller of IceProcessMessages(), closes the same connection on an IO
error. When a client connection failed during setup, the connection
was closed twice, and the session manager crashed on the freed
connection.

Leave the close to whoever owns the connection: the error handler only
logs, as xfce4-session's does. accept_xsmp_connection() no longer frees
the authentication watch while it runs inside that watch's
IceProcessMessages(); the watch frees itself afterwards and leaves the
connection to the new client. The connection's context is cleared
before it is closed, and a second client setup on a connection that
was already handed over is refused.

Assisted-by: Claude Code:claude-opus-5
NeiroNext added a commit to Ubuntu-Unity-LifeSupport/unity-distro that referenced this pull request Oct 13, 2026
…CE connection only once when a client fails during setup; upstream linuxmint/cinnamon-session#220), published 2026-10-13 12:41:10Z

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant