Skip to content

Commit

Permalink
net: qrtr: Avoid potential use after free in MHI send
Browse files Browse the repository at this point in the history
commit 47a017f upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
andersson authored and gregkh committed May 7, 2021
1 parent 0356e50 commit 03c649d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions net/qrtr/mhi.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ static int qcom_mhi_qrtr_send(struct qrtr_endpoint *ep, struct sk_buff *skb)
struct qrtr_mhi_dev *qdev = container_of(ep, struct qrtr_mhi_dev, ep);
int rc;

if (skb->sk)
sock_hold(skb->sk);

rc = skb_linearize(skb);
if (rc)
goto free_skb;
Expand All @@ -59,12 +62,11 @@ static int qcom_mhi_qrtr_send(struct qrtr_endpoint *ep, struct sk_buff *skb)
if (rc)
goto free_skb;

if (skb->sk)
sock_hold(skb->sk);

return rc;

free_skb:
if (skb->sk)
sock_put(skb->sk);
kfree_skb(skb);

return rc;
Expand Down

0 comments on commit 03c649d

Please sign in to comment.