Skip to contentSkip to conversation

auxdisplay: ht16k33: fix potential user-after-free on module unload

PATCH In review Miguel Ojeda 4 participants 5 messages Feb 9, 2019 – Feb 14, 2019

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

PATCH 1/1 auxdisplay: ht16k33: fix potential user-after-free on module unload

On module unload/remove, we need to ensure that work does not run after we have freed resources. Concretely, cancel_delayed_work() may return while the callback function is still running.

From kernel/workqueue.c:

The work callback function may still be running on return, unless it returns true and the work doesn't re-arm itself. Explicitly flush or use cancel_delayed_work_sync() to wait on it.

---
 drivers/auxdisplay/ht16k33.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/auxdisplay/ht16k33.c +1 -1
index a43276c76fc6..21393ec3b9a4 100644
@@ -509,7 +509,7 @@ static int ht16k33_remove(struct i2c_client *client)
 	struct ht16k33_priv *priv = i2c_get_clientdata(client);
 	struct ht16k33_fbdev *fbdev = &priv->fbdev;
 
-	cancel_delayed_work(&fbdev->work);
+	cancel_delayed_work_sync(&fbdev->work);
 	unregister_framebuffer(fbdev->info);
 	framebuffer_release(fbdev->info);
 	free_page((unsigned long) fbdev->buffer);
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Miguel Ojeda

On module unload/remove, we need to ensure that work does not run after we have freed resources. Concretely, cancel_delayed_work() may return while the callback function is still running.

From kernel/workqueue.c:

Quoted 7 lines

The work callback function may still be running on return, unless it returns true and the work doesn't re-arm itself. Explicitly flush or use cancel_delayed_work_sync() to wait on it.

Quoted 20 lines
---
 drivers/auxdisplay/ht16k33.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/auxdisplay/ht16k33.c +1 -1
index a43276c76fc6..21393ec3b9a4 100644
@@ -509,7 +509,7 @@ static int ht16k33_remove(struct i2c_client *client)
 	struct ht16k33_priv *priv = i2c_get_clientdata(client);
 	struct ht16k33_fbdev *fbdev = &priv->fbdev;
 
-	cancel_delayed_work(&fbdev->work);
+	cancel_delayed_work_sync(&fbdev->work);
 	unregister_framebuffer(fbdev->info);
 	framebuffer_release(fbdev->info);
 	free_page((unsigned long) fbdev->buffer);
Signature · 1 line
2.17.1
Signature · 1 line
Dmitry
Reviewed-by on v1 1/1
#2 lore raw
In reply to Miguel Ojeda
Quoted 7 lines · Miguel Ojeda

On module unload/remove, we need to ensure that work does not run after we have freed resources. Concretely, cancel_delayed_work() may return while the callback function is still running.

From kernel/workqueue.c:

Quoted 7 lines

The work callback function may still be running on return, unless it returns true and the work doesn't re-arm itself. Explicitly flush or use cancel_delayed_work_sync() to wait on it.

Yes, this should do the trick.

maintainer Acked-by on v1 1/1
#3 lore raw
In reply to Miguel Ojeda
Quoted 22 lines · On Sat, 9 Feb 2019 01:15:22 +0100 Miguel Ojeda…

On module unload/remove, we need to ensure that work does not run after we have freed resources. Concretely, cancel_delayed_work() may return while the callback function is still running.

From kernel/workqueue.c:

The work callback function may still be running on return, unless it returns true and the work doesn't re-arm itself. Explicitly flush or use cancel_delayed_work_sync() to wait on it.

---
 drivers/auxdisplay/ht16k33.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/auxdisplay/ht16k33.c +0 -0
index a43276c76fc6..21393ec3b9a4 100644

drivers/auxdisplay/ht16k33.c static int ht16k33_remove(struct i2c_client *client) · line 515

Quoted 8 lines
drivers/auxdisplay/ht16k33.c +1 -1
@@ -509,7 +509,7 @@ static int ht16k33_remove(struct i2c_client *client)
 	struct ht16k33_priv *priv = i2c_get_clientdata(client);
 	struct ht16k33_fbdev *fbdev = &priv->fbdev;
 
-	cancel_delayed_work(&fbdev->work);
+	cancel_delayed_work_sync(&fbdev->work);
 	unregister_framebuffer(fbdev->info);
 	framebuffer_release(fbdev->info);
 	free_page((unsigned long) fbdev->buffer);

Looks good