Skip to content

Commit

Permalink
[IRDA]: Fix rfcomm use-after-free
Browse files Browse the repository at this point in the history
Adrian Bunk wrote:
> Commit 8de0a15 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.

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

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Marcel Holtmann authored and David S. Miller committed Jul 31, 2007
1 parent 566cfd8 commit 09c7d82
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions net/bluetooth/rfcomm/tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,17 +267,18 @@ 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;
}

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;
Expand Down

0 comments on commit 09c7d82

Please sign in to comment.