[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <182d36d5-df77-2479-882a-5bb588c5f170@kernel.org>
Date: Tue, 3 Jan 2023 10:24:28 +0100
From: Jiri Slaby <jirislaby@...nel.org>
To: Hang Zhang <zh.nvgt@...il.com>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>,
Daniel Vetter <daniel.vetter@...ll.ch>,
Yangxi Xiang <xyangxi5@...il.com>,
Xuezhi Zhang <zhangxuezhi1@...lpad.com>,
Helge Deller <deller@....de>,
Tetsuo Handa <penguin-kernel@...ove.SAKURA.ne.jp>,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] tty: vt: add some NULL checks for vc_data
On 29. 12. 22, 7:41, Hang Zhang wrote:
> vc_selection(), do_blank_screen() and scrollfront() all access "vc_data"
> structures obtained from the global "vc_cons[fg_console].d", which can
> be freed and nullified (e.g., in the error path of vc_allocate()). But
> these functions don't have any NULL checks against the pointers before
> dereferencing them, causing potentially use-after-free or null pointer
> dereference.
Could you elaborate under what circumstances is fg_console set to a
non-allocated console?
> Prevent these potential issues by placing NULL checks in these functions
> before accessing "vc_data" structures. Similar checks can be found in
> other functions like vt_console_print() and poke_blanked_console().
>
> Signed-off-by: Hang Zhang <zh.nvgt@...il.com>
> ---
> drivers/tty/vt/selection.c | 3 +++
> drivers/tty/vt/vt.c | 5 +++++
> 2 files changed, 8 insertions(+)
>
> diff --git a/drivers/tty/vt/selection.c b/drivers/tty/vt/selection.c
> index 6ef22f01cc51..c727fd947683 100644
> --- a/drivers/tty/vt/selection.c
> +++ b/drivers/tty/vt/selection.c
> @@ -319,6 +319,9 @@ static int vc_selection(struct vc_data *vc, struct tiocl_selection *v,
> {
> int ps, pe;
>
> + if (!vc)
> + return 0;
> +
> poke_blanked_console();
>
> if (v->sel_mode == TIOCL_SELCLEAR) {
> diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
> index 981d2bfcf9a5..00f8fdc61e9f 100644
> --- a/drivers/tty/vt/vt.c
> +++ b/drivers/tty/vt/vt.c
> @@ -1493,6 +1493,8 @@ void scrollback(struct vc_data *vc)
>
> void scrollfront(struct vc_data *vc, int lines)
> {
> + if (!vc)
> + return;
> if (!lines)
> lines = vc->vc_rows / 2;
> scrolldelta(lines);
> @@ -4346,6 +4348,9 @@ void do_blank_screen(int entering_gfx)
> struct vc_data *vc = vc_cons[fg_console].d;
> int i;
>
> + if (!vc)
> + return;
> +
> might_sleep();
>
> WARN_CONSOLE_UNLOCKED();
thanks,
--
js
suse labs
Powered by blists - more mailing lists