Skip to contentSkip to conversation

Bluetooth: hci_ldisc: check for missing tty operations

PATCH Superseded Vladis Dronov 2 participants 4 messages Jul 26, 2019 – Jul 30, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Bluetooth: hci_ldisc: check for missing tty operations

Certain ttys operations (pty_unix98_ops) lack tiocmget() and tiocmset() functions which are called by the certain HCI UART protocols (hci_ath, hci_bcm, hci_intel, hci_mrvl, hci_qca) via hci_uart_set_flow_control() or directly. This leads to an execution at NULL and can be triggered by an unprivileged user. Fix this by adding a check for the missing tty operations the same way it is done for write().

This fixes CVE-2019-10207. The Fixes: lines list commits where calls to tiocm[gs]et() or hci_uart_set_flow_control() were added to the HCI UART protocols.

Reported-by [email protected]
Cc [email protected] # v2.6.36+
Fixes c19483cc5e56 ("bluetooth: Fix missing NULL check")
Fixes b3190df62861 ("Bluetooth: Support for Atheros AR300x serial chip")
Fixes 118612fb9165 ("Bluetooth: hci_bcm: Add suspend/resume PM functions")
Fixes ff2895592f0f ("Bluetooth: hci_intel: Add Intel baudrate configuration support")
Fixes 162f812f23ba ("Bluetooth: hci_uart: Add Marvell support")
Fixes fa9ad876b8e0 ("Bluetooth: hci_qca: Add support for Qualcomm Bluetooth chip wcn3990")

---

out-of-commit-message-note:

I believe, this is a good location for the check. This way we protect protocols which does not call tiocm[gs]et() or hci_uart_set_flow_control() but may change to call them in the future.

Also we do not need hci_uart_has_tiocm_support() helper now.

 drivers/bluetooth/hci_ldisc.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/bluetooth/hci_ldisc.c +4 -3
index c84f985f348d..4a85c51d0307 100644
@@ -459,10 +459,11 @@ static int hci_uart_tty_open(struct tty_struct *tty)
 
 	BT_DBG("tty %p", tty);
 
-	/* Error if the tty has no write op instead of leaving an exploitable
-	 * hole
+	/* Error if the tty has no write or tiocm[gs]et ops instead of leaving
+	 * an exploitable hole
 	 */
-	if (tty->ops->write == NULL)
+	if (tty->ops->write == NULL || tty->ops->tiocmget == NULL ||
+	    tty->ops->tiocmset == NULL)
 		return -EOPNOTSUPP;
 
 	hu = kzalloc(sizeof(struct hci_uart), GFP_KERNEL);
Signature · 1 line
2.21.0
maintainer
#1 lore raw

Hi Vladis,

Quoted 41 lines

Certain ttys operations (pty_unix98_ops) lack tiocmget() and tiocmset() functions which are called by the certain HCI UART protocols (hci_ath, hci_bcm, hci_intel, hci_mrvl, hci_qca) via hci_uart_set_flow_control() or directly. This leads to an execution at NULL and can be triggered by an unprivileged user. Fix this by adding a check for the missing tty operations the same way it is done for write().

This fixes CVE-2019-10207. The Fixes: lines list commits where calls to tiocm[gs]et() or hci_uart_set_flow_control() were added to the HCI UART protocols.

Reported-by [email protected]
Cc [email protected] # v2.6.36+
Fixes c19483cc5e56 ("bluetooth: Fix missing NULL check")
Fixes b3190df62861 ("Bluetooth: Support for Atheros AR300x serial chip")
Fixes 118612fb9165 ("Bluetooth: hci_bcm: Add suspend/resume PM functions")
Fixes ff2895592f0f ("Bluetooth: hci_intel: Add Intel baudrate configuration support")
Fixes 162f812f23ba ("Bluetooth: hci_uart: Add Marvell support")
Fixes fa9ad876b8e0 ("Bluetooth: hci_qca: Add support for Qualcomm Bluetooth chip wcn3990")

---

out-of-commit-message-note:

I believe, this is a good location for the check. This way we protect protocols which does not call tiocm[gs]et() or hci_uart_set_flow_control() but may change to call them in the future.

Also we do not need hci_uart_has_tiocm_support() helper now.

drivers/bluetooth/hci_ldisc.c | 7 ++++---

1 file changed, 4 insertions(+), 3 deletions(-)
drivers/bluetooth/hci_ldisc.c +0 -0
index c84f985f348d..4a85c51d0307 100644
@@ -459,10 +459,11 @@ static int hci_uart_tty_open(struct tty_struct *tty)
 
 	BT_DBG("tty %p", tty);

drivers/bluetooth/hci_ldisc.c static int hci_uart_tty_open(struct tty_struct *tty) · line 467

Quoted 10 lines
drivers/bluetooth/hci_ldisc.c +4 -3
 
-	/* Error if the tty has no write op instead of leaving an exploitable
-	 * hole
+	/* Error if the tty has no write or tiocm[gs]et ops instead of leaving
+	 * an exploitable hole
 	 */
-	if (tty->ops->write == NULL)
+	if (tty->ops->write == NULL || tty->ops->tiocmget == NULL ||
+	    tty->ops->tiocmset == NULL)
 		return -EOPNOTSUPP;

this means that you can not run hci_h4.c on any TTY anymore. For all the vendor specific ones, I agree, but H:4 is a Bluetooth SIG defined standard one that we might want to allow on any kind of TTY since it doesn’t really mandate anything.

So I would prefer if we go with a hci_uart_has_tiocm_support helper for now.

Regards

Marcel

#2 lore raw

PATCH v3 1/1 Bluetooth: hci_uart: check for missing tty operations

Certain ttys operations (pty_unix98_ops) lack tiocmget() and tiocmset() functions which are called by the certain HCI UART protocols (hci_ath, hci_bcm, hci_intel, hci_mrvl, hci_qca) via hci_uart_set_flow_control() or directly. This leads to an execution at NULL and can be triggered by an unprivileged user. Fix this by adding a helper function and a check for the missing tty operations in the protocols code.

This fixes CVE-2019-10207. The Fixes: lines list commits where calls to tiocm[gs]et() or hci_uart_set_flow_control() were added to the HCI UART protocols.

Reported-by [email protected]
Cc [email protected] # v2.6.36+
Fixes b3190df62861 ("Bluetooth: Support for Atheros AR300x serial chip")
Fixes 118612fb9165 ("Bluetooth: hci_bcm: Add suspend/resume PM functions")
Fixes ff2895592f0f ("Bluetooth: hci_intel: Add Intel baudrate configuration support")
Fixes 162f812f23ba ("Bluetooth: hci_uart: Add Marvell support")
Fixes fa9ad876b8e0 ("Bluetooth: hci_qca: Add support for Qualcomm Bluetooth chip wcn3990")

---

out-of-commit-message-note:

it is possible that a HCI UART protocol uses serial device's operations and not a tty ones. i made hci_uart_has_flow_control() to check this also, hence the name. serial device's code checks if the needed operations are present itself.

i believe, hci_h5 does not need this check, as it uses serial device functions only (as of now):

    serdev_device_set_flow_control(h5->hu->serdev, false);
    serdev_device_set_baudrate(h5->hu->serdev, 115200);
 drivers/bluetooth/hci_ath.c   | 3 +++
 drivers/bluetooth/hci_bcm.c   | 3 +++
 drivers/bluetooth/hci_intel.c | 3 +++
 drivers/bluetooth/hci_ldisc.c | 7 +++++++
 drivers/bluetooth/hci_mrvl.c  | 3 +++
 drivers/bluetooth/hci_qca.c   | 3 +++
 drivers/bluetooth/hci_uart.h  | 1 +
 7 files changed, 23 insertions(+)
drivers/bluetooth/hci_ath.c +3 -0
index a55be205b91a..dbfe34664633 100644
@@ -98,6 +98,9 @@ static int ath_open(struct hci_uart *hu)
 
 	BT_DBG("hu %p", hu);
 
+	if (!hci_uart_has_flow_control(hu))
+		return -EOPNOTSUPP;
+
 	ath = kzalloc(sizeof(*ath), GFP_KERNEL);
 	if (!ath)
 		return -ENOMEM;
drivers/bluetooth/hci_bcm.c +3 -0
index 8905ad2edde7..ae2624fce913 100644
@@ -406,6 +406,9 @@ static int bcm_open(struct hci_uart *hu)
 
 	bt_dev_dbg(hu->hdev, "hu %p", hu);
 
+	if (!hci_uart_has_flow_control(hu))
+		return -EOPNOTSUPP;
+
 	bcm = kzalloc(sizeof(*bcm), GFP_KERNEL);
 	if (!bcm)
 		return -ENOMEM;
drivers/bluetooth/hci_intel.c +3 -0
index 207bae5e0d46..31f25153087d 100644
@@ -391,6 +391,9 @@ static int intel_open(struct hci_uart *hu)
 
 	BT_DBG("hu %p", hu);
 
+	if (!hci_uart_has_flow_control(hu))
+		return -EOPNOTSUPP;
+
 	intel = kzalloc(sizeof(*intel), GFP_KERNEL);
 	if (!intel)
 		return -ENOMEM;
drivers/bluetooth/hci_ldisc.c +7 -0
index 8950e07889fe..11049e2336f3 100644
@@ -292,6 +292,13 @@ static int hci_uart_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
 	return 0;
 }
 
+/* Check the underlying device or tty has flow control support */
+bool hci_uart_has_flow_control(struct hci_uart *hu)
+{
+	return hu->serdev ||
+		(hu->tty->driver->ops->tiocmget && hu->tty->driver->ops->tiocmset);
+}
+
 /* Flow control or un-flow control the device */
 void hci_uart_set_flow_control(struct hci_uart *hu, bool enable)
 {
drivers/bluetooth/hci_mrvl.c +3 -0
index f98e5cc343b2..fbc3f7c3a5c7 100644
@@ -59,6 +59,9 @@ static int mrvl_open(struct hci_uart *hu)
 
 	BT_DBG("hu %p", hu);
 
+	if (!hci_uart_has_flow_control(hu))
+		return -EOPNOTSUPP;
+
 	mrvl = kzalloc(sizeof(*mrvl), GFP_KERNEL);
 	if (!mrvl)
 		return -ENOMEM;
drivers/bluetooth/hci_qca.c +3 -0
index 9a5c9c1f9484..82a0a3691a63 100644
@@ -473,6 +473,9 @@ static int qca_open(struct hci_uart *hu)
 
 	BT_DBG("hu %p qca_open", hu);
 
+	if (!hci_uart_has_flow_control(hu))
+		return -EOPNOTSUPP;
+
 	qca = kzalloc(sizeof(struct qca_data), GFP_KERNEL);
 	if (!qca)
 		return -ENOMEM;
drivers/bluetooth/hci_uart.h +1 -0
index f11af3912ce6..6ab631101019 100644
@@ -104,6 +104,7 @@ int hci_uart_wait_until_sent(struct hci_uart *hu);
 int hci_uart_init_ready(struct hci_uart *hu);
 void hci_uart_init_work(struct work_struct *work);
 void hci_uart_set_baudrate(struct hci_uart *hu, unsigned int speed);
+bool hci_uart_has_flow_control(struct hci_uart *hu);
 void hci_uart_set_flow_control(struct hci_uart *hu, bool enable);
 void hci_uart_set_speeds(struct hci_uart *hu, unsigned int init_speed,
 			 unsigned int oper_speed);
Signature · 1 line
2.20.1
maintainer
#3 lore raw

Re: [PATCH v3] Bluetooth: hci_uart: check for missing tty operations

Hi Vladis,

Quoted 35 lines

Certain ttys operations (pty_unix98_ops) lack tiocmget() and tiocmset() functions which are called by the certain HCI UART protocols (hci_ath, hci_bcm, hci_intel, hci_mrvl, hci_qca) via hci_uart_set_flow_control() or directly. This leads to an execution at NULL and can be triggered by an unprivileged user. Fix this by adding a helper function and a check for the missing tty operations in the protocols code.

This fixes CVE-2019-10207. The Fixes: lines list commits where calls to tiocm[gs]et() or hci_uart_set_flow_control() were added to the HCI UART protocols.

Reported-by [email protected]
Cc [email protected] # v2.6.36+
Fixes b3190df62861 ("Bluetooth: Support for Atheros AR300x serial chip")
Fixes 118612fb9165 ("Bluetooth: hci_bcm: Add suspend/resume PM functions")
Fixes ff2895592f0f ("Bluetooth: hci_intel: Add Intel baudrate configuration support")
Fixes 162f812f23ba ("Bluetooth: hci_uart: Add Marvell support")
Fixes fa9ad876b8e0 ("Bluetooth: hci_qca: Add support for Qualcomm Bluetooth chip wcn3990")

---

out-of-commit-message-note:

it is possible that a HCI UART protocol uses serial device's operations and not a tty ones. i made hci_uart_has_flow_control() to check this also, hence the name. serial device's code checks if the needed operations are present itself.

i believe, hci_h5 does not need this check, as it uses serial device functions only (as of now):

   serdev_device_set_flow_control(h5->hu->serdev, false);
   serdev_device_set_baudrate(h5->hu->serdev, 115200);
Quoted 8 lines
drivers/bluetooth/hci_ath.c   | 3 +++
drivers/bluetooth/hci_bcm.c   | 3 +++
drivers/bluetooth/hci_intel.c | 3 +++
drivers/bluetooth/hci_ldisc.c | 7 +++++++
drivers/bluetooth/hci_mrvl.c  | 3 +++
drivers/bluetooth/hci_qca.c   | 3 +++
drivers/bluetooth/hci_uart.h  | 1 +
7 files changed, 23 insertions(+)

I changed the hci_uart_has_flow_control function into using more readable separate checks and then send the patch directly to Linus.

Regards

Marcel