Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

TTY: fix atime/mtime regression

In commit b0de59b5733d ("TTY: do not update atime/mtime on read/write")
we removed timestamps from tty inodes to fix a security issue and waited
if something breaks. Well, 'w', the utility to find out logged users
and their inactivity time broke. It shows that users are inactive since
the time they logged in.

To revert to the old behaviour while still preventing attackers to
guess the password length, we update the timestamps in one-minute
intervals by this patch.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Jiri Slaby and committed by
Linus Torvalds
37b7f3c7 91d80a84

+16 -2
+16 -2
drivers/tty/tty_io.c
··· 941 941 942 942 EXPORT_SYMBOL(start_tty); 943 943 944 + static void tty_update_time(struct timespec *time) 945 + { 946 + unsigned long sec = get_seconds(); 947 + sec -= sec % 60; 948 + if ((long)(sec - time->tv_sec) > 0) 949 + time->tv_sec = sec; 950 + } 951 + 944 952 /** 945 953 * tty_read - read method for tty device files 946 954 * @file: pointer to tty file ··· 968 960 loff_t *ppos) 969 961 { 970 962 int i; 963 + struct inode *inode = file_inode(file); 971 964 struct tty_struct *tty = file_tty(file); 972 965 struct tty_ldisc *ld; 973 966 974 - if (tty_paranoia_check(tty, file_inode(file), "tty_read")) 967 + if (tty_paranoia_check(tty, inode, "tty_read")) 975 968 return -EIO; 976 969 if (!tty || (test_bit(TTY_IO_ERROR, &tty->flags))) 977 970 return -EIO; ··· 985 976 else 986 977 i = -EIO; 987 978 tty_ldisc_deref(ld); 979 + 980 + if (i > 0) 981 + tty_update_time(&inode->i_atime); 988 982 989 983 return i; 990 984 } ··· 1089 1077 break; 1090 1078 cond_resched(); 1091 1079 } 1092 - if (written) 1080 + if (written) { 1081 + tty_update_time(&file_inode(file)->i_mtime); 1093 1082 ret = written; 1083 + } 1094 1084 out: 1095 1085 tty_write_unlock(tty); 1096 1086 return ret;