diff mbox series

[v2] bluetooth: guard against controllers sending zero'd events

Message ID 20200302154249.25047-1-alainm@chromium.org (mailing list archive)
State Changes Requested
Delegated to: Marcel Holtmann
Headers show
Series [v2] bluetooth: guard against controllers sending zero'd events | expand

Commit Message

Alain Michaud March 2, 2020, 3:42 p.m. UTC
Some controllers have been observed to send zero'd events under some
conditions.  This change guards against this condition as well as adding
a trace to facilitate diagnosability of this condition.

Signed-off-by: Alain Michaud <alainm@chromium.org>
---

 net/bluetooth/hci_event.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Marcel Holtmann March 2, 2020, 10:12 p.m. UTC | #1
Hi Alain,

> Some controllers have been observed to send zero'd events under some
> conditions.  This change guards against this condition as well as adding
> a trace to facilitate diagnosability of this condition.
> 
> Signed-off-by: Alain Michaud <alainm@chromium.org>
> ---
> 
> net/bluetooth/hci_event.c | 6 ++++++
> 1 file changed, 6 insertions(+)
> 
> diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
> index 591e7477e925..56305b3a865e 100644
> --- a/net/bluetooth/hci_event.c
> +++ b/net/bluetooth/hci_event.c
> @@ -5868,6 +5868,12 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)
> 	u8 status = 0, event = hdr->evt, req_evt = 0;
> 	u16 opcode = HCI_OP_NOP;
> 
> +	if (!event) {
> +		bt_dev_warn(hdev, "Received unexpected HCI Event 00000000");
> +		kfree_skb(skb);
> +		hdev->stat.evt_rx++;
> +	}
> +
> 	if (hdev->sent_cmd && bt_cb(hdev->sent_cmd)->hci.req_event == event) {
> 		struct hci_command_hdr *cmd_hdr = (void *) hdev->sent_cmd->data;
> 		opcode = __le16_to_cpu(cmd_hdr->opcode);

what about doing just this:

@@ -5868,6 +5868,11 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)
        u8 status = 0, event = hdr->evt, req_evt = 0;
        u16 opcode = HCI_OP_NOP;
 
+       if (!event) {
+               bt_dev_warn(hdev, ..);
+               goto done;
+       }
+
        if (hdev->sent_cmd && bt_cb(hdev->sent_cmd)->hci.req_event == event) {
                struct hci_command_hdr *cmd_hdr = (void *) hdev->sent_cmd->data;
                opcode = __le16_to_cpu(cmd_hdr->opcode);
@@ -6079,6 +6084,7 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)
                req_complete_skb(hdev, status, opcode, orig_skb);
        }
 
+done:
        kfree_skb(orig_skb);
        kfree_skb(skb);
        hdev->stat.evt_rx++;

Regards

Marcel
diff mbox series

Patch

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 591e7477e925..56305b3a865e 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -5868,6 +5868,12 @@  void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)
 	u8 status = 0, event = hdr->evt, req_evt = 0;
 	u16 opcode = HCI_OP_NOP;
 
+	if (!event) {
+		bt_dev_warn(hdev, "Received unexpected HCI Event 00000000");
+		kfree_skb(skb);
+		hdev->stat.evt_rx++;
+	}
+
 	if (hdev->sent_cmd && bt_cb(hdev->sent_cmd)->hci.req_event == event) {
 		struct hci_command_hdr *cmd_hdr = (void *) hdev->sent_cmd->data;
 		opcode = __le16_to_cpu(cmd_hdr->opcode);