Skip to content

Commit 80ea733

Browse files
peterhurleyholtmann
authored andcommitted
Bluetooth: Fix unreleased rfcomm_dev reference
When RFCOMM_RELEASE_ONHUP is set, the rfcomm tty driver 'takes over' the initial rfcomm_dev reference created by the RFCOMMCREATEDEV ioctl. The assumption is that the rfcomm tty driver will release the rfcomm_dev reference when the tty is freed (in rfcomm_tty_cleanup()). However, if the tty is never opened, the 'take over' never occurs, so when RFCOMMRELEASEDEV ioctl is called, the reference is not released. Track the state of the reference 'take over' so that the release is guaranteed by either the RFCOMMRELEASEDEV ioctl or the rfcomm tty driver. Note that the synchronous hangup in rfcomm_release_dev() ensures that rfcomm_tty_install() cannot race with the RFCOMMRELEASEDEV ioctl. 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 1c64834 commit 80ea733

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

‎include/net/bluetooth/rfcomm.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ int rfcomm_connect_ind(struct rfcomm_session *s, u8 channel,
333333

334334
/* rfcomm_dev.status bit definitions */
335335
#define RFCOMM_DEV_RELEASED 0
336+
#define RFCOMM_TTY_OWNED 1
336337

337338
struct rfcomm_dev_req {
338339
s16 dev_id;

‎net/bluetooth/rfcomm/tty.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ static int rfcomm_release_dev(void __user *arg)
441441
tty_kref_put(tty);
442442
}
443443

444-
if (!test_bit(RFCOMM_RELEASE_ONHUP, &dev->flags))
444+
if (!test_bit(RFCOMM_TTY_OWNED, &dev->status))
445445
tty_port_put(&dev->port);
446446

447447
tty_port_put(&dev->port);
@@ -685,8 +685,10 @@ static int rfcomm_tty_install(struct tty_driver *driver, struct tty_struct *tty)
685685
* when the last process closes the tty. The behaviour is expected by
686686
* userspace.
687687
*/
688-
if (test_bit(RFCOMM_RELEASE_ONHUP, &dev->flags))
688+
if (test_bit(RFCOMM_RELEASE_ONHUP, &dev->flags)) {
689+
set_bit(RFCOMM_TTY_OWNED, &dev->status);
689690
tty_port_put(&dev->port);
691+
}
690692

691693
return 0;
692694
}

0 commit comments

Comments
 (0)