diff options
author | Peter Hurley <peter@hurleysoftware.com> | 2014-02-09 20:59:06 -0500 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2014-02-14 16:39:29 -0500 |
commit | 960603a54aa0d5f4f1c4f1037bcaee571d03cb1e (patch) | |
tree | e226fbc1a87886de9b8fdc821d6f39a4d67ee40a | |
parent | 082a1532fc7607727f759c069eb8dd9fa5ae3f37 (diff) |
Bluetooth: Exclude released devices from RFCOMMGETDEVLIST ioctl
When enumerating RFCOMM devices in the rfcomm_dev_list, holding
the rfcomm_dev_lock only guarantees the existence of the enumerated
rfcomm_dev in memory, and not safe access to its state. Testing
the device state (such as RFCOMM_TTY_RELEASED) does not guarantee
the device will remain in that state for the subsequent access
to the rfcomm_dev's fields, nor guarantee that teardown has not
commenced.
Obtain an rfcomm_dev reference for the duration of rfcomm_dev
access.
Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Tested-By: Alexander Holler <holler@ahsoftware.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
-rw-r--r-- | net/bluetooth/rfcomm/tty.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c index 7cf193f0eea7..b385d9985656 100644 --- a/net/bluetooth/rfcomm/tty.c +++ b/net/bluetooth/rfcomm/tty.c | |||
@@ -468,7 +468,7 @@ static int rfcomm_get_dev_list(void __user *arg) | |||
468 | spin_lock(&rfcomm_dev_lock); | 468 | spin_lock(&rfcomm_dev_lock); |
469 | 469 | ||
470 | list_for_each_entry(dev, &rfcomm_dev_list, list) { | 470 | list_for_each_entry(dev, &rfcomm_dev_list, list) { |
471 | if (test_bit(RFCOMM_TTY_RELEASED, &dev->flags)) | 471 | if (!tty_port_get(&dev->port)) |
472 | continue; | 472 | continue; |
473 | (di + n)->id = dev->id; | 473 | (di + n)->id = dev->id; |
474 | (di + n)->flags = dev->flags; | 474 | (di + n)->flags = dev->flags; |
@@ -476,6 +476,7 @@ static int rfcomm_get_dev_list(void __user *arg) | |||
476 | (di + n)->channel = dev->channel; | 476 | (di + n)->channel = dev->channel; |
477 | bacpy(&(di + n)->src, &dev->src); | 477 | bacpy(&(di + n)->src, &dev->src); |
478 | bacpy(&(di + n)->dst, &dev->dst); | 478 | bacpy(&(di + n)->dst, &dev->dst); |
479 | tty_port_put(&dev->port); | ||
479 | if (++n >= dev_num) | 480 | if (++n >= dev_num) |
480 | break; | 481 | break; |
481 | } | 482 | } |