Fix CVE-2024-40966 for openEuler-22.03-LTS-SP1
Linus Torvalds (1): tty: add the option to have a tty reject a new ldisc
Yi Yang (1): tty: vt device use only n_tty ldisc
drivers/tty/tty_ldisc.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
From: Linus Torvalds torvalds@linux-foundation.org
mainline inclusion from mainline-v6.10-rc1 commit 6bd23e0c2bb6c65d4f5754d1456bc9a4427fc59b category: bugfix bugzilla: https://gitee.com/src-openeuler/kernel/issues/IACT4T CVE: CVE-2024-40966
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i...
--------------------------------
... and use it to limit the virtual terminals to just N_TTY. They are kind of special, and in particular, the "con_write()" routine violates the "writes cannot sleep" rule that some ldiscs rely on.
This avoids the
BUG: sleeping function called from invalid context at kernel/printk/printk.c:2659
when N_GSM has been attached to a virtual console, and gsmld_write() calls con_write() while holding a spinlock, and con_write() then tries to get the console lock.
Tested-by: Tetsuo Handa penguin-kernel@i-love.sakura.ne.jp Cc: Jiri Slaby jirislaby@kernel.org Cc: Andrew Morton akpm@linux-foundation.org Cc: Daniel Starke daniel.starke@siemens.com Reported-by: syzbot syzbot+dbac96d8e73b61aa559c@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=dbac96d8e73b61aa559c Signed-off-by: Linus Torvalds torvalds@linux-foundation.org Link: https://lore.kernel.org/r/20240423163339.59780-1-torvalds@linux-foundation.o... Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org Conflicts: include/linux/tty_driver.h [Not merge commit 1fe183091753 ("tty: add kernel-doc for tty_operations"),and context conflicts] Signed-off-by: Yi Yang yiyang13@huawei.com --- drivers/tty/tty_ldisc.c | 6 ++++++ drivers/tty/vt/vt.c | 10 ++++++++++ include/linux/tty_driver.h | 1 + 3 files changed, 17 insertions(+)
diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c index fe37ec331289..afdce732d144 100644 --- a/drivers/tty/tty_ldisc.c +++ b/drivers/tty/tty_ldisc.c @@ -578,6 +578,12 @@ int tty_set_ldisc(struct tty_struct *tty, int disc) goto out; }
+ if (tty->ops->ldisc_ok) { + retval = tty->ops->ldisc_ok(tty, disc); + if (retval) + goto out; + } + old_ldisc = tty->ldisc;
/* Shutdown the old discipline. */ diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c index 33fb7b6555f4..34f3f752f0b2 100644 --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c @@ -3448,6 +3448,15 @@ static void con_cleanup(struct tty_struct *tty) tty_port_put(&vc->port); }
+/* + * We can't deal with anything but the N_TTY ldisc, + * because we can sleep in our write() routine. + */ +static int con_ldisc_ok(struct tty_struct *tty, int ldisc) +{ + return ldisc == N_TTY ? 0 : -EINVAL; +} + static int default_color = 7; /* white */ static int default_italic_color = 2; // green (ASCII) static int default_underline_color = 3; // cyan (ASCII) @@ -3576,6 +3585,7 @@ static const struct tty_operations con_ops = { .resize = vt_resize, .shutdown = con_shutdown, .cleanup = con_cleanup, + .ldisc_ok = con_ldisc_ok, };
static struct cdev vc0_cdev; diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h index 2f719b471d52..3d200e18f4fa 100644 --- a/include/linux/tty_driver.h +++ b/include/linux/tty_driver.h @@ -270,6 +270,7 @@ struct tty_operations { void (*hangup)(struct tty_struct *tty); int (*break_ctl)(struct tty_struct *tty, int state); void (*flush_buffer)(struct tty_struct *tty); + int (*ldisc_ok)(struct tty_struct *tty, int ldisc); void (*set_ldisc)(struct tty_struct *tty); void (*wait_until_sent)(struct tty_struct *tty, int timeout); void (*send_xchar)(struct tty_struct *tty, char ch);
hulk inclusion category: bugfix bugzilla: https://gitee.com/src-openeuler/kernel/issues/IACT4T CVE: CVE-2024-40966
--------------------------------
After backport mainline commit 6bd23e0c2bb6 ("tty: add the option to have a tty reject a new ldisc") Introduced kabi breakage. Fix kabi breakage by check whether it is vt device in tty_set_ldisc(), and check ldisc whether it is N_TTY.
Fixes: 8c3d894dca0a("[Backport] tty: add the option to have a tty reject a new ldisc") Signed-off-by: Yi Yang yiyang13@huawei.com --- drivers/tty/tty_ldisc.c | 10 +++++++--- drivers/tty/vt/vt.c | 10 ---------- include/linux/tty_driver.h | 1 - 3 files changed, 7 insertions(+), 14 deletions(-)
diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c index afdce732d144..43413040ec34 100644 --- a/drivers/tty/tty_ldisc.c +++ b/drivers/tty/tty_ldisc.c @@ -578,11 +578,15 @@ int tty_set_ldisc(struct tty_struct *tty, int disc) goto out; }
- if (tty->ops->ldisc_ok) { - retval = tty->ops->ldisc_ok(tty, disc); - if (retval) +#ifdef CONFIG_VT + /*vt device use only n_tty ldisc*/ + if (tty->ops->ioctl == vt_ioctl) { + if (disc != N_TTY) { + retval = -EINVAL; goto out; + } } +#endif
old_ldisc = tty->ldisc;
diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c index 34f3f752f0b2..33fb7b6555f4 100644 --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c @@ -3448,15 +3448,6 @@ static void con_cleanup(struct tty_struct *tty) tty_port_put(&vc->port); }
-/* - * We can't deal with anything but the N_TTY ldisc, - * because we can sleep in our write() routine. - */ -static int con_ldisc_ok(struct tty_struct *tty, int ldisc) -{ - return ldisc == N_TTY ? 0 : -EINVAL; -} - static int default_color = 7; /* white */ static int default_italic_color = 2; // green (ASCII) static int default_underline_color = 3; // cyan (ASCII) @@ -3585,7 +3576,6 @@ static const struct tty_operations con_ops = { .resize = vt_resize, .shutdown = con_shutdown, .cleanup = con_cleanup, - .ldisc_ok = con_ldisc_ok, };
static struct cdev vc0_cdev; diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h index 3d200e18f4fa..2f719b471d52 100644 --- a/include/linux/tty_driver.h +++ b/include/linux/tty_driver.h @@ -270,7 +270,6 @@ struct tty_operations { void (*hangup)(struct tty_struct *tty); int (*break_ctl)(struct tty_struct *tty, int state); void (*flush_buffer)(struct tty_struct *tty); - int (*ldisc_ok)(struct tty_struct *tty, int ldisc); void (*set_ldisc)(struct tty_struct *tty); void (*wait_until_sent)(struct tty_struct *tty, int timeout); void (*send_xchar)(struct tty_struct *tty, char ch);
反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://gitee.com/openeuler/kernel/pulls/10909 邮件列表地址:https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/Z...
FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://gitee.com/openeuler/kernel/pulls/10909 Mailing list address: https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/Z...