Bluetooth: Fix double free of SMP data skb
Subsystems (2)
PATCH 1/1 Bluetooth: Fix double free of SMP data skb
From: Johan Hedberg <[email protected]>
In the case that the SMP recv callback returns error the calling code in l2cap_core.c expects that it still owns the skb and will try to free it. The SMP code should therefore not try to free the skb if it return an error. This patch fixes such behavior in the SMP command handler function.
---
This patch should probably get Cc: stable, however it should only be applied after my "[PATCH 0/3] Some more SMP fixes" patch set. The reason I ordered these like this is for this patch to have the familiar smp_sig_channel function name to ease backporting.
net/bluetooth/smp.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
net/bluetooth/smp.c +6 -7
@@ -1387,10 +1387,8 @@ static int smp_sig_channel(struct l2cap_chan *chan, struct sk_buff *skb)return 0 ; } -if (skb->len <1 ) { -kfree_skb (skb); +if (skb->len <1 )return -EILSEQ ; - }if (!test_bit (HCI_LE_ENABLED , &hcon->hdev->dev_flags)) { err = -EOPNOTSUPP ;
@@ -1410,8 +1408,9 @@ static int smp_sig_channel(struct l2cap_chan *chan, struct sk_buff *skb)if (code !=SMP_CMD_PAIRING_REQ && code !=SMP_CMD_SECURITY_REQ && !test_bit (HCI_CONN_LE_SMP_PEND , &hcon->flags)) {BT_ERR ("Unexpected SMP command 0x%02x. Disconnecting." , code); -kfree_skb (skb); -return -EOPNOTSUPP ; + reason =SMP_CMD_NOTSUPP ; + err = -EOPNOTSUPP ; + goto done; }switch (code) {
@@ -1472,8 +1471,8 @@ static int smp_sig_channel(struct l2cap_chan *chan, struct sk_buff *skb) done:if (reason)smp_failure (conn, reason); - -kfree_skb (skb); +if (!err) +kfree_skb (skb);return err; }
Signature · 1 line
1.9.3
Hi,
Quoted 6 lines · On Mon, Aug 11, 2014, [email protected] wrote:
In the case that the SMP recv callback returns error the calling code in
l2cap_core.cexpects that it still owns the skb and will try to free it. The SMP code should therefore not try to free the skb if it return an error. This patch fixes such behavior in the SMP command handler function.
Quoted 6 lines
Signed-off-by Johan Hedberg <[email protected]>---
This patch should probably get Cc: stable, however it should only be applied after my "[PATCH 0/3] Some more SMP fixes" patch set. The reason I ordered these like this is for this patch to have the familiarsmp_sig_channelfunction name to ease backporting.
Correction to this backporting part: I must have been looking at some other receive path since now that I checked a second time smp_sig_channel() usage should be fine on old kernels. I.e. this patch is only needed for bluetooth-next.
Johan