diff mbox series

drm/debugfs: fix potential NULL pointer dereference

Message ID 20231205130631.3456986-1-m.szyprowski@samsung.com (mailing list archive)
State New, archived
Headers show
Series drm/debugfs: fix potential NULL pointer dereference | expand

Commit Message

Marek Szyprowski Dec. 5, 2023, 1:06 p.m. UTC
encoder->funcs entry might be NULL, so check it first before calling its
methods. This fixes NULL pointer dereference observed on Rasberry Pi
3b/4b boards.

Fixes: caf525ed45b4 ("drm/encoder: register per-encoder debugfs dir")
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
---
This fixes the following issue observed on Raspberry Pi 4b:

vc4-drm gpu: bound fe400000.hvs (ops vc4_hvs_ops [vc4])
vc4-drm gpu: bound fef00700.hdmi (ops vc4_hdmi_ops [vc4])
vc4-drm gpu: bound fef05700.hdmi (ops vc4_hdmi_ops [vc4])
vc4-drm gpu: bound fe004000.txp (ops vc4_txp_ops [vc4])
vc4-drm gpu: bound fe206000.pixelvalve (ops vc4_crtc_ops [vc4])
vc4-drm gpu: bound fe207000.pixelvalve (ops vc4_crtc_ops [vc4])
vc4-drm gpu: bound fe20a000.pixelvalve (ops vc4_crtc_ops [vc4])
vc4-drm gpu: bound fe216000.pixelvalve (ops vc4_crtc_ops [vc4])
8<--- cut here ---
Unable to handle kernel NULL pointer dereference at virtual address 00000010 when read
[00000010] *pgd=00000000
Internal error: Oops: 5 [#1] SMP ARM
Modules linked in: sha256_arm raspberrypi_hwmon cfg80211(+) hci_uart btbcm bluetooth vc4(+) ecdh_generic ecc libaes snd_soc_hdmi_codec snd_soc_core v3d drm_shmem_helper ac97_bus snd_pcm_dmaengine snd_pcm genet(+) gpu_sched snd_timer snd bcm2711_thermal soundcore drm_dma_helper
CPU: 1 PID: 221 Comm: systemd-udevd Not tainted 6.7.0-rc4-next-20231205 #14267
Hardware name: BCM2711
PC is at drm_debugfs_encoder_add+0x6c/0x98
LR is at 0x0
...
 drm_debugfs_encoder_add from drm_encoder_register_all+0x20/0x60
 drm_encoder_register_all from drm_modeset_register_all+0x34/0x70
 drm_modeset_register_all from drm_dev_register+0x24c/0x28c
 drm_dev_register from vc4_drm_bind+0x21c/0x2d0 [vc4]
 vc4_drm_bind [vc4] from try_to_bring_up_aggregate_device+0x160/0x1bc
 try_to_bring_up_aggregate_device from component_master_add_with_match+0xc4/0xf8
 component_master_add_with_match from vc4_platform_drm_probe+0xa0/0xc0 [vc4]
 vc4_platform_drm_probe [vc4] from platform_probe+0x5c/0xb8
 platform_probe from really_probe+0xc8/0x2dc
 really_probe from __driver_probe_device+0x88/0x19c
 __driver_probe_device from driver_probe_device+0x30/0x104
 driver_probe_device from __driver_attach+0x90/0x174
 __driver_attach from bus_for_each_dev+0x6c/0xb4
 bus_for_each_dev from bus_add_driver+0xcc/0x1cc
 bus_add_driver from driver_register+0x7c/0x118
 driver_register from vc4_drm_register+0x44/0x1000 [vc4]
 vc4_drm_register [vc4] from do_one_initcall+0x40/0x1e0
 do_one_initcall from do_init_module+0x50/0x1e4
 do_init_module from init_module_from_file+0x90/0xbc
 init_module_from_file from sys_finit_module+0x144/0x258
 sys_finit_module from ret_fast_syscall+0x0/0x54
Exception stack(0xf0cf1fa8 to 0xf0cf1ff0)
...
---[ end trace 0000000000000000 ]---

---
 drivers/gpu/drm/drm_debugfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Dmitry Baryshkov Dec. 5, 2023, 1:19 p.m. UTC | #1
On Tue, 5 Dec 2023 at 15:06, Marek Szyprowski <m.szyprowski@samsung.com> wrote:
>
> encoder->funcs entry might be NULL, so check it first before calling its
> methods. This fixes NULL pointer dereference observed on Rasberry Pi
> 3b/4b boards.
>
> Fixes: caf525ed45b4 ("drm/encoder: register per-encoder debugfs dir")
> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>

Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>

> ---
> This fixes the following issue observed on Raspberry Pi 4b:
>
> vc4-drm gpu: bound fe400000.hvs (ops vc4_hvs_ops [vc4])
> vc4-drm gpu: bound fef00700.hdmi (ops vc4_hdmi_ops [vc4])
> vc4-drm gpu: bound fef05700.hdmi (ops vc4_hdmi_ops [vc4])
> vc4-drm gpu: bound fe004000.txp (ops vc4_txp_ops [vc4])
> vc4-drm gpu: bound fe206000.pixelvalve (ops vc4_crtc_ops [vc4])
> vc4-drm gpu: bound fe207000.pixelvalve (ops vc4_crtc_ops [vc4])
> vc4-drm gpu: bound fe20a000.pixelvalve (ops vc4_crtc_ops [vc4])
> vc4-drm gpu: bound fe216000.pixelvalve (ops vc4_crtc_ops [vc4])
> 8<--- cut here ---
> Unable to handle kernel NULL pointer dereference at virtual address 00000010 when read
> [00000010] *pgd=00000000
> Internal error: Oops: 5 [#1] SMP ARM
> Modules linked in: sha256_arm raspberrypi_hwmon cfg80211(+) hci_uart btbcm bluetooth vc4(+) ecdh_generic ecc libaes snd_soc_hdmi_codec snd_soc_core v3d drm_shmem_helper ac97_bus snd_pcm_dmaengine snd_pcm genet(+) gpu_sched snd_timer snd bcm2711_thermal soundcore drm_dma_helper
> CPU: 1 PID: 221 Comm: systemd-udevd Not tainted 6.7.0-rc4-next-20231205 #14267
> Hardware name: BCM2711
> PC is at drm_debugfs_encoder_add+0x6c/0x98
> LR is at 0x0
> ...
>  drm_debugfs_encoder_add from drm_encoder_register_all+0x20/0x60
>  drm_encoder_register_all from drm_modeset_register_all+0x34/0x70
>  drm_modeset_register_all from drm_dev_register+0x24c/0x28c
>  drm_dev_register from vc4_drm_bind+0x21c/0x2d0 [vc4]
>  vc4_drm_bind [vc4] from try_to_bring_up_aggregate_device+0x160/0x1bc
>  try_to_bring_up_aggregate_device from component_master_add_with_match+0xc4/0xf8
>  component_master_add_with_match from vc4_platform_drm_probe+0xa0/0xc0 [vc4]
>  vc4_platform_drm_probe [vc4] from platform_probe+0x5c/0xb8
>  platform_probe from really_probe+0xc8/0x2dc
>  really_probe from __driver_probe_device+0x88/0x19c
>  __driver_probe_device from driver_probe_device+0x30/0x104
>  driver_probe_device from __driver_attach+0x90/0x174
>  __driver_attach from bus_for_each_dev+0x6c/0xb4
>  bus_for_each_dev from bus_add_driver+0xcc/0x1cc
>  bus_add_driver from driver_register+0x7c/0x118
>  driver_register from vc4_drm_register+0x44/0x1000 [vc4]
>  vc4_drm_register [vc4] from do_one_initcall+0x40/0x1e0
>  do_one_initcall from do_init_module+0x50/0x1e4
>  do_init_module from init_module_from_file+0x90/0xbc
>  init_module_from_file from sys_finit_module+0x144/0x258
>  sys_finit_module from ret_fast_syscall+0x0/0x54
> Exception stack(0xf0cf1fa8 to 0xf0cf1ff0)
> ...
> ---[ end trace 0000000000000000 ]---
>
> ---
>  drivers/gpu/drm/drm_debugfs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
Nishanth Menon Dec. 6, 2023, 2:54 p.m. UTC | #2
On 15:19-20231205, Dmitry Baryshkov wrote:
> On Tue, 5 Dec 2023 at 15:06, Marek Szyprowski <m.szyprowski@samsung.com> wrote:
> >
> > encoder->funcs entry might be NULL, so check it first before calling its
> > methods. This fixes NULL pointer dereference observed on Rasberry Pi
> > 3b/4b boards.
> >
> > Fixes: caf525ed45b4 ("drm/encoder: register per-encoder debugfs dir")
> > Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
> 
> Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>

Tested-by: Nishanth Menon <nm@ti.com>

Fixed multiple platform boot fails on TI K3 SoC family including
BeaglePlay, BeagleBone-AI64.
Dmitry Baryshkov Dec. 7, 2023, 10:33 a.m. UTC | #3
On Tue, 05 Dec 2023 14:06:31 +0100, Marek Szyprowski wrote:
> encoder->funcs entry might be NULL, so check it first before calling its
> methods. This fixes NULL pointer dereference observed on Rasberry Pi
> 3b/4b boards.
> 
> 

Applied to drm-misc-next, thanks!

[1/1] drm/debugfs: fix potential NULL pointer dereference
      commit: 76385d493c2137460ee7735a5d3a494099c35188

Best regards,
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
index 02e7481758c0..f4715a67e340 100644
--- a/drivers/gpu/drm/drm_debugfs.c
+++ b/drivers/gpu/drm/drm_debugfs.c
@@ -638,7 +638,7 @@  void drm_debugfs_encoder_add(struct drm_encoder *encoder)
 	debugfs_create_file("bridges", 0444, root, encoder,
 			    &bridges_fops);
 
-	if (encoder->funcs->debugfs_init)
+	if (encoder->funcs && encoder->funcs->debugfs_init)
 		encoder->funcs->debugfs_init(encoder, root);
 }