Skip to contentSkip to conversation

net/bluetooth/rfcomm/tty.c: use-after-free

DISCUSSION Applied Adrian Bunk 3 participants 3 messages Jul 23, 2007 – Jul 26, 2007

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

Commit 8de0a15483b357d0f0b821330ec84d1660cadc4e added the following use-after-free in net/bluetooth/rfcomm/tty.c:

<-- snip -->

...
static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc) {
...

        if (IS_ERR(dev->tty_dev)) {
                list_del(&dev->list);
                kfree(dev);
                return PTR_ERR(dev->tty_dev);
        }

...

<-- snip -->

Spotted by the Coverity checker.

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
maintainer
#1 lore raw

Hi Adrian,

Quoted 14 lines

Commit 8de0a15483b357d0f0b821330ec84d1660cadc4e added the following use-after-free in net/bluetooth/rfcomm/tty.c:

<-- snip -->

...
static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc) {
...

        if (IS_ERR(dev->tty_dev)) {
                list_del(&dev->list);
                kfree(dev);
                return PTR_ERR(dev->tty_dev);
        }
Quoted 5 lines

...

<-- snip -->

Spotted by the Coverity checker.

really good catch. I fully overlooked that one. The attached patch should fix it.

Regards

Marcel

net/bluetooth/rfcomm/tty.c +3 -2
index 23ba61a..22a8320 100644
@@ -267,7 +267,7 @@ static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc)
 out:
 	write_unlock_bh(&rfcomm_dev_lock);
 
-	if (err) {
+	if (err < 0) {
 		kfree(dev);
 		return err;
 	}
@@ -275,9 +275,10 @@ out:
 	dev->tty_dev = tty_register_device(rfcomm_tty_driver, dev->id, NULL);
 
 	if (IS_ERR(dev->tty_dev)) {
+		err = PTR_ERR(dev->tty_dev);
 		list_del(&dev->list);
 		kfree(dev);
-		return PTR_ERR(dev->tty_dev);
+		return err;
 	}
 
 	return dev->id;
maintainer Applied
#2 lore raw

From: Marcel Holtmann <[email protected]>
Date: Mon, 23 Jul 2007 09:47:12 +0200

Quoted 4 lines

Hi Adrian,

Quoted 2 lines

Commit 8de0a15483b357d0f0b821330ec84d1660cadc4e added the following use-after-free in net/bluetooth/rfcomm/tty.c:

...

Quoted 6 lines
Quoted 1 line

Spotted by the Coverity checker.

really good catch. I fully overlooked that one. The attached patch should fix it.

Applied, thanks everyone.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/