]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
terminal-util: reset access mode in vt_restore(), too
authorLennart Poettering <lennart@poettering.net>
Tue, 30 Apr 2019 17:26:14 +0000 (19:26 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 24 May 2019 13:07:55 +0000 (15:07 +0200)
Only changing ownership back to root is not enough we also need to
change the access mode, otherwise the user might have set 666 first, and
thus allow everyone access before and after the chown().

src/basic/terminal-util.c
src/basic/terminal-util.h
src/core/execute.c

index 71238ac9c43579079f9182be18f62f1e97c47513..3a0d16a74f59dcf09d9c4f3e434bf555fb04239f 100644 (file)
@@ -1291,8 +1291,7 @@ int vt_restore(int fd) {
         };
         int r, q = 0;
 
-        r = ioctl(fd, KDSETMODE, KD_TEXT);
-        if (r < 0)
+        if (ioctl(fd, KDSETMODE, KD_TEXT) < 0)
                 q = log_debug_errno(errno, "Failed to set VT in text mode, ignoring: %m");
 
         r = vt_reset_keyboard(fd);
@@ -1302,18 +1301,17 @@ int vt_restore(int fd) {
                         q = r;
         }
 
-        r = ioctl(fd, VT_SETMODE, &mode);
-        if (r < 0) {
+        if (ioctl(fd, VT_SETMODE, &mode) < 0) {
                 log_debug_errno(errno, "Failed to set VT_AUTO mode, ignoring: %m");
                 if (q >= 0)
                         q = -errno;
         }
 
-        r = fchown(fd, 0, (gid_t) -1);
+        r = fchmod_and_chown(fd, TTY_MODE, 0, (gid_t) -1);
         if (r < 0) {
-                log_debug_errno(errno, "Failed to chown VT, ignoring: %m");
+                log_debug_errno(r, "Failed to chmod()/chown() VT, ignoring: %m");
                 if (q >= 0)
-                        q = -errno;
+                        q = r;
         }
 
         return q;
index 90adc14d176fcf2ec805e96a7661da59a28e9e40..87d09f87598a1dc53f7f49223a8d2d2f96fb55e0 100644 (file)
@@ -163,3 +163,6 @@ int vt_restore(int fd);
 int vt_release(int fd, bool restore_vt);
 
 void get_log_colors(int priority, const char **on, const char **off, const char **highlight);
+
+/* This assumes there is a 'tty' group */
+#define TTY_MODE 0620
index ab2a4de37a515ae2e70f317674f674ea2ecc05e9..640efac295d03afbce225c5b455d3dc58c7eded2 100644 (file)
@@ -97,9 +97,6 @@
 #define IDLE_TIMEOUT_USEC (5*USEC_PER_SEC)
 #define IDLE_TIMEOUT2_USEC (1*USEC_PER_SEC)
 
-/* This assumes there is a 'tty' group */
-#define TTY_MODE 0620
-
 #define SNDBUF_SIZE (8*1024*1024)
 
 static int shift_fds(int fds[], size_t n_fds) {