Bluetooth: Fix missing HCI_RAW check when binding USER_CHANNEL socket
Subsystems (2)
PATCH 1/1 Bluetooth: Fix missing HCI_RAW check when binding USER_CHANNEL socket
From: Johan Hedberg <[email protected]>
HCI devices in RAW mode will have the HCI_UP flag set. The existing hci_sock_bind code, when invoked on a HCI_CHANNEL_USER socket, tests for this flag and will return EBUSY, making it impossible to bind any HCI device RAW mode. This patch adds an extra condition for the HCI_RAW flag to make it possible for bind() to succeed.
--- net/bluetooth/hci_sock.c | 1 + 1 file changed, 1 insertion(+)
net/bluetooth/hci_sock.c +1 -0
@@ -754,6 +754,7 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr,hci_dev_test_flag (hdev,HCI_SETUP ) ||hci_dev_test_flag (hdev,HCI_CONFIG ) || (!hci_dev_test_flag (hdev,HCI_AUTO_OFF ) && + !test_bit (HCI_RAW , &hdev->flags) && test_bit(HCI_UP, &hdev->flags))) { err = -EBUSY;hci_dev_put (hdev);
Signature · 1 line
2.4.3
Marcel Holtmann
maintainerHi Johan,
Quoted 16 lines
HCI devices in RAW mode will have the
HCI_UPflag set. The existinghci_sock_bindcode, when invoked on aHCI_CHANNEL_USERsocket, tests for this flag and will return EBUSY, making it impossible to bind any HCI device RAW mode. This patch adds an extra condition for theHCI_RAWflag to make it possible forbind()to succeed.Signed-off-by Johan Hedberg <[email protected]>---
net/bluetooth/hci_sock.c| 1 +1 file changed, 1 insertion(+)net/bluetooth/hci_sock.c +0
-0
net/bluetooth/hci_sock.c static int hci_sock_bind(struct socket *sock, struct sockaddr *addr, · line 760
Quoted 7 lines
net/bluetooth/hci_sock.c +1
-0@@ -754,6 +754,7 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr,hci_dev_test_flag (hdev,HCI_SETUP ) ||hci_dev_test_flag (hdev,HCI_CONFIG ) || (!hci_dev_test_flag (hdev,HCI_AUTO_OFF ) && + !test_bit (HCI_RAW , &hdev->flags) && test_bit(HCI_UP, &hdev->flags))) { err = -EBUSY;hci_dev_put (hdev);
since we keep extending this single check into something that becomes really hard to understand why it is correct we need a large comment above explaining what we are doing and why that is correct.
Especially in conjunction with the HCI_RAW flag since that is an indication of user channel being active. You can no longer set it via an ioctl. Which means it has turned into special meaning.
This means I do not want to return EBUSY in case user channel is already active, I want to return EUSERS. I am not sure you have actually checked that this might no longer do the right thing. And I have the feeling we need a test case for that in userchan-tester.
Which means that this HCI_RAW check might need to be paired with the HCI_QUIRK_RAW_DEVICE to achieve the proper effect or we have to re-think the handling of HCI_QUIRK_RAW_DEVICE.
Regards
Marcel