linux-arm-msm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: qrtr: Avoid potential use after free in MHI send
@ 2021-04-21 17:40 Bjorn Andersson
  2021-04-21 18:10 ` patchwork-bot+netdevbpf
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Bjorn Andersson @ 2021-04-21 17:40 UTC (permalink / raw)
  To: Manivannan Sadhasivam, David S. Miller, Jakub Kicinski
  Cc: linux-arm-msm, netdev, linux-kernel

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: 6e728f321393 ("net: qrtr: Add MHI transport layer")
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
---
 net/qrtr/mhi.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/net/qrtr/mhi.c b/net/qrtr/mhi.c
index 2bf2b1943e61..fa611678af05 100644
--- a/net/qrtr/mhi.c
+++ b/net/qrtr/mhi.c
@@ -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;
@@ -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;
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: qrtr: Avoid potential use after free in MHI send
  2021-04-21 17:40 [PATCH] net: qrtr: Avoid potential use after free in MHI send Bjorn Andersson
@ 2021-04-21 18:10 ` patchwork-bot+netdevbpf
  2021-04-22  4:26 ` Manivannan Sadhasivam
  2021-05-26 19:03 ` patchwork-bot+linux-arm-msm
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-04-21 18:10 UTC (permalink / raw)
  To: Bjorn Andersson; +Cc: mani, davem, kuba, linux-arm-msm, netdev, linux-kernel

Hello:

This patch was applied to netdev/net.git (refs/heads/master):

On Wed, 21 Apr 2021 10:40:07 -0700 you wrote:
> 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..
> 
> [...]

Here is the summary with links:
  - net: qrtr: Avoid potential use after free in MHI send
    https://git.kernel.org/netdev/net/c/47a017f33943

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: qrtr: Avoid potential use after free in MHI send
  2021-04-21 17:40 [PATCH] net: qrtr: Avoid potential use after free in MHI send Bjorn Andersson
  2021-04-21 18:10 ` patchwork-bot+netdevbpf
@ 2021-04-22  4:26 ` Manivannan Sadhasivam
  2021-05-26 19:03 ` patchwork-bot+linux-arm-msm
  2 siblings, 0 replies; 4+ messages in thread
From: Manivannan Sadhasivam @ 2021-04-22  4:26 UTC (permalink / raw)
  To: Bjorn Andersson
  Cc: David S. Miller, Jakub Kicinski, linux-arm-msm, netdev, linux-kernel

On Wed, Apr 21, 2021 at 10:40:07AM -0700, Bjorn Andersson wrote:
> 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: 6e728f321393 ("net: qrtr: Add MHI transport layer")
> Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>

Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>

Thanks,
Mani

> ---
>  net/qrtr/mhi.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/net/qrtr/mhi.c b/net/qrtr/mhi.c
> index 2bf2b1943e61..fa611678af05 100644
> --- a/net/qrtr/mhi.c
> +++ b/net/qrtr/mhi.c
> @@ -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;
> @@ -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;
> -- 
> 2.29.2
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: qrtr: Avoid potential use after free in MHI send
  2021-04-21 17:40 [PATCH] net: qrtr: Avoid potential use after free in MHI send Bjorn Andersson
  2021-04-21 18:10 ` patchwork-bot+netdevbpf
  2021-04-22  4:26 ` Manivannan Sadhasivam
@ 2021-05-26 19:03 ` patchwork-bot+linux-arm-msm
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+linux-arm-msm @ 2021-05-26 19:03 UTC (permalink / raw)
  To: Bjorn Andersson; +Cc: linux-arm-msm

Hello:

This patch was applied to qcom/linux.git (refs/heads/for-next):

On Wed, 21 Apr 2021 10:40:07 -0700 you wrote:
> 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..
> 
> [...]

Here is the summary with links:
  - net: qrtr: Avoid potential use after free in MHI send
    https://git.kernel.org/qcom/c/47a017f33943

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-05-26 19:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-21 17:40 [PATCH] net: qrtr: Avoid potential use after free in MHI send Bjorn Andersson
2021-04-21 18:10 ` patchwork-bot+netdevbpf
2021-04-22  4:26 ` Manivannan Sadhasivam
2021-05-26 19:03 ` patchwork-bot+linux-arm-msm

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).