Skip to content

Commit 960603a

Browse files
peterhurleyholtmann
authored andcommitted
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>
1 parent 082a153 commit 960603a

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

  • net/bluetooth/rfcomm

‎net/bluetooth/rfcomm/tty.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,14 +468,15 @@ static int rfcomm_get_dev_list(void __user *arg)
468468
spin_lock(&rfcomm_dev_lock);
469469

470470
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))
472472
continue;
473473
(di + n)->id = dev->id;
474474
(di + n)->flags = dev->flags;
475475
(di + n)->state = dev->dlc->state;
476476
(di + n)->channel = dev->channel;
477477
bacpy(&(di + n)->src, &dev->src);
478478
bacpy(&(di + n)->dst, &dev->dst);
479+
tty_port_put(&dev->port);
479480
if (++n >= dev_num)
480481
break;
481482
}

0 commit comments

Comments
 (0)