mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v0] mctp: fix netdev reference bug
@ 2022-03-24  2:39 Lin Ma
  2022-03-24  3:17 ` Matt Johnston
  0 siblings, 1 reply; 3+ messages in thread
From: Lin Ma @ 2022-03-24  2:39 UTC (permalink / raw)
  To: jk, matt, davem, kuba, pabeni, netdev, linux-kernel; +Cc: Lin Ma

In extended addressing mode, function mctp_local_output() fetch netdev
through dev_get_by_index_rcu, which won't increase netdev's reference
counter. Hence, the reference may underflow when mctp_local_output calls
dev_put(), results in possible use after free.

This patch adds dev_hold() to fix the reference bug.

Fixes: 99ce45d5e7db ("mctp: Implement extended addressing")
Signed-off-by: Lin Ma <linma@zju.edu.cn>
---
 net/mctp/route.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/mctp/route.c b/net/mctp/route.c
index e52cef750500..a9e5d6c40c65 100644
--- a/net/mctp/route.c
+++ b/net/mctp/route.c
@@ -817,6 +817,7 @@ int mctp_local_output(struct sock *sk, struct mctp_route *rt,
 			return rc;
 		}
 
+		dev_hold(dev);
 		rt->dev = __mctp_dev_get(dev);
 		rcu_read_unlock();
 
-- 
2.35.1


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

* Re: [PATCH v0] mctp: fix netdev reference bug
  2022-03-24  2:39 [PATCH v0] mctp: fix netdev reference bug Lin Ma
@ 2022-03-24  3:17 ` Matt Johnston
  0 siblings, 0 replies; 3+ messages in thread
From: Matt Johnston @ 2022-03-24  3:17 UTC (permalink / raw)
  To: Lin Ma, jk, davem, kuba, pabeni, netdev, linux-kernel

Hi Lin Ma,

On Thu, 2022-03-24 at 10:39 +0800, Lin Ma wrote:
> In extended addressing mode, function mctp_local_output() fetch netdev
> through dev_get_by_index_rcu, which won't increase netdev's reference
> counter. Hence, the reference may underflow when mctp_local_output calls
> dev_put(), results in possible use after free.
> 
> This patch adds dev_hold() to fix the reference bug.

This was already fixed in net-next to increment the refcount in
__mctp_dev_get() and use mctp_dev_put().

dc121c008491 ("mctp: make __mctp_dev_get() take a refcount hold")
e297db3eadd7 ("mctp: Fix incorrect netdev unref for extended addr")

Thanks,
Matt


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

* Re: [PATCH v0] mctp: fix netdev reference bug
@ 2022-03-24  3:26 Lin Ma
  0 siblings, 0 replies; 3+ messages in thread
From: Lin Ma @ 2022-03-24  3:26 UTC (permalink / raw)
  To: Matt Johnston; +Cc: jk, davem, kuba, pabeni, netdev, linux-kernel

Hi Matt,

Oops, sorry for the false alarm, I found this on mainline kernel and I should checkout net-next before sending the patch.

Regards

>Hi Lin Ma,
>
>On Thu, 2022-03-24 at 10:39 +0800, Lin Ma wrote:
>> In extended addressing mode, function mctp_local_output() fetch netdev
>> through dev_get_by_index_rcu, which won't increase netdev's reference
>> counter. Hence, the reference may underflow when mctp_local_output calls
>> dev_put(), results in possible use after free.
>> 
>> This patch adds dev_hold() to fix the reference bug.
>
>This was already fixed in net-next to increment the refcount in
>__mctp_dev_get() and use mctp_dev_put().
>
>dc121c008491 ("mctp: make __mctp_dev_get() take a refcount hold")
>e297db3eadd7 ("mctp: Fix incorrect netdev unref for extended addr")
>
>Thanks,
>Matt

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

end of thread, other threads:[~2022-03-24  3:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-24  2:39 [PATCH v0] mctp: fix netdev reference bug Lin Ma
2022-03-24  3:17 ` Matt Johnston
2022-03-24  3:26 Lin Ma

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®