vt: selection, close sel_buffer race
syzkaller reported this UAF: BUG: KASAN: use-after-free in n_tty_receive_buf_common+0x2481/0x2940 drivers/tty/n_tty.c:1741 Read of size 1 at addr ffff8880089e40e9 by task syz-executor.1/13184 CPU: 0 PID: 13184 Comm: syz-executor.1 Not tainted 5.4.7 #1 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-1 04/01/2014 Call Trace: ... kasan_report+0xe/0x20 mm/kasan/common.c:634 n_tty_receive_buf_common+0x2481/0x2940 drivers/tty/n_tty.c:1741 tty_ldisc_receive_buf+0xac/0x190 drivers/tty/tty_buffer.c:461 paste_selection+0x297/0x400 drivers/tty/vt/selection.c:372 tioclinux+0x20d/0x4e0 drivers/tty/vt/vt.c:3044 vt_ioctl+0x1bcf/0x28d0 drivers/tty/vt/vt_ioctl.c:364 tty_ioctl+0x525/0x15a0 drivers/tty/tty_io.c:2657 vfs_ioctl fs/ioctl.c:47 [inline] It is due to a race between parallel paste_selection (TIOCL_PASTESEL) and set_selection_user (TIOCL_SETSEL) invocations. One uses sel_buffer, while the other frees it and reallocates a new one for another selection. Add a mutex to close this race. The mutex takes care properly of sel_buffer and sel_buffer_lth only. The other selection global variables (like sel_start, sel_end, and sel_cons) are protected only in set_selection_user. The other functions need quite some more work to close the races of the variables there. This is going to happen later. This likely fixes (I am unsure as there is no reproducer provided) bug 206361 too. It was marked as CVE-2020-8648. Signed-off-by:Jiri Slaby <jslaby@suse.cz> Reported-by:
<syzbot+59997e8d5cbdc486e6f6@syzkaller.appspotmail.com> References: https://bugzilla.kernel.org/show_bug.cgi?id=206361 Cc: stable <stable@vger.kernel.org> Link: https://lore.kernel.org/r/20200210081131.23572-2-jslaby@suse.cz Signed-off-by:
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-
mentioned in commit 18c9897b
-
mentioned in commit 4ef6bca9
-
mentioned in commit 88bc4372
-
mentioned in commit 32b03155
-
mentioned in commit 964ada1f
-
mentioned in commit 4efc9317
-
mentioned in commit 23637eb9
-
mentioned in commit c87961ff
-
mentioned in commit e44f1b03
-
mentioned in commit 5ace0772
-
mentioned in commit ea474d24
-
mentioned in commit 121855e1
-
mentioned in commit ebd43352
-
mentioned in commit b5d9eb6f
-
mentioned in commit 3ae660dc
-
mentioned in commit 20d73501
-
mentioned in commit faf873a4
-
mentioned in commit e4fad84a
-
mentioned in commit 2c3be1ef
-
mentioned in commit 8a7959dd
-
mentioned in commit 4b29fb12
-
mentioned in commit 0b7b3cb5
-
mentioned in commit 301b78bb
-
mentioned in commit 784243c2
-
mentioned in commit 8a66af8a
-
mentioned in commit 546eb5b9
-
mentioned in commit 55e9560c
-
mentioned in commit 5ae56675
-
mentioned in commit fbc32342
-
mentioned in commit 66c8bfc0
-
mentioned in commit d4534456
-
mentioned in commit 7699dae9
-
mentioned in commit aaacf6bf
-
mentioned in commit 616dc606
-
mentioned in commit ee660c7a
-
mentioned in commit 80e62466