Skip to contentSkip to conversation

drm/sun4i: hdmi: Check for null pointer before cleanup

PATCH In review Stefan Mavrodiev 3 participants 8 messages Dec 16, 2019 – Dec 17, 2019

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

PATCH 1/1 drm/sun4i: hdmi: Check for null pointer before cleanup

It's possible hdmi->connector and hdmi->encoder divices to be NULL. This can happen when building as kernel module and you try to remove the module.

This patch make simple null check, before calling the cleanup functions.

---
 drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c +4 -2
index a7c4654445c7..b61e00f2ecb8 100644
@@ -685,8 +685,10 @@ static void sun4i_hdmi_unbind(struct device *dev, struct device *master,
 	struct sun4i_hdmi *hdmi = dev_get_drvdata(dev);
 
 	cec_unregister_adapter(hdmi->cec_adap);
-	drm_connector_cleanup(&hdmi->connector);
-	drm_encoder_cleanup(&hdmi->encoder);
+	if (hdmi->connector.dev)
+		drm_connector_cleanup(&hdmi->connector);
+	if (hdmi->encoder.dev)
+		drm_encoder_cleanup(&hdmi->encoder);
 	i2c_del_adapter(hdmi->i2c);
 	i2c_put_adapter(hdmi->ddc_i2c);
 	clk_disable_unprepare(hdmi->mod_clk);
Signature · 1 line
2.17.1
maintainer
#1 lore raw

Hi,

Quoted 16 lines · Stefan Mavrodiev

It's possible hdmi->connector and hdmi->encoder divices to be NULL. This can happen when building as kernel module and you try to remove the module.

This patch make simple null check, before calling the cleanup functions.

---
 drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c +0 -0
index a7c4654445c7..b61e00f2ecb8 100644

drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c static void sun4i_hdmi_unbind(struct device *dev, struct device *master, · line 691

Quoted 9 lines
drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c +4 -2
@@ -685,8 +685,10 @@ static void sun4i_hdmi_unbind(struct device *dev, struct device *master,
 	struct sun4i_hdmi *hdmi = dev_get_drvdata(dev);
 
 	cec_unregister_adapter(hdmi->cec_adap);
-	drm_connector_cleanup(&hdmi->connector);
-	drm_encoder_cleanup(&hdmi->encoder);
+	if (hdmi->connector.dev)
+		drm_connector_cleanup(&hdmi->connector);
+	if (hdmi->encoder.dev)
+		drm_encoder_cleanup(&hdmi->encoder);

Hmmm, this doesn't look right. Do you have more information on how you can reproduce it?

Maxime

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

#2 lore raw

Hi,

Quoted 21 lines · Maxime Ripard

Hi,

Quoted 18 lines · Stefan Mavrodiev

It's possible hdmi->connector and hdmi->encoder divices to be NULL. This can happen when building as kernel module and you try to remove the module.

This patch make simple null check, before calling the cleanup functions.

---
  drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c +0 -0
index a7c4654445c7..b61e00f2ecb8 100644
@@ -685,8 +685,10 @@ static void sun4i_hdmi_unbind(struct device *dev, struct device *master,
  	struct sun4i_hdmi *hdmi = dev_get_drvdata(dev);
 
Quoted 9 lines

drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c static void sun4i_hdmi_unbind(struct device *dev, struct device *master, · line 691

Quoted 7 lines
drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c +4 -2
  	cec_unregister_adapter(hdmi->cec_adap);
-	drm_connector_cleanup(&hdmi->connector);
-	drm_encoder_cleanup(&hdmi->encoder);
+	if (hdmi->connector.dev)
+		drm_connector_cleanup(&hdmi->connector);
+	if (hdmi->encoder.dev)
+		drm_encoder_cleanup(&hdmi->encoder);

Hmmm, this doesn't look right. Do you have more information on how you can reproduce it?

Just build sun4i_drm_hdmi as module (CONFIG_DRM_SUN4I_HDMI=m). Then try to unload the module:

# rmmod sun4i_drm_hdmi

And you get this:

Unable to handle kernel NULL pointer dereference at virtual address 00000000
pgd = 6b032436
[00000000] *pgd=00000000
Internal error: Oops: 5 [#1] SMP ARM
Modules linked in: sun4i_drm_hdmi(-)
CPU: 0 PID: 1081 Comm: rmmod Not tainted 5.5.0-rc1-00030-g6ec417030d93 #33
Hardware name: Allwinner sun7i (A20) Family
PC is at drm_connector_cleanup+0x40/0x208
LR is at sun4i_hdmi_unbind+0x10/0x54 [sun4i_drm_hdmi]

...

I've tested that with sunxi/for-next branch on A20-OLinuXino board.

Best regards,
Stefan

Quoted 2 lines

Maxime

maintainer
#3 lore raw
Quoted 50 lines · Stefan Mavrodiev

Hi,

Quoted 21 lines · Maxime Ripard

Hi,

Quoted 18 lines · Stefan Mavrodiev

It's possible hdmi->connector and hdmi->encoder divices to be NULL. This can happen when building as kernel module and you try to remove the module.

This patch make simple null check, before calling the cleanup functions.

---
  drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c +0 -0
index a7c4654445c7..b61e00f2ecb8 100644
@@ -685,8 +685,10 @@ static void sun4i_hdmi_unbind(struct device *dev, struct device *master,
  	struct sun4i_hdmi *hdmi = dev_get_drvdata(dev);
 
Quoted 9 lines

drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c static void sun4i_hdmi_unbind(struct device *dev, struct device *master, · line 691

Quoted 7 lines
drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c +4 -2
  	cec_unregister_adapter(hdmi->cec_adap);
-	drm_connector_cleanup(&hdmi->connector);
-	drm_encoder_cleanup(&hdmi->encoder);
+	if (hdmi->connector.dev)
+		drm_connector_cleanup(&hdmi->connector);
+	if (hdmi->encoder.dev)
+		drm_encoder_cleanup(&hdmi->encoder);

Hmmm, this doesn't look right. Do you have more information on how you can reproduce it?

Just build sun4i_drm_hdmi as module (CONFIG_DRM_SUN4I_HDMI=m). Then try to unload the module:

# rmmod sun4i_drm_hdmi

And you get this:

Unable to handle kernel NULL pointer dereference at virtual address 00000000
pgd = 6b032436
[00000000] *pgd=00000000
Internal error: Oops: 5 [#1] SMP ARM
Modules linked in: sun4i_drm_hdmi(-)
CPU: 0 PID: 1081 Comm: rmmod Not tainted 5.5.0-rc1-00030-g6ec417030d93 #33
Hardware name: Allwinner sun7i (A20) Family
PC is at drm_connector_cleanup+0x40/0x208
LR is at sun4i_hdmi_unbind+0x10/0x54 [sun4i_drm_hdmi]
Quoted 4 lines

...

I've tested that with sunxi/for-next branch on A20-OLinuXino board.

Yeah, you detailed the symptoms nicely in the commit log, but my point was that we shouldn't end up in that situation in the first place.

Your patch works around it, but it doesn't fix the underlying issue. Is drm_connector_cleanup (or the encoder variant) called twice?

Maxime

maintainer
#4 lore raw
Quoted 54 lines · Maxime Ripard
Quoted 53 lines · Stefan Mavrodiev

Hi,

Quoted 21 lines · Maxime Ripard

Hi,

Quoted 18 lines · Stefan Mavrodiev

It's possible hdmi->connector and hdmi->encoder divices to be NULL. This can happen when building as kernel module and you try to remove the module.

This patch make simple null check, before calling the cleanup functions.

---
  drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c +0 -0
index a7c4654445c7..b61e00f2ecb8 100644
@@ -685,8 +685,10 @@ static void sun4i_hdmi_unbind(struct device *dev, struct device *master,
  	struct sun4i_hdmi *hdmi = dev_get_drvdata(dev);
 
Quoted 9 lines

drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c static void sun4i_hdmi_unbind(struct device *dev, struct device *master, · line 691

Quoted 7 lines
drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c +4 -2
  	cec_unregister_adapter(hdmi->cec_adap);
-	drm_connector_cleanup(&hdmi->connector);
-	drm_encoder_cleanup(&hdmi->encoder);
+	if (hdmi->connector.dev)
+		drm_connector_cleanup(&hdmi->connector);
+	if (hdmi->encoder.dev)
+		drm_encoder_cleanup(&hdmi->encoder);

Hmmm, this doesn't look right. Do you have more information on how you can reproduce it?

Just build sun4i_drm_hdmi as module (CONFIG_DRM_SUN4I_HDMI=m). Then try to unload the module:

# rmmod sun4i_drm_hdmi

And you get this:

Unable to handle kernel NULL pointer dereference at virtual address 00000000
pgd = 6b032436
[00000000] *pgd=00000000
Internal error: Oops: 5 [#1] SMP ARM
Modules linked in: sun4i_drm_hdmi(-)
CPU: 0 PID: 1081 Comm: rmmod Not tainted 5.5.0-rc1-00030-g6ec417030d93 #33
Hardware name: Allwinner sun7i (A20) Family
PC is at drm_connector_cleanup+0x40/0x208
LR is at sun4i_hdmi_unbind+0x10/0x54 [sun4i_drm_hdmi]

...

Quoted 7 lines
Quoted 1 line

I've tested that with sunxi/for-next branch on A20-OLinuXino board.

Yeah, you detailed the symptoms nicely in the commit log, but my point was that we shouldn't end up in that situation in the first place.

Your patch works around it, but it doesn't fix the underlying issue. Is drm_connector_cleanup (or the encoder variant) called twice?

Answering myself, yes it is. It's both the destroy call back and called in unbind. We should just remove the one in the unbind then.

Maxime

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

#5 lore raw

Hi,

Quoted 54 lines · Maxime Ripard
Quoted 53 lines · Maxime Ripard
Quoted 52 lines · Stefan Mavrodiev

Hi,

Quoted 21 lines · Maxime Ripard

Hi,

Quoted 18 lines · Stefan Mavrodiev

It's possible hdmi->connector and hdmi->encoder divices to be NULL. This can happen when building as kernel module and you try to remove the module.

This patch make simple null check, before calling the cleanup functions.

---
   drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c | 6 ++++--
   1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c +0 -0
index a7c4654445c7..b61e00f2ecb8 100644
@@ -685,8 +685,10 @@ static void sun4i_hdmi_unbind(struct device *dev, struct device *master,
   	struct sun4i_hdmi *hdmi = dev_get_drvdata(dev);
 
Quoted 9 lines

drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c static void sun4i_hdmi_unbind(struct device *dev, struct device *master, · line 691

Quoted 7 lines
drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c +4 -2
   	cec_unregister_adapter(hdmi->cec_adap);
-	drm_connector_cleanup(&hdmi->connector);
-	drm_encoder_cleanup(&hdmi->encoder);
+	if (hdmi->connector.dev)
+		drm_connector_cleanup(&hdmi->connector);
+	if (hdmi->encoder.dev)
+		drm_encoder_cleanup(&hdmi->encoder);

Hmmm, this doesn't look right. Do you have more information on how you can reproduce it?

Just build sun4i_drm_hdmi as module (CONFIG_DRM_SUN4I_HDMI=m). Then try to unload the module:

# rmmod sun4i_drm_hdmi

And you get this:

Unable to handle kernel NULL pointer dereference at virtual address 00000000
pgd = 6b032436
[00000000] *pgd=00000000
Internal error: Oops: 5 [#1] SMP ARM
Modules linked in: sun4i_drm_hdmi(-)
CPU: 0 PID: 1081 Comm: rmmod Not tainted 5.5.0-rc1-00030-g6ec417030d93 #33
Hardware name: Allwinner sun7i (A20) Family
PC is at drm_connector_cleanup+0x40/0x208
LR is at sun4i_hdmi_unbind+0x10/0x54 [sun4i_drm_hdmi]

...

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

I've tested that with sunxi/for-next branch on A20-OLinuXino board.

Yeah, you detailed the symptoms nicely in the commit log, but my point was that we shouldn't end up in that situation in the first place.

Your patch works around it, but it doesn't fix the underlying issue. Is drm_connector_cleanup (or the encoder variant) called twice?

Answering myself, yes it is. It's both the destroy call back and called in unbind. We should just remove the one in the unbind then.

Should I do this or leave it to you?

Stefan

Quoted 2 lines

Maxime

maintainer
#6 lore raw
Quoted 61 lines · Stefan Mavrodiev

Hi,

Quoted 58 lines · Maxime Ripard
Quoted 57 lines · Maxime Ripard
Quoted 49 lines · Stefan Mavrodiev

Hi,

Quoted 21 lines · Maxime Ripard

Hi,

Quoted 18 lines · Stefan Mavrodiev

It's possible hdmi->connector and hdmi->encoder divices to be NULL. This can happen when building as kernel module and you try to remove the module.

This patch make simple null check, before calling the cleanup functions.

---
   drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c | 6 ++++--
   1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c +0 -0
index a7c4654445c7..b61e00f2ecb8 100644
@@ -685,8 +685,10 @@ static void sun4i_hdmi_unbind(struct device *dev, struct device *master,
   	struct sun4i_hdmi *hdmi = dev_get_drvdata(dev);
 
Quoted 9 lines

drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c static void sun4i_hdmi_unbind(struct device *dev, struct device *master, · line 691

Quoted 7 lines
drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c +4 -2
   	cec_unregister_adapter(hdmi->cec_adap);
-	drm_connector_cleanup(&hdmi->connector);
-	drm_encoder_cleanup(&hdmi->encoder);
+	if (hdmi->connector.dev)
+		drm_connector_cleanup(&hdmi->connector);
+	if (hdmi->encoder.dev)
+		drm_encoder_cleanup(&hdmi->encoder);

Hmmm, this doesn't look right. Do you have more information on how you can reproduce it?

Just build sun4i_drm_hdmi as module (CONFIG_DRM_SUN4I_HDMI=m). Then try to unload the module:

# rmmod sun4i_drm_hdmi

And you get this:

Unable to handle kernel NULL pointer dereference at virtual address 00000000
pgd = 6b032436
[00000000] *pgd=00000000
Internal error: Oops: 5 [#1] SMP ARM
Modules linked in: sun4i_drm_hdmi(-)
CPU: 0 PID: 1081 Comm: rmmod Not tainted 5.5.0-rc1-00030-g6ec417030d93 #33
Hardware name: Allwinner sun7i (A20) Family
PC is at drm_connector_cleanup+0x40/0x208
LR is at sun4i_hdmi_unbind+0x10/0x54 [sun4i_drm_hdmi]
Quoted 4 lines

...

I've tested that with sunxi/for-next branch on A20-OLinuXino board.

Yeah, you detailed the symptoms nicely in the commit log, but my point was that we shouldn't end up in that situation in the first place.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Your patch works around it, but it doesn't fix the underlying issue. Is drm_connector_cleanup (or the encoder variant) called twice?

Answering myself, yes it is. It's both the destroy call back and called in unbind. We should just remove the one in the unbind then.

Should I do this or leave it to you?

You started that discussion, so it's only fair that you do the patch :)

Maxime

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

#7 lore raw
In reply to Stefan Mavrodiev
Quoted 1 line · Stefan Mavrodiev

It's possible hdmi->connector and hdmi->encoder divices to be NULL.

The wording is broken and s/divices/devices/. I'd write:

It's possible that the parent devices of the connector and/or encoder are NULL. This makes drm_connector_cleanup and drm_encoder_cleanup respectively trigger a NULL pointer exeception:

<...log here...>

This is reproducible by

<...receipt here...>

So add a check for NULL before calling these functions.

Of course this doesn't address the reservations by Maxime.

Best regards
Uwe

Signature · 7 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel