* [PATCH] vt: defer kfree() of vc_screenbuf in vc_do_resize()
@ 2020-07-29 14:57 Tetsuo Handa
2020-08-04 11:15 ` Tetsuo Handa
0 siblings, 1 reply; 5+ messages in thread
From: Tetsuo Handa @ 2020-07-29 14:57 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby, Daniel Vetter
Cc: linux-fbdev, Bartlomiej Zolnierkiewicz, Tetsuo Handa,
linux-kernel, dri-devel, syzbot
syzbot is reporting UAF bug in set_origin() from vc_do_resize() [1], for
vc_do_resize() calls kfree(vc->vc_screenbuf) before calling set_origin().
Unfortunately, in set_origin(), vc->vc_sw->con_set_origin() might access
vc->vc_pos when scroll is involved in order to manipulate cursor, but
vc->vc_pos refers already released vc->vc_screenbuf until vc->vc_pos gets
updated based on the result of vc->vc_sw->con_set_origin().
Preserving old buffer and tolerating outdated vc members until set_origin()
completes would be easier than preventing vc->vc_sw->con_set_origin() from
accessing outdated vc members.
[1] https://syzkaller.appspot.com/bug?id=6649da2081e2ebdc65c0642c214b27fe91099db3
Reported-by: syzbot <syzbot+9116ecc1978ca3a12f43@syzkaller.appspotmail.com>
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
---
drivers/tty/vt/vt.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index 42d8c67..c9ee8e9 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -1196,7 +1196,7 @@ static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc,
unsigned int old_rows, old_row_size, first_copied_row;
unsigned int new_cols, new_rows, new_row_size, new_screen_size;
unsigned int user;
- unsigned short *newscreen;
+ unsigned short *oldscreen, *newscreen;
struct uni_screen *new_uniscr = NULL;
WARN_CONSOLE_UNLOCKED();
@@ -1294,10 +1294,11 @@ static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc,
if (new_scr_end > new_origin)
scr_memsetw((void *)new_origin, vc->vc_video_erase_char,
new_scr_end - new_origin);
- kfree(vc->vc_screenbuf);
+ oldscreen = vc->vc_screenbuf;
vc->vc_screenbuf = newscreen;
vc->vc_screenbuf_size = new_screen_size;
set_origin(vc);
+ kfree(oldscreen);
/* do part of a reset_terminal() */
vc->vc_top = 0;
--
1.8.3.1
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] vt: defer kfree() of vc_screenbuf in vc_do_resize()
2020-07-29 14:57 [PATCH] vt: defer kfree() of vc_screenbuf in vc_do_resize() Tetsuo Handa
@ 2020-08-04 11:15 ` Tetsuo Handa
2020-08-04 12:58 ` Greg Kroah-Hartman
0 siblings, 1 reply; 5+ messages in thread
From: Tetsuo Handa @ 2020-08-04 11:15 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby, Daniel Vetter, Bartlomiej Zolnierkiewicz
Cc: syzbot, linux-fbdev, linux-kernel, dri-devel
Do you think this approach is acceptable? Or, do we need to modify set_origin() ?
On 2020/07/29 23:57, Tetsuo Handa wrote:
> syzbot is reporting UAF bug in set_origin() from vc_do_resize() [1], for
> vc_do_resize() calls kfree(vc->vc_screenbuf) before calling set_origin().
>
> Unfortunately, in set_origin(), vc->vc_sw->con_set_origin() might access
> vc->vc_pos when scroll is involved in order to manipulate cursor, but
> vc->vc_pos refers already released vc->vc_screenbuf until vc->vc_pos gets
> updated based on the result of vc->vc_sw->con_set_origin().
>
> Preserving old buffer and tolerating outdated vc members until set_origin()
> completes would be easier than preventing vc->vc_sw->con_set_origin() from
> accessing outdated vc members.
>
> [1] https://syzkaller.appspot.com/bug?id=6649da2081e2ebdc65c0642c214b27fe91099db3
>
> Reported-by: syzbot <syzbot+9116ecc1978ca3a12f43@syzkaller.appspotmail.com>
> Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
> ---
> drivers/tty/vt/vt.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
> index 42d8c67..c9ee8e9 100644
> --- a/drivers/tty/vt/vt.c
> +++ b/drivers/tty/vt/vt.c
> @@ -1196,7 +1196,7 @@ static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc,
> unsigned int old_rows, old_row_size, first_copied_row;
> unsigned int new_cols, new_rows, new_row_size, new_screen_size;
> unsigned int user;
> - unsigned short *newscreen;
> + unsigned short *oldscreen, *newscreen;
> struct uni_screen *new_uniscr = NULL;
>
> WARN_CONSOLE_UNLOCKED();
> @@ -1294,10 +1294,11 @@ static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc,
> if (new_scr_end > new_origin)
> scr_memsetw((void *)new_origin, vc->vc_video_erase_char,
> new_scr_end - new_origin);
> - kfree(vc->vc_screenbuf);
> + oldscreen = vc->vc_screenbuf;
> vc->vc_screenbuf = newscreen;
> vc->vc_screenbuf_size = new_screen_size;
> set_origin(vc);
> + kfree(oldscreen);
>
> /* do part of a reset_terminal() */
> vc->vc_top = 0;
>
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] vt: defer kfree() of vc_screenbuf in vc_do_resize()
2020-08-04 11:15 ` Tetsuo Handa
@ 2020-08-04 12:58 ` Greg Kroah-Hartman
2020-08-11 15:02 ` Tetsuo Handa
0 siblings, 1 reply; 5+ messages in thread
From: Greg Kroah-Hartman @ 2020-08-04 12:58 UTC (permalink / raw)
To: Tetsuo Handa
Cc: linux-fbdev, Bartlomiej Zolnierkiewicz, Daniel Vetter,
linux-kernel, dri-devel, syzbot, Jiri Slaby
On Tue, Aug 04, 2020 at 08:15:43PM +0900, Tetsuo Handa wrote:
> Do you think this approach is acceptable? Or, do we need to modify set_origin() ?
>
> On 2020/07/29 23:57, Tetsuo Handa wrote:
> > syzbot is reporting UAF bug in set_origin() from vc_do_resize() [1], for
> > vc_do_resize() calls kfree(vc->vc_screenbuf) before calling set_origin().
> >
> > Unfortunately, in set_origin(), vc->vc_sw->con_set_origin() might access
> > vc->vc_pos when scroll is involved in order to manipulate cursor, but
> > vc->vc_pos refers already released vc->vc_screenbuf until vc->vc_pos gets
> > updated based on the result of vc->vc_sw->con_set_origin().
> >
> > Preserving old buffer and tolerating outdated vc members until set_origin()
> > completes would be easier than preventing vc->vc_sw->con_set_origin() from
> > accessing outdated vc members.
> >
> > [1] https://syzkaller.appspot.com/bug?id=6649da2081e2ebdc65c0642c214b27fe91099db3
> >
> > Reported-by: syzbot <syzbot+9116ecc1978ca3a12f43@syzkaller.appspotmail.com>
> > Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
> > ---
> > drivers/tty/vt/vt.c | 5 +++--
> > 1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
> > index 42d8c67..c9ee8e9 100644
> > --- a/drivers/tty/vt/vt.c
> > +++ b/drivers/tty/vt/vt.c
> > @@ -1196,7 +1196,7 @@ static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc,
> > unsigned int old_rows, old_row_size, first_copied_row;
> > unsigned int new_cols, new_rows, new_row_size, new_screen_size;
> > unsigned int user;
> > - unsigned short *newscreen;
> > + unsigned short *oldscreen, *newscreen;
> > struct uni_screen *new_uniscr = NULL;
> >
> > WARN_CONSOLE_UNLOCKED();
> > @@ -1294,10 +1294,11 @@ static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc,
> > if (new_scr_end > new_origin)
> > scr_memsetw((void *)new_origin, vc->vc_video_erase_char,
> > new_scr_end - new_origin);
> > - kfree(vc->vc_screenbuf);
> > + oldscreen = vc->vc_screenbuf;
> > vc->vc_screenbuf = newscreen;
> > vc->vc_screenbuf_size = new_screen_size;
> > set_origin(vc);
> > + kfree(oldscreen);
> >
> > /* do part of a reset_terminal() */
> > vc->vc_top = 0;
I think what you have here is fine, as cleaning up set_orgin() might be
hard to do at this point in time.
thanks,
greg k-h
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] vt: defer kfree() of vc_screenbuf in vc_do_resize()
2020-08-04 12:58 ` Greg Kroah-Hartman
@ 2020-08-11 15:02 ` Tetsuo Handa
2020-08-11 15:10 ` Greg Kroah-Hartman
0 siblings, 1 reply; 5+ messages in thread
From: Tetsuo Handa @ 2020-08-11 15:02 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: linux-fbdev, Bartlomiej Zolnierkiewicz, Daniel Vetter,
linux-kernel, dri-devel, syzbot, Jiri Slaby
On 2020/08/04 21:58, Greg Kroah-Hartman wrote:
> On Tue, Aug 04, 2020 at 08:15:43PM +0900, Tetsuo Handa wrote:
>> Do you think this approach is acceptable? Or, do we need to modify set_origin() ?
>>
> I think what you have here is fine, as cleaning up set_orgin() might be
> hard to do at this point in time.
>
Seems that there is no comment. Greg, will you pick up this patch?
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] vt: defer kfree() of vc_screenbuf in vc_do_resize()
2020-08-11 15:02 ` Tetsuo Handa
@ 2020-08-11 15:10 ` Greg Kroah-Hartman
0 siblings, 0 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2020-08-11 15:10 UTC (permalink / raw)
To: Tetsuo Handa
Cc: linux-fbdev, Bartlomiej Zolnierkiewicz, Daniel Vetter,
linux-kernel, dri-devel, syzbot, Jiri Slaby
On Wed, Aug 12, 2020 at 12:02:03AM +0900, Tetsuo Handa wrote:
> On 2020/08/04 21:58, Greg Kroah-Hartman wrote:
> > On Tue, Aug 04, 2020 at 08:15:43PM +0900, Tetsuo Handa wrote:
> >> Do you think this approach is acceptable? Or, do we need to modify set_origin() ?
> >>
> > I think what you have here is fine, as cleaning up set_orgin() might be
> > hard to do at this point in time.
> >
>
> Seems that there is no comment. Greg, will you pick up this patch?
Yes, will do after -rc1 is out.
thanks,
greg k-h
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-08-12 7:05 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-29 14:57 [PATCH] vt: defer kfree() of vc_screenbuf in vc_do_resize() Tetsuo Handa
2020-08-04 11:15 ` Tetsuo Handa
2020-08-04 12:58 ` Greg Kroah-Hartman
2020-08-11 15:02 ` Tetsuo Handa
2020-08-11 15:10 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).