* [PATCH] Bluetooth: hci_core: Avoid mixing up req_complete and req_complete_skb
@ 2016-02-19 22:25 Douglas Anderson
2016-02-20 7:04 ` Johan Hedberg
2016-02-20 8:00 ` Marcel Holtmann
0 siblings, 2 replies; 3+ messages in thread
From: Douglas Anderson @ 2016-02-19 22:25 UTC (permalink / raw)
To: Johan Hedberg, Marcel Holtmann
Cc: Douglas Anderson, gustavo-THi1TnShQwVAfugRpC6u6w,
johan.hedberg-Re5JQEeQqe8AvxtiuMwx3w,
davem-fT/PcQaiUtIeIZ0/mPfg9Q,
linux-bluetooth-u79uwXL29TY76Z2rM5mHXA,
netdev-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
In commit 44d271377479 ("Bluetooth: Compress the size of struct
hci_ctrl") we squashed down the size of the structure by using a union
with the assumption that all users would use the flag to determine
whether we had a req_complete or a req_complete_skb.
Unfortunately we had a case in hci_req_cmd_complete() where we weren't
looking at the flag. This can result in a situation where we might be
storing a hci_req_complete_skb_t in a hci_req_complete_t variable, or
vice versa.
During some testing I found at least one case where the function
hci_req_sync_complete() was called improperly because the kernel thought
that it didn't require an SKB. Looking through the stack in kgdb I
found that it was called by hci_event_packet() and that
hci_event_packet() had both of its locals "req_complete" and
"req_complete_skb" pointing to the same place: both to
hci_req_sync_complete().
Let's make sure we always check the flag.
For more details on debugging done, see <http://crbug.com/588288>.
Fixes: 44d271377479 ("Bluetooth: Compress the size of struct hci_ctrl")
Signed-off-by: Douglas Anderson <dianders-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
---
Testing was done on a Chrome OS device on kernel 3.14 w/
bluetooth-next backports. Since I couldn't reliably reproduce the
problem, I simply confirmed that existing functionality worked.
net/bluetooth/hci_core.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 541760fe53d4..9c0a6830ff92 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -4118,8 +4118,10 @@ void hci_req_cmd_complete(struct hci_dev *hdev, u16 opcode, u8 status,
break;
}
- *req_complete = bt_cb(skb)->hci.req_complete;
- *req_complete_skb = bt_cb(skb)->hci.req_complete_skb;
+ if (bt_cb(skb)->hci.req_flags & HCI_REQ_SKB)
+ *req_complete_skb = bt_cb(skb)->hci.req_complete_skb;
+ else
+ *req_complete = bt_cb(skb)->hci.req_complete;
kfree_skb(skb);
}
spin_unlock_irqrestore(&hdev->cmd_q.lock, flags);
--
2.7.0.rc3.207.g0ac5344
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Bluetooth: hci_core: Avoid mixing up req_complete and req_complete_skb
2016-02-19 22:25 [PATCH] Bluetooth: hci_core: Avoid mixing up req_complete and req_complete_skb Douglas Anderson
@ 2016-02-20 7:04 ` Johan Hedberg
2016-02-20 8:00 ` Marcel Holtmann
1 sibling, 0 replies; 3+ messages in thread
From: Johan Hedberg @ 2016-02-20 7:04 UTC (permalink / raw)
To: Douglas Anderson
Cc: Marcel Holtmann, gustavo, davem, linux-bluetooth, netdev,
linux-kernel
Hi Douglas,
On Fri, Feb 19, 2016, Douglas Anderson wrote:
> In commit 44d271377479 ("Bluetooth: Compress the size of struct
> hci_ctrl") we squashed down the size of the structure by using a union
> with the assumption that all users would use the flag to determine
> whether we had a req_complete or a req_complete_skb.
>
> Unfortunately we had a case in hci_req_cmd_complete() where we weren't
> looking at the flag. This can result in a situation where we might be
> storing a hci_req_complete_skb_t in a hci_req_complete_t variable, or
> vice versa.
>
> During some testing I found at least one case where the function
> hci_req_sync_complete() was called improperly because the kernel thought
> that it didn't require an SKB. Looking through the stack in kgdb I
> found that it was called by hci_event_packet() and that
> hci_event_packet() had both of its locals "req_complete" and
> "req_complete_skb" pointing to the same place: both to
> hci_req_sync_complete().
>
> Let's make sure we always check the flag.
>
> For more details on debugging done, see <http://crbug.com/588288>.
>
> Fixes: 44d271377479 ("Bluetooth: Compress the size of struct hci_ctrl")
> Signed-off-by: Douglas Anderson <dianders@chromium.org>
> ---
> Testing was done on a Chrome OS device on kernel 3.14 w/
> bluetooth-next backports. Since I couldn't reliably reproduce the
> problem, I simply confirmed that existing functionality worked.
>
> net/bluetooth/hci_core.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
Good catch.
Acked-by: Johan Hedberg <johan.hedberg@intel.com>
Marcel, I think we want to send this through our stable tree to 4.5-rc
(where the patch introducing the bug is).
Johan
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Bluetooth: hci_core: Avoid mixing up req_complete and req_complete_skb
2016-02-19 22:25 [PATCH] Bluetooth: hci_core: Avoid mixing up req_complete and req_complete_skb Douglas Anderson
2016-02-20 7:04 ` Johan Hedberg
@ 2016-02-20 8:00 ` Marcel Holtmann
1 sibling, 0 replies; 3+ messages in thread
From: Marcel Holtmann @ 2016-02-20 8:00 UTC (permalink / raw)
To: Douglas Anderson
Cc: Johan Hedberg, Gustavo F. Padovan, Johan Hedberg, David S. Miller,
BlueZ development, Network Development, linux-kernel
Hi Douglas,
> In commit 44d271377479 ("Bluetooth: Compress the size of struct
> hci_ctrl") we squashed down the size of the structure by using a union
> with the assumption that all users would use the flag to determine
> whether we had a req_complete or a req_complete_skb.
>
> Unfortunately we had a case in hci_req_cmd_complete() where we weren't
> looking at the flag. This can result in a situation where we might be
> storing a hci_req_complete_skb_t in a hci_req_complete_t variable, or
> vice versa.
>
> During some testing I found at least one case where the function
> hci_req_sync_complete() was called improperly because the kernel thought
> that it didn't require an SKB. Looking through the stack in kgdb I
> found that it was called by hci_event_packet() and that
> hci_event_packet() had both of its locals "req_complete" and
> "req_complete_skb" pointing to the same place: both to
> hci_req_sync_complete().
>
> Let's make sure we always check the flag.
>
> For more details on debugging done, see <http://crbug.com/588288>.
>
> Fixes: 44d271377479 ("Bluetooth: Compress the size of struct hci_ctrl")
> Signed-off-by: Douglas Anderson <dianders@chromium.org>
> ---
> Testing was done on a Chrome OS device on kernel 3.14 w/
> bluetooth-next backports. Since I couldn't reliably reproduce the
> problem, I simply confirmed that existing functionality worked.
>
> net/bluetooth/hci_core.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
patch has been applied to bluetooth-stable tree.
Regards
Marcel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-02-20 8:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-19 22:25 [PATCH] Bluetooth: hci_core: Avoid mixing up req_complete and req_complete_skb Douglas Anderson
2016-02-20 7:04 ` Johan Hedberg
2016-02-20 8:00 ` Marcel Holtmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).