Bluetooth: Add NULL check for tiocmget() and tiocmset()
Subsystems (2)
v3 cover Bluetooth: Add NULL check for tiocmget() and tiocmset()
tiocmget() and tiocmset() operations are optional and some tty drivers like pty miss the operations. Add NULL checks to prevent from dereference.
Myungho Jung (2):
Bluetooth: hci_ath: Add NULL check for tiocmget() and tiocmset() in
ath_setup()
Bluetooth: hci_ldisc: Add NULL check for tiocmget() and tiocmset() in
hci_uart_set_flow_control()
drivers/bluetooth/hci_ath.c | 6 ++++++ drivers/bluetooth/hci_ldisc.c | 4 ++++ 2 files changed, 10 insertions(+)
Signature · 1 line
2.17.1
PATCH v3 1/2 Bluetooth: hci_ath: Add NULL check for tiocmget() and tiocmset() in ath_setup()
tiocmget() and tiocmset() operations are optional so they are not guaranteed to be set. Return ENODEV in ath_setup() if tty driver doesn't support the operations.
---
Changes in v2:
- Add NULL check and return error in ath_setup() instead of
ath_hci_uart_work()
Changes in v3:
- Fix to return -ENODEV
- Split into 2 patches
- Add stable CC and fixes tags
drivers/bluetooth/hci_ath.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/bluetooth/hci_ath.c +6 -0
@@ -185,8 +185,14 @@ static int ath_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)static int ath_setup (struct hci_uart *hu) { +struct tty_struct *tty = hu->tty; +BT_DBG ("hu %p" , hu); +/* tty driver should support operations to set RTS */ +if (!tty->driver->ops->tiocmget || !tty->driver->ops->tiocmset) +return -ENODEV ; + hu->hdev->set_bdaddr = ath_set_bdaddr;return 0 ;
Signature · 1 line
2.17.1
PATCH v3 2/2 Bluetooth: hci_ldisc: Add NULL check for tiocmget() and tiocmset() in hci_uart_set_flow_control()
In reply to Myungho Jungtiocmget() or tiocmset() operations are optional. Just return from hci_uart_set_flow_control() if tiocmget() or tiocmset() operation is NULL.
---
Changes in v2:
- Remove braces in if statment
Changes in v3:
- Split into 2 patches
- Add stable CC and fixes tags
drivers/bluetooth/hci_ldisc.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/bluetooth/hci_ldisc.c +4 -0
@@ -314,6 +314,10 @@ void hci_uart_set_flow_control(struct hci_uart *hu, bool enable)return ; } +/* tiocmget() and tiocmset() operations are optional */ +if (!tty->driver->ops->tiocmget || !tty->driver->ops->tiocmset) +return ; +if (enable) {/* Disable hardware flow control */ ktermios = tty->termios;
Signature · 1 line
2.17.1
Marcel Holtmann
maintainerRe: [PATCH v3 2/2] Bluetooth: hci_ldisc: Add NULL check for tiocmget() and tiocmset() in hci_uart_set_flow_control()
Hi Myungho,
Quoted 23 lines
tiocmget()ortiocmset()operations are optional. Just return fromhci_uart_set_flow_control()iftiocmget()ortiocmset()operation is NULL.Fixes 2a973dfada2b ("hci_uart: Add new line discipline enhancements")Cc <[email protected]> # 4.2Signed-off-by Myungho Jung <[email protected]>---
Changes in v2:
- Remove braces in if statmentChanges in v3:
- Split into 2 patches
- Add stable CC and fixes tags
drivers/bluetooth/hci_ldisc.c| 4 ++++1 file changed, 4 insertions(+)drivers/bluetooth/hci_ldisc.c +0
-0
drivers/bluetooth/hci_ldisc.c void hci_uart_set_flow_control(struct hci_uart *hu, bool enable) · line 320
Quoted 7 lines
drivers/bluetooth/hci_ldisc.c +4
-0@@ -314,6 +314,10 @@ void hci_uart_set_flow_control(struct hci_uart *hu, bool enable)return ; } +/* tiocmget() and tiocmset() operations are optional */ +if (!tty->driver->ops->tiocmget || !tty->driver->ops->tiocmset) +return ; +
lets just fail setting the line discipline if these ops are not available. Doing some silent ignoring is not going to help.
Regards
Marcel
Marcel Holtmann
maintainerHi Myungho,
Quoted 10 lines
tiocmget()andtiocmset()operations are optional and some tty drivers like pty miss the operations. Add NULL checks to prevent from dereference.Myungho Jung (2):
Bluetooth:hci_ath: Add NULL check fortiocmget()andtiocmset()in
ath_setup()
Bluetooth:hci_ldisc: Add NULL check fortiocmget()andtiocmset()in
hci_uart_set_flow_control()
Quoted 3 lines
drivers/bluetooth/hci_ath.c| 6 ++++++drivers/bluetooth/hci_ldisc.c| 4 ++++2 files changed, 10 insertions(+)
why are we not enforcing the availability of these in the hci_uart_tty_open?
Regards
Marcel
Quoted 16 lines · Marcel Holtmann
Hi Myungho,
Quoted 10 lines
tiocmget()andtiocmset()operations are optional and some tty drivers like pty miss the operations. Add NULL checks to prevent from dereference.Myungho Jung (2):
Bluetooth:hci_ath: Add NULL check fortiocmget()andtiocmset()in
ath_setup()
Bluetooth:hci_ldisc: Add NULL check fortiocmget()andtiocmset()in
hci_uart_set_flow_control()Quoted 3 lines
drivers/bluetooth/hci_ath.c| 6 ++++++drivers/bluetooth/hci_ldisc.c| 4 ++++2 files changed, 10 insertions(+)
Quoted 6 lines
why are we not enforcing the availability of these in the
hci_uart_tty_open?Regards
Marcel
Hi Marcel,
Are the operations required on any HCI UART drivers? For now, I found only 5 drivers (ath, bcm, intel, mrvl, and qca) are explicitly calling them. So, I'm not sure whether it breaks any existing code with other drivers if returning error in open().
Thanks,
Myungho
Marcel Holtmann
maintainerHi Myungho,
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
tiocmget()andtiocmset()operations are optional and some tty drivers like pty miss the operations. Add NULL checks to prevent from dereference.Myungho Jung (2):
Bluetooth:hci_ath: Add NULL check fortiocmget()andtiocmset()in
ath_setup()
Bluetooth:hci_ldisc: Add NULL check fortiocmget()andtiocmset()in
hci_uart_set_flow_control()
drivers/bluetooth/hci_ath.c| 6 ++++++drivers/bluetooth/hci_ldisc.c| 4 ++++2 files changed, 10 insertions(+)
Quoted 6 lines
Quoted 1 line
why are we not enforcing the availability of these in the
hci_uart_tty_open?Are the operations required on any HCI UART drivers? For now, I found only 5 drivers (ath, bcm, intel, mrvl, and qca) are explicitly calling them. So, I'm not sure whether it breaks any existing code with other drivers if returning error in
open().
the H:4 spec requires setting flow control. In some cases this is done by the hciattach or btattach utility, but it still means that it is required. So failing on TTYs that don’t support it is just fine.
Regards
Marcel
Quoted 23 lines · Marcel Holtmann
Hi Myungho,
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
tiocmget()andtiocmset()operations are optional and some tty drivers like pty miss the operations. Add NULL checks to prevent from dereference.Myungho Jung (2):
Bluetooth:hci_ath: Add NULL check fortiocmget()andtiocmset()in
ath_setup()
Bluetooth:hci_ldisc: Add NULL check fortiocmget()andtiocmset()in
hci_uart_set_flow_control()
drivers/bluetooth/hci_ath.c| 6 ++++++drivers/bluetooth/hci_ldisc.c| 4 ++++2 files changed, 10 insertions(+)Quoted 6 lines
Quoted 1 line
why are we not enforcing the availability of these in the
hci_uart_tty_open?Are the operations required on any HCI UART drivers? For now, I found only 5 drivers (ath, bcm, intel, mrvl, and qca) are explicitly calling them. So, I'm not sure whether it breaks any existing code with other drivers if returning error in
open().
Quoted 6 lines
the H:4 spec requires setting flow control. In some cases this is done by the hciattach or btattach utility, but it still means that it is required. So failing on TTYs that don’t support it is just fine.
Regards
Marcel
Ok, let me make a change on hci_uart_tty_open().
Thanks,
Myungho