Skip to contentSkip to conversation

drm/komeda: Handle NULL pointer access code path in error case

PATCH In review [email protected] 3 participants 3 messages Nov 27, 2020

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

PATCH 1/1 drm/komeda: Handle NULL pointer access code path in error case

From: Carsten Haitzler <[email protected]>

komeda_component_get_old_state() technically can return a NULL pointer. komeda_compiz_set_input() even warns when this happens, but then proceeeds to use that NULL pointer tocompare memory content there agains the new sate to see if it changed. In this case, it's better to assume that the input changed as there is no old state to compare against and thus assume the changes happen anyway.

---
 drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c +2 -1
index 8f32ae7c25d0..e8b1e15312d8 100644
@@ -707,7 +707,8 @@ komeda_compiz_set_input(struct komeda_compiz *compiz,
 	WARN_ON(!old_st);
 
 	/* compare with old to check if this input has been changed */
-	if (memcmp(&(to_compiz_st(old_st)->cins[idx]), cin, sizeof(*cin)))
+	if (!old_st ||
+	    memcmp(&(to_compiz_st(old_st)->cins[idx]), cin, sizeof(*cin)))
 		c_st->changed_active_inputs |= BIT(idx);
 
 	komeda_component_add_input(c_st, &dflow->input, idx);
Signature · 6 lines
2.29.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 19 lines · On 27/11/2020 11:00, [email protected] wrote:

From: Carsten Haitzler <[email protected]>

komeda_component_get_old_state() technically can return a NULL pointer. komeda_compiz_set_input() even warns when this happens, but then proceeeds to use that NULL pointer tocompare memory content there agains the new sate to see if it changed. In this case, it's better to assume that the input changed as there is no old state to compare against and thus assume the changes happen anyway.

---
  drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c +0 -0
index 8f32ae7c25d0..e8b1e15312d8 100644

drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c komeda_compiz_set_input(struct komeda_compiz *compiz, · line 712

Quoted 7 lines
drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c +2 -1
@@ -707,7 +707,8 @@ komeda_compiz_set_input(struct komeda_compiz *compiz,
  	WARN_ON(!old_st);
 
  	/* compare with old to check if this input has been changed */
-	if (memcmp(&(to_compiz_st(old_st)->cins[idx]), cin, sizeof(*cin)))
+	if (!old_st ||
+	    memcmp(&(to_compiz_st(old_st)->cins[idx]), cin, sizeof(*cin)))
  		c_st->changed_active_inputs |= BIT(idx);

Even better, you can move the WARN_ON into the if:

	if (WARN_ON(!old_st) || ...

Either way:

Steve

drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c komeda_compiz_set_input(struct komeda_compiz *compiz, · line 714

Quoted 3 lines
drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c +0 -0
  	komeda_component_add_input(c_st, &dflow->input, idx);
 

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

maintainer Acked-by on v1 1/1
#2 lore raw
In reply to [email protected]
Quoted 6 lines · On Fri, Nov 27, 2020 at 11:00:54AM +0000, [email protected] wrote:

From: Carsten Haitzler <[email protected]>

komeda_component_get_old_state() technically can return a NULL pointer. komeda_compiz_set_input() even warns when this happens, but then proceeeds to use that NULL pointer tocompare memory content there agains the new sate to see if it changed. In this case, it's better to

s/sate/state/

Quoted 4 lines

assume that the input changed as there is no old state to compare against and thus assume the changes happen anyway.

I can make the small fix when pulling the patch for merge into drm-misc-next-fixes.

Best regards,
Liviu

Quoted 21 lines
---
 drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c +2 -1
index 8f32ae7c25d0..e8b1e15312d8 100644
@@ -707,7 +707,8 @@ komeda_compiz_set_input(struct komeda_compiz *compiz,
 	WARN_ON(!old_st);
 
 	/* compare with old to check if this input has been changed */
-	if (memcmp(&(to_compiz_st(old_st)->cins[idx]), cin, sizeof(*cin)))
+	if (!old_st ||
+	    memcmp(&(to_compiz_st(old_st)->cins[idx]), cin, sizeof(*cin)))
 		c_st->changed_active_inputs |= BIT(idx);
 
 	komeda_component_add_input(c_st, &dflow->input, idx);
Signature · 1 line
2.29.2
Signature · 12 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel