CVE-2026-98839: vt: selection: Fix unsigned underflow and slab-out-of-bounds read in paste_selection()
In the Linux kernel, the following vulnerability has been resolved:
vt: selection: Fix unsigned underflow and slab-out-of-bounds read in pasteselection()
In pasteselection(), the loop copies mint(unsigned int, vcsel.buflen - pasted,tty->receiveroom) bytes per iteration into ttyldiscreceivebuf() and increments pasted += count.
Because the selection mutex (vcsel.lock) is dropped inside the loop Whenever the line discipline buffer fills up and pasteselection() sleeps on tty->writewait, a concurrent TIOCLINUX (TIOCLSETSEL) ioctl can replace vcsel.buffer with a shorter selection and reduce vcsel.buflen below pasted.
When pasteselection() resumes, vcsel.buflen - pasted underflows as an unsigned integer to a large positive value, causing ttyldiscreceivebuf(ld, vcsel.buffer + pasted, NULL, count) to read up to 4094 bytes out-of-bounds past the newly allocated vcsel.buffer.
Fix this by terminating the loop when pasted >= vcsel.buflen.
Kernel stack trace (Linux 7.3.0-rc3): ================================================================== BUG: KASAN: slab-out-of-bounds in nttyreceivebufcommon+0xa01/0x1650 Read of size 4094 at addr ffff888101c58010 by task kworker/u17:1/65 Workqueue: eventsunbound flushtoldisc Call Trace: <TASK> dumpstacklvl+0x70/0xa0 printreport+0x153/0x4c6 kasanreport+0xf1/0x120 kasancheckrange+0x11c/0x200 asanmemcpy+0x29/0x70 nttyreceivebufcommon+0xa01/0x1650 ttyldiscreceivebuf+0x66/0x110 ttyportdefaultreceivebuf+0x6b/0xb0 flushtoldisc+0x1b4/0x410 processonework+0x6ff/0x1110 workerthread+0x4a8/0xb70 kthread+0x307/0x3e0 retfromfork+0x3ed/0x680 </TASK> ==================================================================
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Compensating control
In paste_selection(), terminate the loop when pasted >= vc_sel.buf_len to prevent vc_sel.buf_len - pasted from underflowing and causing an out-of-bounds read.
Event History
Frequently Asked Questions
What conditions are required to trigger the out-of-bounds read?
A paste operation must block because the line discipline buffer is full and paste_selection() sleeps on tty->write_wait. While the selection mutex is dropped, a concurrent TIOCLINUX TIOCL_SETSEL ioctl must replace the selection buffer with a shorter one before the paste resumes.
What is the practical impact of the race?
When the paste resumes after the selection is shortened, the unsigned subtraction vc_sel.buf_len - pasted can underflow. This can cause tty_ldisc_receive_buf() to read up to 4094 bytes beyond the newly allocated selection buffer.
How can systems determine whether they have the fix?
Check whether the kernel includes the paste_selection() loop termination condition for pasted >= vc_sel.buf_len. The provided stable references identify commits containing the correction.