terminal-util: reset access mode in vt_restore(), too

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().
This commit is contained in:
Lennart Poettering 2019-04-30 19:26:14 +02:00
parent 4b3b5bc71b
commit 1802d5f2cf
3 changed files with 8 additions and 10 deletions

View 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;

View 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

View 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) {