mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] drm/connector: hdmi: Handle NULL display mode in state check helper
@ 2025-01-07  0:00 Cristian Ciocaltea
  2025-01-07  9:35 ` Dmitry Baryshkov
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Cristian Ciocaltea @ 2025-01-07  0:00 UTC (permalink / raw)
  To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Simona Vetter, Dave Stevenson, Dmitry Baryshkov
  Cc: kernel, dri-devel, linux-kernel

drm_atomic_helper_connector_hdmi_check() helper makes use of
connector_state_get_mode() to obtain a drm_display_mode pointer, but it
doesn't validate it, which may lead to a NULL pointer dereference in
some cases, i.e. unloading a DRM module:

[ 1002.910414] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000
[...]
[ 1002.923833] Hardware name: Radxa ROCK 5B (DT)
[ 1002.924819] pc : drm_match_cea_mode+0x30/0x280 [drm]
[ 1002.925318] lr : hdmi_try_format_bpc+0x7c/0x580 [drm_display_helper]
[...]
[ 1002.932411] Call trace:
[ 1002.932626]  drm_match_cea_mode+0x30/0x280 [drm] (P)
[ 1002.933120]  hdmi_try_format_bpc+0x7c/0x580 [drm_display_helper]
[ 1002.933662]  drm_atomic_helper_connector_hdmi_check+0x10c/0x478 [drm_display_helper]
[ 1002.934355]  drm_bridge_connector_atomic_check+0x20/0x40 [drm_display_helper]
[ 1002.934993]  drm_atomic_helper_check_modeset+0x698/0xd28 [drm_kms_helper]
[ 1002.935607]  drm_atomic_helper_check+0x28/0xb8 [drm_kms_helper]
[ 1002.936143]  drm_atomic_check_only+0x794/0x988 [drm]
[ 1002.936635]  drm_atomic_commit+0x60/0xe0 [drm]
[ 1002.937082]  drm_atomic_helper_disable_all+0x184/0x218 [drm_kms_helper]
[ 1002.937678]  drm_atomic_helper_shutdown+0x90/0x150 [drm_kms_helper]
[ 1002.938243]  rockchip_drm_unbind+0x38/0x80 [rockchipdrm]
[ 1002.938720]  component_master_del+0xac/0xf8
[ 1002.939089]  rockchip_drm_platform_remove+0x34/0x78 [rockchipdrm]
[...]

Add the missing NULL check before passing the mode pointer further.

Fixes: f035f4097f1e ("drm/connector: hdmi: Calculate TMDS character rate")
Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
---
 drivers/gpu/drm/display/drm_hdmi_state_helper.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/display/drm_hdmi_state_helper.c b/drivers/gpu/drm/display/drm_hdmi_state_helper.c
index cfc2aaee1da08a103cbf933c891d5cc31b0886a8..e4d4fce6ab59d37067327d3e6da235c9a5a45b42 100644
--- a/drivers/gpu/drm/display/drm_hdmi_state_helper.c
+++ b/drivers/gpu/drm/display/drm_hdmi_state_helper.c
@@ -503,6 +503,9 @@ int drm_atomic_helper_connector_hdmi_check(struct drm_connector *connector,
 		connector_state_get_mode(new_conn_state);
 	int ret;
 
+	if (!mode)
+		return 0;
+
 	new_conn_state->hdmi.is_limited_range = hdmi_is_limited_range(connector, new_conn_state);
 
 	ret = hdmi_compute_config(connector, new_conn_state, mode);

---
base-commit: 938fbb16aba8f7b88e0fdcf56f315a5bbad41aad
change-id: 20250107-hdmi-conn-null-mode-be0c5e49ed8c


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] drm/connector: hdmi: Handle NULL display mode in state check helper
  2025-01-07  0:00 [PATCH] drm/connector: hdmi: Handle NULL display mode in state check helper Cristian Ciocaltea
@ 2025-01-07  9:35 ` Dmitry Baryshkov
  2025-01-07 12:59 ` AngeloGioacchino Del Regno
  2025-01-07 15:16 ` Maxime Ripard
  2 siblings, 0 replies; 5+ messages in thread
From: Dmitry Baryshkov @ 2025-01-07  9:35 UTC (permalink / raw)
  To: Cristian Ciocaltea
  Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Simona Vetter, Dave Stevenson, kernel, dri-devel,
	linux-kernel

On Tue, Jan 07, 2025 at 02:00:35AM +0200, Cristian Ciocaltea wrote:
> drm_atomic_helper_connector_hdmi_check() helper makes use of
> connector_state_get_mode() to obtain a drm_display_mode pointer, but it
> doesn't validate it, which may lead to a NULL pointer dereference in
> some cases, i.e. unloading a DRM module:
> 
> [ 1002.910414] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000
> [...]
> [ 1002.923833] Hardware name: Radxa ROCK 5B (DT)
> [ 1002.924819] pc : drm_match_cea_mode+0x30/0x280 [drm]
> [ 1002.925318] lr : hdmi_try_format_bpc+0x7c/0x580 [drm_display_helper]
> [...]
> [ 1002.932411] Call trace:
> [ 1002.932626]  drm_match_cea_mode+0x30/0x280 [drm] (P)
> [ 1002.933120]  hdmi_try_format_bpc+0x7c/0x580 [drm_display_helper]
> [ 1002.933662]  drm_atomic_helper_connector_hdmi_check+0x10c/0x478 [drm_display_helper]
> [ 1002.934355]  drm_bridge_connector_atomic_check+0x20/0x40 [drm_display_helper]
> [ 1002.934993]  drm_atomic_helper_check_modeset+0x698/0xd28 [drm_kms_helper]
> [ 1002.935607]  drm_atomic_helper_check+0x28/0xb8 [drm_kms_helper]
> [ 1002.936143]  drm_atomic_check_only+0x794/0x988 [drm]
> [ 1002.936635]  drm_atomic_commit+0x60/0xe0 [drm]
> [ 1002.937082]  drm_atomic_helper_disable_all+0x184/0x218 [drm_kms_helper]
> [ 1002.937678]  drm_atomic_helper_shutdown+0x90/0x150 [drm_kms_helper]
> [ 1002.938243]  rockchip_drm_unbind+0x38/0x80 [rockchipdrm]
> [ 1002.938720]  component_master_del+0xac/0xf8
> [ 1002.939089]  rockchip_drm_platform_remove+0x34/0x78 [rockchipdrm]
> [...]
> 
> Add the missing NULL check before passing the mode pointer further.
> 
> Fixes: f035f4097f1e ("drm/connector: hdmi: Calculate TMDS character rate")
> Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
> ---
>  drivers/gpu/drm/display/drm_hdmi_state_helper.c | 3 +++
>  1 file changed, 3 insertions(+)
> 

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

-- 
With best wishes
Dmitry

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] drm/connector: hdmi: Handle NULL display mode in state check helper
  2025-01-07  0:00 [PATCH] drm/connector: hdmi: Handle NULL display mode in state check helper Cristian Ciocaltea
  2025-01-07  9:35 ` Dmitry Baryshkov
@ 2025-01-07 12:59 ` AngeloGioacchino Del Regno
  2025-01-07 15:16 ` Maxime Ripard
  2 siblings, 0 replies; 5+ messages in thread
From: AngeloGioacchino Del Regno @ 2025-01-07 12:59 UTC (permalink / raw)
  To: Cristian Ciocaltea, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, Dave Stevenson,
	Dmitry Baryshkov
  Cc: kernel, dri-devel, linux-kernel

Il 07/01/25 01:00, Cristian Ciocaltea ha scritto:
> drm_atomic_helper_connector_hdmi_check() helper makes use of
> connector_state_get_mode() to obtain a drm_display_mode pointer, but it
> doesn't validate it, which may lead to a NULL pointer dereference in
> some cases, i.e. unloading a DRM module:
> 
> [ 1002.910414] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000
> [...]
> [ 1002.923833] Hardware name: Radxa ROCK 5B (DT)
> [ 1002.924819] pc : drm_match_cea_mode+0x30/0x280 [drm]
> [ 1002.925318] lr : hdmi_try_format_bpc+0x7c/0x580 [drm_display_helper]
> [...]
> [ 1002.932411] Call trace:
> [ 1002.932626]  drm_match_cea_mode+0x30/0x280 [drm] (P)
> [ 1002.933120]  hdmi_try_format_bpc+0x7c/0x580 [drm_display_helper]
> [ 1002.933662]  drm_atomic_helper_connector_hdmi_check+0x10c/0x478 [drm_display_helper]
> [ 1002.934355]  drm_bridge_connector_atomic_check+0x20/0x40 [drm_display_helper]
> [ 1002.934993]  drm_atomic_helper_check_modeset+0x698/0xd28 [drm_kms_helper]
> [ 1002.935607]  drm_atomic_helper_check+0x28/0xb8 [drm_kms_helper]
> [ 1002.936143]  drm_atomic_check_only+0x794/0x988 [drm]
> [ 1002.936635]  drm_atomic_commit+0x60/0xe0 [drm]
> [ 1002.937082]  drm_atomic_helper_disable_all+0x184/0x218 [drm_kms_helper]
> [ 1002.937678]  drm_atomic_helper_shutdown+0x90/0x150 [drm_kms_helper]
> [ 1002.938243]  rockchip_drm_unbind+0x38/0x80 [rockchipdrm]
> [ 1002.938720]  component_master_del+0xac/0xf8
> [ 1002.939089]  rockchip_drm_platform_remove+0x34/0x78 [rockchipdrm]
> [...]
> 
> Add the missing NULL check before passing the mode pointer further.
> 
> Fixes: f035f4097f1e ("drm/connector: hdmi: Calculate TMDS character rate")
> Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] drm/connector: hdmi: Handle NULL display mode in state check helper
  2025-01-07  0:00 [PATCH] drm/connector: hdmi: Handle NULL display mode in state check helper Cristian Ciocaltea
  2025-01-07  9:35 ` Dmitry Baryshkov
  2025-01-07 12:59 ` AngeloGioacchino Del Regno
@ 2025-01-07 15:16 ` Maxime Ripard
  2025-01-08 22:37   ` Cristian Ciocaltea
  2 siblings, 1 reply; 5+ messages in thread
From: Maxime Ripard @ 2025-01-07 15:16 UTC (permalink / raw)
  To: Cristian Ciocaltea
  Cc: Maarten Lankhorst, Thomas Zimmermann, David Airlie,
	Simona Vetter, Dave Stevenson, Dmitry Baryshkov, kernel,
	dri-devel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1886 bytes --]

On Tue, Jan 07, 2025 at 02:00:35AM +0200, Cristian Ciocaltea wrote:
> drm_atomic_helper_connector_hdmi_check() helper makes use of
> connector_state_get_mode() to obtain a drm_display_mode pointer, but it
> doesn't validate it, which may lead to a NULL pointer dereference in
> some cases, i.e. unloading a DRM module:
> 
> [ 1002.910414] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000
> [...]
> [ 1002.923833] Hardware name: Radxa ROCK 5B (DT)
> [ 1002.924819] pc : drm_match_cea_mode+0x30/0x280 [drm]
> [ 1002.925318] lr : hdmi_try_format_bpc+0x7c/0x580 [drm_display_helper]
> [...]
> [ 1002.932411] Call trace:
> [ 1002.932626]  drm_match_cea_mode+0x30/0x280 [drm] (P)
> [ 1002.933120]  hdmi_try_format_bpc+0x7c/0x580 [drm_display_helper]
> [ 1002.933662]  drm_atomic_helper_connector_hdmi_check+0x10c/0x478 [drm_display_helper]
> [ 1002.934355]  drm_bridge_connector_atomic_check+0x20/0x40 [drm_display_helper]
> [ 1002.934993]  drm_atomic_helper_check_modeset+0x698/0xd28 [drm_kms_helper]
> [ 1002.935607]  drm_atomic_helper_check+0x28/0xb8 [drm_kms_helper]
> [ 1002.936143]  drm_atomic_check_only+0x794/0x988 [drm]
> [ 1002.936635]  drm_atomic_commit+0x60/0xe0 [drm]
> [ 1002.937082]  drm_atomic_helper_disable_all+0x184/0x218 [drm_kms_helper]
> [ 1002.937678]  drm_atomic_helper_shutdown+0x90/0x150 [drm_kms_helper]
> [ 1002.938243]  rockchip_drm_unbind+0x38/0x80 [rockchipdrm]
> [ 1002.938720]  component_master_del+0xac/0xf8
> [ 1002.939089]  rockchip_drm_platform_remove+0x34/0x78 [rockchipdrm]
> [...]
> 
> Add the missing NULL check before passing the mode pointer further.
> 
> Fixes: f035f4097f1e ("drm/connector: hdmi: Calculate TMDS character rate")
> Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>

Looks good to me, but we need to provide a test for that case too

Maxime

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 273 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] drm/connector: hdmi: Handle NULL display mode in state check helper
  2025-01-07 15:16 ` Maxime Ripard
@ 2025-01-08 22:37   ` Cristian Ciocaltea
  0 siblings, 0 replies; 5+ messages in thread
From: Cristian Ciocaltea @ 2025-01-08 22:37 UTC (permalink / raw)
  To: Maxime Ripard
  Cc: Maarten Lankhorst, Thomas Zimmermann, David Airlie,
	Simona Vetter, Dave Stevenson, Dmitry Baryshkov, kernel,
	dri-devel, linux-kernel

On 1/7/25 5:16 PM, Maxime Ripard wrote:
> On Tue, Jan 07, 2025 at 02:00:35AM +0200, Cristian Ciocaltea wrote:
>> drm_atomic_helper_connector_hdmi_check() helper makes use of
>> connector_state_get_mode() to obtain a drm_display_mode pointer, but it
>> doesn't validate it, which may lead to a NULL pointer dereference in
>> some cases, i.e. unloading a DRM module:
>>
>> [ 1002.910414] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000
>> [...]
>> [ 1002.923833] Hardware name: Radxa ROCK 5B (DT)
>> [ 1002.924819] pc : drm_match_cea_mode+0x30/0x280 [drm]
>> [ 1002.925318] lr : hdmi_try_format_bpc+0x7c/0x580 [drm_display_helper]
>> [...]
>> [ 1002.932411] Call trace:
>> [ 1002.932626]  drm_match_cea_mode+0x30/0x280 [drm] (P)
>> [ 1002.933120]  hdmi_try_format_bpc+0x7c/0x580 [drm_display_helper]
>> [ 1002.933662]  drm_atomic_helper_connector_hdmi_check+0x10c/0x478 [drm_display_helper]
>> [ 1002.934355]  drm_bridge_connector_atomic_check+0x20/0x40 [drm_display_helper]
>> [ 1002.934993]  drm_atomic_helper_check_modeset+0x698/0xd28 [drm_kms_helper]
>> [ 1002.935607]  drm_atomic_helper_check+0x28/0xb8 [drm_kms_helper]
>> [ 1002.936143]  drm_atomic_check_only+0x794/0x988 [drm]
>> [ 1002.936635]  drm_atomic_commit+0x60/0xe0 [drm]
>> [ 1002.937082]  drm_atomic_helper_disable_all+0x184/0x218 [drm_kms_helper]
>> [ 1002.937678]  drm_atomic_helper_shutdown+0x90/0x150 [drm_kms_helper]
>> [ 1002.938243]  rockchip_drm_unbind+0x38/0x80 [rockchipdrm]
>> [ 1002.938720]  component_master_del+0xac/0xf8
>> [ 1002.939089]  rockchip_drm_platform_remove+0x34/0x78 [rockchipdrm]
>> [...]
>>
>> Add the missing NULL check before passing the mode pointer further.
>>
>> Fixes: f035f4097f1e ("drm/connector: hdmi: Calculate TMDS character rate")
>> Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
> 
> Looks good to me, but we need to provide a test for that case too

Test cases provided in v2:

https://lore.kernel.org/lkml/20250109-hdmi-conn-null-mode-v2-2-9eeaf1109547@collabora.com/

Thanks,
Cristian

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-01-08 22:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-07  0:00 [PATCH] drm/connector: hdmi: Handle NULL display mode in state check helper Cristian Ciocaltea
2025-01-07  9:35 ` Dmitry Baryshkov
2025-01-07 12:59 ` AngeloGioacchino Del Regno
2025-01-07 15:16 ` Maxime Ripard
2025-01-08 22:37   ` Cristian Ciocaltea

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®