From 53c5d0e55aeac4ee948e47f7de82c2d6c4dcbe10 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sat, 27 Dec 2025 12:12:18 +0100 Subject: [PATCH] Always reset ownership and permissions on TTY device nodes During /bin/login phase the TTY device node is chowned and chmodded to the authenticated user. It will remain in this state until the next call to getty. Signed-off-by: Joachim Wiberg --- src/exec.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/exec.c b/src/exec.c index efed8e52..9bb19b59 100644 --- a/src/exec.c +++ b/src/exec.c @@ -286,6 +286,12 @@ static void prepare_tty(char *tty, speed_t speed, const char *procname, struct r char name[80]; int fd, dummy; + /* Set proper protections and ownership */ + if (chown(tty, 0, 0)) + logit(LOG_ERR, "failed chowning 0:0 %s: %s", tty, strerror(errno)); + if (chmod(tty, 0620)) + logit(LOG_ERR, "failed chmoding 620 %s: %s", tty, strerror(errno)); + fd = open(tty, O_RDWR); if (fd < 0) { logit(LOG_ERR, "Failed opening %s: %s", tty, strerror(errno));