fbcon: fix null-ptr-deref in fbcon_switch
Subsystems (3)
PATCH 1/1 fbcon: fix null-ptr-deref in fbcon_switch
Add check for vc_cons[logo_shown].d, as it can be released by vt_ioctl(VT_DISALLOCATE).
--- drivers/video/fbdev/core/fbcon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/video/fbdev/core/fbcon.c +2 -2
@@ -2254,7 +2254,7 @@ static int fbcon_switch(struct vc_data *vc)fbcon_update_softback (vc); } -if (logo_shown >=0 ) { +if (logo_shown >=0 &&vc_cons_allocated (logo_shown)) {struct vc_data *conp2 = vc_cons[logo_shown].d; if (conp2->vc_top = logo_lines
@@ -2852,7 +2852,7 @@ static void fbcon_scrolldelta(struct vc_data *vc, int lines)return ;if (vc->vc_mode !=KD_TEXT || !lines)return ; -if (logo_shown >=0 ) { +if (logo_shown >=0 &&vc_cons_allocated (logo_shown)) {struct vc_data *conp2 = vc_cons[logo_shown].d; if (conp2->vc_top = logo_lines
Signature · 1 line
2.17.1
Quoted 2 lines · Qiujun Huang
Add check for vc_cons[logo_shown].d, as it can be released by
vt_ioctl(VT_DISALLOCATE).
Can you pls link to the syzbot report and distill the essence of the crash/issue here in the commit message? As-is a bit unclear what's going on. Patch itself looks correct.
Thanks, Daniel
Quoted 29 lines
Reported-by [email protected]Signed-off-by Qiujun Huang <[email protected]>--- drivers/video/fbdev/core/fbcon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/video/fbdev/core/fbcon.c +2
-3@@ -2254,7 +2254,7 @@ static int fbcon_switch(struct vc_data *vc)fbcon_update_softback (vc); } -if (logo_shown >=0 ) { +if (logo_shown >=0 &&vc_cons_allocated (logo_shown)) {struct vc_data *conp2 = vc_cons[logo_shown].d; if (conp2->vc_top = logo_lines@@ -2852,7 +2852,7 @@ static void fbcon_scrolldelta(struct vc_data *vc, int lines)return ;if (vc->vc_mode !=KD_TEXT || !lines)return ; - if (logo_shown >= 0) { +if (logo_shown >=0 &&vc_cons_allocated (logo_shown)) {struct vc_data *conp2 = vc_cons[logo_shown].d; if (conp2->vc_top = logo_lines --
Quoted 2 lines
2.17.1
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
Quoted 8 lines · Daniel Vetter
Quoted 2 lines · Qiujun Huang
Add check for vc_cons[logo_shown].d, as it can be released by
vt_ioctl(VT_DISALLOCATE).Can you pls link to the syzbot report and distill the essence of the crash/issue here in the commit message? As-is a bit unclear what's going on. Patch itself looks correct.
https://lkml.org/lkml/2020/3/27/403
Thanks.
Quoted 40 lines
Thanks, Daniel
Quoted 29 lines
Reported-by [email protected]Signed-off-by Qiujun Huang <[email protected]>--- drivers/video/fbdev/core/fbcon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/video/fbdev/core/fbcon.c +2
-3@@ -2254,7 +2254,7 @@ static int fbcon_switch(struct vc_data *vc)fbcon_update_softback (vc); } -if (logo_shown >=0 ) { +if (logo_shown >=0 &&vc_cons_allocated (logo_shown)) {struct vc_data *conp2 = vc_cons[logo_shown].d; if (conp2->vc_top = logo_lines@@ -2852,7 +2852,7 @@ static void fbcon_scrolldelta(struct vc_data *vc, int lines)return ;if (vc->vc_mode !=KD_TEXT || !lines)return ; - if (logo_shown >= 0) { +if (logo_shown >=0 &&vc_cons_allocated (logo_shown)) {struct vc_data *conp2 = vc_cons[logo_shown].d; if (conp2->vc_top = logo_lines --Quoted 2 lines
2.17.1
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
Hi Qiujun
Thanks for looking into the sysbot bugs.
Quoted 23 lines · Qiujun Huang
Add check for vc_cons[logo_shown].d, as it can be released by
vt_ioctl(VT_DISALLOCATE).Reported-by [email protected]Signed-off-by Qiujun Huang <[email protected]>--- drivers/video/fbdev/core/fbcon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/video/fbdev/core/fbcon.c +1
-1@@ -2254,7 +2254,7 @@ static int fbcon_switch(struct vc_data *vc)fbcon_update_softback (vc); } -if (logo_shown >=0 ) { +if (logo_shown >=0 &&vc_cons_allocated (logo_shown)) {struct vc_data *conp2 = vc_cons[logo_shown].d; if (conp2->vc_top = logo_lines
drivers/video/fbdev/core/fbcon.c static void fbcon_scrolldelta(struct vc_data *vc, int lines) · line 2858
Quoted 8 lines
drivers/video/fbdev/core/fbcon.c +1
-1@@ -2852,7 +2852,7 @@ static void fbcon_scrolldelta(struct vc_data *vc, int lines)return ;if (vc->vc_mode !=KD_TEXT || !lines)return ; -if (logo_shown >=0 ) { +if (logo_shown >=0 &&vc_cons_allocated (logo_shown)) {struct vc_data *conp2 = vc_cons[logo_shown].d; if (conp2->vc_top = logo_lines
I am not familiar with this code.
But it looks like you try to avoid the sympton which is that logo_shown has a wrong value after a vc is deallocated, and do not fix the root cause.
We have:
vt_ioctl(VT_DISALLOCATE)
|
+- vc_deallocate()
|
+- visual_deinit()
|
+- vc->vc_sw->con_deinit(vc)
|
+- fbcon_deinit()Would it be better to update logo_shown
in fbcon_deinit()?
Then we will not try to do anything with
the logo in fbcon_switch().
fbcon_deinit() is called with console locked
so there should not be any races.
I did not stare long enough on the code to come up with a patch, but this may be a better way to fix it.
Sam
Quoted 56 lines · Sam Ravnborg
Hi Qiujun
Thanks for looking into the sysbot bugs.
Quoted 23 lines · Qiujun Huang
Add check for vc_cons[logo_shown].d, as it can be released by
vt_ioctl(VT_DISALLOCATE).Reported-by [email protected]Signed-off-by Qiujun Huang <[email protected]>--- drivers/video/fbdev/core/fbcon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/video/fbdev/core/fbcon.c +1
-1@@ -2254,7 +2254,7 @@ static int fbcon_switch(struct vc_data *vc)fbcon_update_softback (vc); } -if (logo_shown >=0 ) { +if (logo_shown >=0 &&vc_cons_allocated (logo_shown)) {struct vc_data *conp2 = vc_cons[logo_shown].d; if (conp2->vc_top = logo_linesdrivers/video/fbdev/core/fbcon.c static void fbcon_scrolldelta(struct vc_data *vc, int lines) · line 2858
Quoted 8 lines
drivers/video/fbdev/core/fbcon.c +1
-1@@ -2852,7 +2852,7 @@ static void fbcon_scrolldelta(struct vc_data *vc, int lines)return ;if (vc->vc_mode !=KD_TEXT || !lines)return ; -if (logo_shown >=0 ) { +if (logo_shown >=0 &&vc_cons_allocated (logo_shown)) {struct vc_data *conp2 = vc_cons[logo_shown].d; if (conp2->vc_top = logo_linesI am not familiar with this code.
But it looks like you try to avoid the sympton which is that
logo_shownhas a wrong value after a vc is deallocated, and do not fix the root cause.We have:
vt_ioctl(VT_DISALLOCATE)
|+- vc_deallocate() | +- visual_deinit() | +- vc->vc_sw->con_deinit(vc) | +- fbcon_deinit()
Quoted 7 lines
Would it be better to update
logo_shown
infbcon_deinit()?
Then we will not try to do anything with
the logo infbcon_switch().
fbcon_deinit()is called with console locked
so there should not be any races.
Get that, thanks.
Quoted 5 lines
I did not stare long enough on the code to come up with a patch, but this may be a better way to fix it.
Sam