Skip to contentSkip to conversation

video: fbdev: fbmem: fix pointer reference to null device field

PATCH In review Zhouyi Zhou 3 participants 3 messages Feb 10, 2022 – Feb 11, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 video: fbdev: fbmem: fix pointer reference to null device field

In function do_remove_conflicting_framebuffers, if device is NULL, there will be null pointer reference. The patch add a check to the if expression.

---
Dear Linux folks

I discover this bug in the PowerPC VM provided by
Open source lab of Oregon State University:

https://lkml.org/lkml/2022/2/8/1145

I found that the root cause of null device field is in offb_init_fb:
info = framebuffer_alloc(sizeof(u32) * 16, NULL);

I have tested the patch in the PowerPC VM. Hope my patch can be correct.

Many Thanks
Zhouyi
--

 drivers/video/fbdev/core/fbmem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/video/fbdev/core/fbmem.c +1 -1
index 34d6bb1bf82e..422b1fc01722 100644
@@ -1579,7 +1579,7 @@ static void do_remove_conflicting_framebuffers(struct apertures_struct *a,
 			 * If it's not a platform device, at least print a warning. A
 			 * fix would add code to remove the device from the system.
 			 */
-			if (dev_is_platform(device)) {
+			if (device && dev_is_platform(device)) {
 				registered_fb[i]->forced_out = true;
 				platform_device_unregister(to_platform_device(device));
 			} else {
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 10 lines · Zhouyi Zhou

In function do_remove_conflicting_framebuffers, if device is NULL, there will be null pointer reference. The patch add a check to the if expression.

---
Dear Linux folks

I discover this bug in the PowerPC VM provided by
Open source lab of Oregon State University:

Quoted 6 lines

https://lkml.org/lkml/2022/2/8/1145

I found that the root cause of null device field is in offb_init_fb:
info = framebuffer_alloc(sizeof(u32) * 16, NULL);

I have tested the patch in the PowerPC VM. Hope my patch can be correct.

This looks plausible to me, but I am quite unfamiliar with this code.

Thanx, Paul

Quoted 22 lines

Many Thanks
Zhouyi
--

 drivers/video/fbdev/core/fbmem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/video/fbdev/core/fbmem.c +1 -1
index 34d6bb1bf82e..422b1fc01722 100644
@@ -1579,7 +1579,7 @@ static void do_remove_conflicting_framebuffers(struct apertures_struct *a,
 			 * If it's not a platform device, at least print a warning. A
 			 * fix would add code to remove the device from the system.
 			 */
-			if (dev_is_platform(device)) {
+			if (device && dev_is_platform(device)) {
 				registered_fb[i]->forced_out = true;
 				platform_device_unregister(to_platform_device(device));
 			} else {
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#2 lore raw
In reply to Zhouyi Zhou

Dear Zhouyi,

Am 10.02.22 um 07:58 schrieb Zhouyi Zhou:

Quoted 28 lines

In function do_remove_conflicting_framebuffers, if device is NULL, there will be null pointer reference. The patch add a check to the if expression.

---
Dear Linux folks

I discover this bug in the PowerPC VM provided by
Open source lab of Oregon State University:

https://lkml.org/lkml/2022/2/8/1145

I found that the root cause of null device field is in offb_init_fb:
info = framebuffer_alloc(sizeof(u32) * 16, NULL);

I have tested the patch in the PowerPC VM. Hope my patch can be correct.

Many Thanks
Zhouyi
--

  drivers/video/fbdev/core/fbmem.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/video/fbdev/core/fbmem.c +0 -0
index 34d6bb1bf82e..422b1fc01722 100644

drivers/video/fbdev/core/fbmem.c static void do_remove_conflicting_framebuffers(struct apertures_struct *a, · line 1585

Quoted 8 lines
drivers/video/fbdev/core/fbmem.c +1 -1
@@ -1579,7 +1579,7 @@ static void do_remove_conflicting_framebuffers(struct apertures_struct *a,
  			 * If it's not a platform device, at least print a warning. A
  			 * fix would add code to remove the device from the system.
  			 */
-			if (dev_is_platform(device)) {
+			if (device && dev_is_platform(device)) {
  				registered_fb[i]->forced_out = true;
  				platform_device_unregister(to_platform_device(device));
  			} else {

Looks reasonable.

Kind regards,

Paul

PS: Please note, this should be unrelated to my problem though, as I didn’t use linux-next. (Let’s continue in the other thread though.)