#995596 xorg-server: /dev/dri/card0 fd leak switching VTs, leads to lockup

Package:
src:xorg-server
Source:
xorg-server
Submitter:
Spiky Caterpillar
Date:
2021-10-02 21:18:03 UTC
Severity:
normal
Tags:
#995596#5
Date:
2021-10-02 21:14:53 UTC
From:
To:
Dear Maintainer,

The X server repeatedly opens /dev/dri/card0 on VT switch, but doesn't
close it. Eventually this leads to FD exhaustion and a wedged X server.

To replicate:
Login on a console
startx
start an xterm
lsof -n|grep -c /dev/dri/card0
control-alt-functionkey to change to another vt
control-alt-functionkey to change back to X
lsof -n|grep -c /dev/dri/card0


The patch I'm using at the moment:

### BEGIN PATCH ###
diff --git a/hw/xfree86/os-support/linux/systemd-logind.c b/hw/xfree86/os-support/linux/systemd-logind.c
index 13784d1..9f196ef 100644
--- a/hw/xfree86/os-support/linux/systemd-logind.c
+++ b/hw/xfree86/os-support/linux/systemd-logind.c
@@ -417,9 +417,10 @@ message_filter(DBusConnection * connection, DBusMessage * message, void *data)
         /* info->vt_active gets set by systemd_logind_vtenter() */
         info->active = TRUE;

-        if (pdev)
+        if (pdev) {
+            close(fd);
             pdev->flags &= ~XF86_PDEV_PAUSED;
-        else
+        } else
             systemd_logind_set_input_fd_for_all_devs(major, minor, fd,
                                                      info->vt_active);
### END PATCH ###

I do not know if the bug applies to the latest upstream version of X,
though the patch does apply.