[PATCH 4/5] Bluetooth: hci_ldisc: reject invalid tty write lengths
From: Li Qiang
Date: Thu Jul 16 2026 - 04:50:59 EST
The HCI UART write worker assumes that a tty write callback returns a
value in the range from zero through the skb length. A negative value or
a value larger than the skb length is passed to accounting and skb_pull,
which can corrupt skb state.
Treat either return value as a transmit error and discard the skb.
Signed-off-by: Li Qiang <liqiang01@xxxxxxxxxx>
---
drivers/bluetooth/hci_ldisc.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
index 47f4902b40b4..668c4f84d7f2 100644
--- a/drivers/bluetooth/hci_ldisc.c
+++ b/drivers/bluetooth/hci_ldisc.c
@@ -163,6 +163,12 @@ static void hci_uart_write_work(struct work_struct *work)
set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
len = tty->ops->write(tty, skb->data, skb->len);
+ if (len < 0 || len > skb->len) {
+ hdev->stat.err_tx++;
+ kfree_skb(skb);
+ continue;
+ }
+
hdev->stat.byte_tx += len;
skb_pull(skb, len);
--
2.43.0