tty: vt: selection: fix soft lockup in paste_selection()
PATCH v2 1/1 tty: vt: selection: fix soft lockup in paste_selection()
Soft lockup occurs when vt device used n_null ldisc, n_null_receivebuf() is not implemented in null_ldisc. So tty_ldisc_receive_buf always return 0 in paste_selection(), this cause deadloop and cause soft lockup.
This can be reproduced as follows:
int ldisc = 0x1b; // 0x1b is n_null struct{
char subcode;
struct tiocl_selection sel;
} data;
date.subcode = TIOCL_SETSEL;
data.sel.xs = 0;
data.sel.xe = 1;
data.sel.ys = 0;
data.sel.ye = 1;
data.sel.sel_mode = TIOCL_SELCHAR;
char bytes[2] = {TIOCL_PASTESEL, 0}; open("ttyxx", O_RDWR) // open a vt device ioctl(fd, TIOCSETD, &ldisc) // set ldisc to n_null ioctl(fd, TIOCLINUX, &data.subcode); ioctl(fd, TIOCLINUX, bytes); // cause deadloop
Fix soft lockup by check receive_buf() and receive_buf2() is NULL.
---
v2:Change Check Condition.
drivers/tty/vt/selection.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/tty/vt/selection.c +6 -0
@@ -397,6 +397,12 @@ int paste_selection(struct tty_struct *tty) ld =tty_ldisc_ref_wait (tty);if (!ld)return -EIO ;/* ldisc was hung up */ + +/*tty_ldisc_receive_buf() won't do anything and cause deadloop later*/ +if (!ld->ops->receive_buf && !ld->ops->receive_buf2) { +tty_ldisc_deref (ld); +return -EIO ; + }tty_buffer_lock_exclusive (&vc->port);add_wait_queue (&vc->paste_wait, &wait);
Signature · 1 line
2.25.1
Greg KH
maintainerQuoted 3 lines · Yi Yang
Soft lockup occurs when vt device used
n_nullldisc,n_null_receivebuf()is not implemented innull_ldisc. Sotty_ldisc_receive_bufalways return 0 inpaste_selection(), this cause deadloop and cause soft lockup.
Why is a vt using n_null?
What is causing that?
Quoted 19 lines
This can be reproduced as follows:
int ldisc =0x1b; //0x1bisn_nullstruct{
char subcode;
structtiocl_selectionsel;
} data;
date.subcode =TIOCL_SETSEL;
data.sel.xs = 0;
data.sel.xe = 1;
data.sel.ys = 0;
data.sel.ye = 1;
data.sel.sel_mode =TIOCL_SELCHAR;
char bytes[2] = {TIOCL_PASTESEL, 0};open("ttyxx", O_RDWR)// open a vt deviceioctl(fd, TIOCSETD, &ldisc)// set ldisc ton_nullioctl(fd, TIOCLINUX, &data.subcode);ioctl(fd, TIOCLINUX, bytes); // cause deadloop
Quoted 1 line
Fix soft lockup by check
receive_buf()andreceive_buf2()is NULL.
As you had permissions to do this, why prevent it?
Quoted 14 lines
Signed-off-by Yi Yang <[email protected]>---
v2:Change Check Condition.
drivers/tty/vt/selection.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/tty/vt/selection.c +0
-0
drivers/tty/vt/selection.c int paste_selection(struct tty_struct *tty) · line 401
Quoted 5 lines
drivers/tty/vt/selection.c +2
-0@@ -397,6 +397,12 @@ int paste_selection(struct tty_struct *tty) ld =tty_ldisc_ref_wait (tty);if (!ld)return -EIO ;/* ldisc was hung up */ + +/*tty_ldisc_receive_buf() won't do anything and cause deadloop later*/
Comments need to be properly formated.
And I do not understand this comment sorry.
drivers/tty/vt/selection.c int paste_selection(struct tty_struct *tty) · line 402
Quoted 1 line
drivers/tty/vt/selection.c +1
-0+if (!ld->ops->receive_buf && !ld->ops->receive_buf2) {
Why check reciev_buf pointers here? What is that causing?
This needs to be documented a lot better please.
thanks,
greg k-h