Skip to content

Commit 47a017f

Browse files
anderssondavem330
authored andcommitted
net: qrtr: Avoid potential use after free in MHI send
It is possible that the MHI ul_callback will be invoked immediately following the queueing of the skb for transmission, leading to the callback decrementing the refcount of the associated sk and freeing the skb. As such the dereference of skb and the increment of the sk refcount must happen before the skb is queued, to avoid the skb to be used after free and potentially the sk to drop its last refcount.. Fixes: 6e728f3 ("net: qrtr: Add MHI transport layer") Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 357a07c commit 47a017f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

net/qrtr/mhi.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ static int qcom_mhi_qrtr_send(struct qrtr_endpoint *ep, struct sk_buff *skb)
5050
struct qrtr_mhi_dev *qdev = container_of(ep, struct qrtr_mhi_dev, ep);
5151
int rc;
5252

53+
if (skb->sk)
54+
sock_hold(skb->sk);
55+
5356
rc = skb_linearize(skb);
5457
if (rc)
5558
goto free_skb;
@@ -59,12 +62,11 @@ static int qcom_mhi_qrtr_send(struct qrtr_endpoint *ep, struct sk_buff *skb)
5962
if (rc)
6063
goto free_skb;
6164

62-
if (skb->sk)
63-
sock_hold(skb->sk);
64-
6565
return rc;
6666

6767
free_skb:
68+
if (skb->sk)
69+
sock_put(skb->sk);
6870
kfree_skb(skb);
6971

7072
return rc;

0 commit comments

Comments
 (0)