]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commit
vt: keyboard, extend func_buf_lock to readers
authorJiri Slaby <jslaby@suse.cz>
Mon, 19 Oct 2020 08:55:17 +0000 (10:55 +0200)
committerStefan Bader <stefan.bader@canonical.com>
Thu, 10 Dec 2020 11:03:14 +0000 (12:03 +0100)
commit169bcbfe511e9d1036fd9a774c779a4f11930caa
tree74cfa69bffde3a7b94f43f70e5e256f576de1918
parent9028f6b013d3ce96dbb6fab75d5ab5a28b1f4283
vt: keyboard, extend func_buf_lock to readers

BugLink: https://bugs.launchpad.net/bugs/1904450
commit 82e61c3909db51d91b9d3e2071557b6435018b80 upstream.

Both read-side users of func_table/func_buf need locking. Without that,
one can easily confuse the code by repeatedly setting altering strings
like:
while (1)
for (a = 0; a < 2; a++) {
struct kbsentry kbs = {};
strcpy((char *)kbs.kb_string, a ? ".\n" : "88888\n");
ioctl(fd, KDSKBSENT, &kbs);
}

When that program runs, one can get unexpected output by holding F1
(note the unxpected period on the last line):
.
88888
.8888

So protect all accesses to 'func_table' (and func_buf) by preexisting
'func_buf_lock'.

It is easy in 'k_fn' handler as 'puts_queue' is expected not to sleep.
On the other hand, KDGKBSENT needs a local (atomic) copy of the string
because copy_to_user can sleep. Use already allocated, but unused
'kbs->kb_string' for that purpose.

Note that the program above needs at least CAP_SYS_TTY_CONFIG.

This depends on the previous patch and on the func_buf_lock lock added
in commit 46ca3f735f34 (tty/vt: fix write/write race in ioctl(KDSKBSENT)
handler) in 5.2.

Likely fixes CVE-2020-25656.

Cc: <stable@vger.kernel.org>
Reported-by: Minh Yuan <yuanmingbuaa@gmail.com>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20201019085517.10176-2-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: William Breathitt Gray <william.gray@canonical.com>
drivers/tty/vt/keyboard.c