[PATCH] um: time-travel: don't use uninitialized fds from START ACK

From: Brad Fitzpatrick via B4 Relay

Date: Mon Nov 16 2026 - 18:43:18 EST


From: Brad Fitzpatrick <bradfitz@xxxxxxxxxxxxx>

When the kernel connects to an external time-travel controller, it
expects the ACK of its UM_TIMETRAVEL_START message to carry two file
descriptors: the shared memory area and a log file. It reads them with
os_rcv_fd_msg() into an uninitialized on-stack array, and then uses
both array elements whenever the message itself was received in full.

os_rcv_fd_msg() leaves the array untouched if the message came without
an SCM_RIGHTS control message. That is what any controller that does
not implement the shared memory extension sends, which the protocol
allows: such controllers are why the kernel falls back to message
based scheduling. In that case the kernel passes stack garbage to
mmap() and then close()s both values.

With CONFIG_INIT_STACK_ALL_ZERO, the default where the compiler
supports it, the garbage is 0, so the kernel closes its own stdin. The
next file descriptor it opens, the epoll instance used for IRQs, then
becomes fd 0:

$ ls -l /proc/$(pidof linux)/fd
0 -> anon_inode:[eventpoll]
1 -> /tmp/uml.log
2 -> /tmp/uml.log
3 -> /dev/shm/#200843
4 -> socket:[216518625]

Without stack initialization the kernel may instead close, or map as
the scheduling area, any file descriptor at all.

Initialize the array to -1 and only use the descriptors that were
actually received. With the fix, fd 0 stays what it was and the epoll
instance gets the next free number.

Fixes: bfb80d8bc92f ("um: add shared memory optimisation for time-travel=ext")
Signed-off-by: Brad Fitzpatrick <bradfitz@xxxxxxxxxxxxx>
---
arch/um/kernel/time.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/arch/um/kernel/time.c b/arch/um/kernel/time.c
index d620b6d6310a5..bcb141b419722 100644
--- a/arch/um/kernel/time.c
+++ b/arch/um/kernel/time.c
@@ -141,15 +141,23 @@ static void time_travel_handle_message(struct um_timetravel_msg *msg,
}

if (unlikely(mode == TTMH_READ_START_ACK)) {
- int fd[UM_TIMETRAVEL_SHARED_MAX_FDS];
+ int fd[UM_TIMETRAVEL_SHARED_MAX_FDS] = {
+ [0 ... UM_TIMETRAVEL_SHARED_MAX_FDS - 1] = -1,
+ };

ret = os_rcv_fd_msg(time_travel_ext_fd, fd,
ARRAY_SIZE(fd), msg, sizeof(*msg));
if (ret == sizeof(*msg)) {
- time_travel_setup_shm(fd[UM_TIMETRAVEL_SHARED_MEMFD],
- msg->time & UM_TIMETRAVEL_START_ACK_ID);
+ /*
+ * A controller without shared memory support
+ * sends no file descriptors with its ACK.
+ */
+ if (fd[UM_TIMETRAVEL_SHARED_MEMFD] >= 0)
+ time_travel_setup_shm(fd[UM_TIMETRAVEL_SHARED_MEMFD],
+ msg->time & UM_TIMETRAVEL_START_ACK_ID);
/* we don't use the logging for now */
- os_close_file(fd[UM_TIMETRAVEL_SHARED_LOGFD]);
+ if (fd[UM_TIMETRAVEL_SHARED_LOGFD] >= 0)
+ os_close_file(fd[UM_TIMETRAVEL_SHARED_LOGFD]);
}
} else {
ret = os_read_file(time_travel_ext_fd, msg, sizeof(*msg));

---
base-commit: 7ea2308ccebce754fd1ac6295f26983a6878045d
change-id: 20261116-bradfitz-um-tt-start-ack-fds-b860a789850d

Best regards,
--
Brad Fitzpatrick <bradfitz@xxxxxxxxxxxxx>