netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v2] ipv6/addrconf: fix a potential refcount underflow for idev
@ 2023-07-08  6:59 Ziyang Xuan
  2023-07-08  8:05 ` Eric Dumazet
  2023-07-09 10:20 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Ziyang Xuan @ 2023-07-08  6:59 UTC (permalink / raw)
  To: davem, dsahern, edumazet, kuba, pabeni, netdev, hannes, fbl

Now in addrconf_mod_rs_timer(), reference idev depends on whether
rs_timer is not pending. Then modify rs_timer timeout.

There is a time gap in [1], during which if the pending rs_timer
becomes not pending. It will miss to hold idev, but the rs_timer
is activated. Thus rs_timer callback function addrconf_rs_timer()
will be executed and put idev later without holding idev. A refcount
underflow issue for idev can be caused by this.

	if (!timer_pending(&idev->rs_timer))
		in6_dev_hold(idev);
		  <--------------[1]
	mod_timer(&idev->rs_timer, jiffies + when);

To fix the issue, hold idev if mod_timer() return 0.

Fixes: b7b1bfce0bb6 ("ipv6: split duplicate address detection and router solicitation timer")
Suggested-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>
---
v2:
  - Do not hold idev anyway firstly.
---
 net/ipv6/addrconf.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 5479da08ef40..e5213e598a04 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -318,9 +318,8 @@ static void addrconf_del_dad_work(struct inet6_ifaddr *ifp)
 static void addrconf_mod_rs_timer(struct inet6_dev *idev,
 				  unsigned long when)
 {
-	if (!timer_pending(&idev->rs_timer))
+	if (!mod_timer(&idev->rs_timer, jiffies + when))
 		in6_dev_hold(idev);
-	mod_timer(&idev->rs_timer, jiffies + when);
 }
 
 static void addrconf_mod_dad_work(struct inet6_ifaddr *ifp,
-- 
2.25.1


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

* Re: [PATCH net v2] ipv6/addrconf: fix a potential refcount underflow for idev
  2023-07-08  6:59 [PATCH net v2] ipv6/addrconf: fix a potential refcount underflow for idev Ziyang Xuan
@ 2023-07-08  8:05 ` Eric Dumazet
  2023-07-09 10:20 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Dumazet @ 2023-07-08  8:05 UTC (permalink / raw)
  To: Ziyang Xuan; +Cc: davem, dsahern, kuba, pabeni, netdev, hannes, fbl

On Sat, Jul 8, 2023 at 8:59 AM Ziyang Xuan
<william.xuanziyang@huawei.com> wrote:
>
> Now in addrconf_mod_rs_timer(), reference idev depends on whether
> rs_timer is not pending. Then modify rs_timer timeout.
>
> There is a time gap in [1], during which if the pending rs_timer
> becomes not pending. It will miss to hold idev, but the rs_timer
> is activated. Thus rs_timer callback function addrconf_rs_timer()
> will be executed and put idev later without holding idev. A refcount
> underflow issue for idev can be caused by this.
>
>         if (!timer_pending(&idev->rs_timer))
>                 in6_dev_hold(idev);
>                   <--------------[1]
>         mod_timer(&idev->rs_timer, jiffies + when);
>
> To fix the issue, hold idev if mod_timer() return 0.
>
> Fixes: b7b1bfce0bb6 ("ipv6: split duplicate address detection and router solicitation timer")
> Suggested-by: Eric Dumazet <edumazet@google.com>
> Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>

Reviewed-by: Eric Dumazet <edumazet@google.com>

Thanks !

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

* Re: [PATCH net v2] ipv6/addrconf: fix a potential refcount underflow for idev
  2023-07-08  6:59 [PATCH net v2] ipv6/addrconf: fix a potential refcount underflow for idev Ziyang Xuan
  2023-07-08  8:05 ` Eric Dumazet
@ 2023-07-09 10:20 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-07-09 10:20 UTC (permalink / raw)
  To: Ziyang Xuan; +Cc: davem, dsahern, edumazet, kuba, pabeni, netdev, hannes, fbl

Hello:

This patch was applied to netdev/net.git (main)
by David S. Miller <davem@davemloft.net>:

On Sat, 8 Jul 2023 14:59:10 +0800 you wrote:
> Now in addrconf_mod_rs_timer(), reference idev depends on whether
> rs_timer is not pending. Then modify rs_timer timeout.
> 
> There is a time gap in [1], during which if the pending rs_timer
> becomes not pending. It will miss to hold idev, but the rs_timer
> is activated. Thus rs_timer callback function addrconf_rs_timer()
> will be executed and put idev later without holding idev. A refcount
> underflow issue for idev can be caused by this.
> 
> [...]

Here is the summary with links:
  - [net,v2] ipv6/addrconf: fix a potential refcount underflow for idev
    https://git.kernel.org/netdev/net/c/06a0716949c2

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] 3+ messages in thread

end of thread, other threads:[~2023-07-09 10:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-08  6:59 [PATCH net v2] ipv6/addrconf: fix a potential refcount underflow for idev Ziyang Xuan
2023-07-08  8:05 ` Eric Dumazet
2023-07-09 10:20 ` patchwork-bot+netdevbpf

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