From 80dbec57d7f26e63f3c4bcea86ce79577d2d7b2d Mon Sep 17 00:00:00 2001 From: Hay Li bi <49456938+haylibi@users.noreply.github.com> Date: Wed, 2 Dec 2026 21:47:05 +0200 Subject: [PATCH] fix(preload): Steam's overlay finds the robust list in Wine games without proot (#3577) thread_robust_head() read the candidate list heads with process_vm_readv(getpid()). In Wine games run without proot, and in any process whose first thread has exited, that read fails with ESRCH, so the emulated get_robust_list answered ENOSYS and Steam's arm64 gameoverlayrenderer.so aborted the game ("futex robust_list not initialized by pthreads"). The read now goes through gettid(). --- tools/linuxfs/preload/robust.c | 2 +- tools/tests/test_robust_list_preload.py | 87 +++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 tools/tests/test_robust_list_preload.py diff --git a/tools/linuxfs/preload/robust.c b/tools/linuxfs/preload/robust.c index 12df5d662b..cfa7813844 100644 --- a/tools/linuxfs/preload/robust.c +++ b/tools/linuxfs/preload/robust.c @@ -140,7 +140,7 @@ static struct robust_list_head *thread_robust_head(void) { if ((uintptr_t)candidate & (sizeof(void *) - 1)) { continue; } - if (process_vm_readv(getpid(), &local, 1, &remote, 1, 0) != (ssize_t)sizeof(copy)) { + if (process_vm_readv(gettid(), &local, 1, &remote, 1, 0) != (ssize_t)sizeof(copy)) { continue; } uintptr_t entry = (uintptr_t)copy.list.next; diff --git a/tools/tests/test_robust_list_preload.py b/tools/tests/test_robust_list_preload.py new file mode 100644 index 0000000000..acbb899fec --- /dev/null +++ b/tools/tests/test_robust_list_preload.py @@ -0,0 +1,87 @@ +from pathlib import Path +import os +import subprocess +import tempfile +import unittest + +PRELOAD = Path(__file__).resolve().parents[1] / "linuxfs/preload" + +PROGRAM = r""" +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include + +static int ask(const char *name) { + struct robust_list_head *head = NULL; + size_t len = 0; + errno = 0; + long ret = syscall(SYS_get_robust_list, 0, &head, &len); + int ok = ret == 0 && head != NULL && len == sizeof(*head) && head->futex_offset < 0; + printf("%s %s ret=%ld errno=%d len=%zu\n", name, ok ? "ok" : "failed", ret, errno, len); + return ok; +} + +static int leader_gone(void) { + char line[256]; + FILE *status = fopen("/proc/self/status", "r"); + int zombie = 0; + while (status && fgets(line, sizeof line, status)) + if (!strncmp(line, "State:", 6)) zombie = strchr(line, 'Z') != NULL; + if (status) fclose(status); + return zombie; +} + +static void *after_leader(void *unused) { + (void)unused; + for (int i = 0; i < 200 && !leader_gone(); i++) usleep(10000); + printf("leader %s\n", leader_gone() ? "zombie" : "alive"); + exit(ask("after-leader-exit") ? 0 : 1); +} + +static void *thread(void *unused) { + (void)unused; + return (void *)(long)ask("thread"); +} + +int main(void) { + pthread_t t; + void *ok; + if (!ask("main")) return 1; + pthread_create(&t, NULL, thread, NULL); + pthread_join(t, &ok); + if (!ok) return 1; + pthread_create(&t, NULL, after_leader, NULL); + pthread_exit(NULL); +} +""" + + +class RobustListAfterLeaderExit(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.tmp = Path(tempfile.mkdtemp()) + cls.lib = cls.tmp / "librobust.so" + subprocess.run(["cc", "-O2", "-Wall", "-Werror", "-fPIC", "-shared", "-pthread", "-o", str(cls.lib), + str(PRELOAD / "robust.c"), str(PRELOAD / "fsync.c"), str(PRELOAD / "noexec.c"), + str(PRELOAD / "writewatch.c"), str(PRELOAD / "clockpause.c"), "-ldl"], check=True) + source = cls.tmp / "robust.c" + source.write_text(PROGRAM) + subprocess.run(["cc", "-O2", "-Wall", "-Werror", "-pthread", "-o", str(cls.tmp / "robust"), str(source)], + check=True) + + def test_every_thread_gets_its_list_after_the_first_thread_exits(self): + result = subprocess.run([str(self.tmp / "robust")], capture_output=True, text=True, timeout=30, + env=dict(os.environ, LD_PRELOAD=str(self.lib))) + self.assertIn("leader zombie", result.stdout) + self.assertEqual(0, result.returncode, result.stdout + result.stderr) + self.assertIn("after-leader-exit ok", result.stdout) + + +if __name__ == "__main__": + unittest.main()