[3.5.y.z,extended,stable] Patch "pps: Fix a use-after free bug when unregistering a source." has been added to staging queue

Message ID 1361895260-28509-1-git-send-email-luis.henriques@canonical.com
State New
Headers show

Commit Message

Luis Henriques Feb. 26, 2013, 4:14 p.m.
This is a note to let you know that I have just added a patch titled

    pps: Fix a use-after free bug when unregistering a source.

to the linux-3.5.y-queue branch of the 3.5.y.z extended stable tree 
which can be found at:


If you, or anyone else, feels it should not be added to this tree, please 
reply to this email.

For more information about the 3.5.y.z tree, see



From ef15fbbd3498462b981c7eb4cafb074e7eee3b26 Mon Sep 17 00:00:00 2001
From: George Spelvin <linux@horizon.com>
Date: Tue, 12 Feb 2013 02:27:20 -0500
Subject: [PATCH] pps: Fix a use-after free bug when unregistering a source.

commit d953e0e837e65ecc1ddaa4f9560f7925878a0de6 upstream.

Remove the cdev from the system (with cdev_del) *before* deallocating it
(in pps_device_destruct, called via kobject_put from device_destroy).

Also prevent deallocating a device with open file handles.

A better long-term fix is probably to remove the cdev from the pps_device
entirely, and instead have all devices reference one global cdev.  Then
the deallocation ordering becomes simpler.

But that's more complex and invasive change, so we leave that
for later.

Signed-off-by: George Spelvin <linux@horizon.com>
Acked-by: Rodolfo Giometti <giometti@enneenne.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[ luis: adjust context ]
Signed-off-by: Luis Henriques <luis.henriques@canonical.com>
 drivers/pps/pps.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)



diff --git a/drivers/pps/pps.c b/drivers/pps/pps.c
index c50a556..f129f4d 100644
--- a/drivers/pps/pps.c
+++ b/drivers/pps/pps.c
@@ -247,12 +247,15 @@  static int pps_cdev_open(struct inode *inode, struct file *file)
 	struct pps_device *pps = container_of(inode->i_cdev,
 						struct pps_device, cdev);
 	file->private_data = pps;
+	kobject_get(&pps->dev->kobj);
 	return 0;

 static int pps_cdev_release(struct inode *inode, struct file *file)
+	struct pps_device *pps = container_of(inode->i_cdev,
+						struct pps_device, cdev);
+	kobject_put(&pps->dev->kobj);
 	return 0;

@@ -274,8 +277,10 @@  static void pps_device_destruct(struct device *dev)
 	struct pps_device *pps = dev_get_drvdata(dev);

-	/* release id here to protect others from using it while it's
-	 * still in use */
+	cdev_del(&pps->cdev);
+	/* Now we can release the ID for re-use */
+	pr_debug("deallocating pps%d\n", pps->id);
 	idr_remove(&pps_idr, pps->id);
@@ -330,6 +335,7 @@  int pps_register_cdev(struct pps_device *pps)
 	if (IS_ERR(pps->dev))
 		goto del_cdev;

+	/* Override the release function with our own */
 	pps->dev->release = pps_device_destruct;

 	pr_debug("source %s got cdev (%d:%d)\n", pps->info.name,
@@ -350,9 +356,9 @@  free_idr:

 void pps_unregister_cdev(struct pps_device *pps)
+	pr_debug("unregistering pps%d\n", pps->id);
 	pps->lookup_cookie = NULL;
 	device_destroy(pps_class, pps->dev->devt);
-	cdev_del(&pps->cdev);