* [PATCH net] ipv6: fix calling in6_ifa_hold incorrectly for dad work
@ 2017-06-15 8:33 Xin Long
2017-06-15 14:58 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Xin Long @ 2017-06-15 8:33 UTC (permalink / raw)
To: network dev; +Cc: davem, hannes
Now when starting the dad work in addrconf_mod_dad_work, if the dad work
is idle and queued, it needs to hold ifa.
The problem is there's one gap in [1], during which if the pending dad work
is removed elsewhere. It will miss to hold ifa, but the dad word is still
idea and queue.
if (!delayed_work_pending(&ifp->dad_work))
in6_ifa_hold(ifp);
<--------------[1]
mod_delayed_work(addrconf_wq, &ifp->dad_work, delay);
An use-after-free issue can be caused by this.
Chen Wei found this issue when WARN_ON(!hlist_unhashed(&ifp->addr_lst)) in
net6_ifa_finish_destroy was hit because of it.
As Hannes' suggestion, this patch is to fix it by holding ifa first in
addrconf_mod_dad_work, then calling mod_delayed_work and putting ifa if
the dad_work is already in queue.
Note that this patch did not choose to fix it with:
if (!mod_delayed_work(delay))
in6_ifa_hold(ifp);
As with it, when delay == 0, dad_work would be scheduled immediately, all
addrconf_mod_dad_work(0) callings had to be moved under ifp->lock.
Reported-by: Wei Chen <weichen@redhat.com>
Suggested-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Acked-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
net/ipv6/addrconf.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 6a4fb1e..686c923 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -332,9 +332,9 @@ static void addrconf_mod_rs_timer(struct inet6_dev *idev,
static void addrconf_mod_dad_work(struct inet6_ifaddr *ifp,
unsigned long delay)
{
- if (!delayed_work_pending(&ifp->dad_work))
- in6_ifa_hold(ifp);
- mod_delayed_work(addrconf_wq, &ifp->dad_work, delay);
+ in6_ifa_hold(ifp);
+ if (mod_delayed_work(addrconf_wq, &ifp->dad_work, delay))
+ in6_ifa_put(ifp);
}
static int snmp6_alloc_dev(struct inet6_dev *idev)
--
2.1.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net] ipv6: fix calling in6_ifa_hold incorrectly for dad work
2017-06-15 8:33 [PATCH net] ipv6: fix calling in6_ifa_hold incorrectly for dad work Xin Long
@ 2017-06-15 14:58 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2017-06-15 14:58 UTC (permalink / raw)
To: lucien.xin; +Cc: netdev, hannes
From: Xin Long <lucien.xin@gmail.com>
Date: Thu, 15 Jun 2017 16:33:58 +0800
> Now when starting the dad work in addrconf_mod_dad_work, if the dad work
> is idle and queued, it needs to hold ifa.
>
> The problem is there's one gap in [1], during which if the pending dad work
> is removed elsewhere. It will miss to hold ifa, but the dad word is still
> idea and queue.
>
> if (!delayed_work_pending(&ifp->dad_work))
> in6_ifa_hold(ifp);
> <--------------[1]
> mod_delayed_work(addrconf_wq, &ifp->dad_work, delay);
>
> An use-after-free issue can be caused by this.
>
> Chen Wei found this issue when WARN_ON(!hlist_unhashed(&ifp->addr_lst)) in
> net6_ifa_finish_destroy was hit because of it.
>
> As Hannes' suggestion, this patch is to fix it by holding ifa first in
> addrconf_mod_dad_work, then calling mod_delayed_work and putting ifa if
> the dad_work is already in queue.
>
> Note that this patch did not choose to fix it with:
>
> if (!mod_delayed_work(delay))
> in6_ifa_hold(ifp);
>
> As with it, when delay == 0, dad_work would be scheduled immediately, all
> addrconf_mod_dad_work(0) callings had to be moved under ifp->lock.
>
> Reported-by: Wei Chen <weichen@redhat.com>
> Suggested-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
> Acked-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
> Signed-off-by: Xin Long <lucien.xin@gmail.com>
Applied and queued up for -stable, thank you.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-06-15 14:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-15 8:33 [PATCH net] ipv6: fix calling in6_ifa_hold incorrectly for dad work Xin Long
2017-06-15 14:58 ` David Miller
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).