* [PATCH net] ppp: unlock all_ppp_mutex before registering device
@ 2018-01-10 15:24 Guillaume Nault
2018-01-15 18:23 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Guillaume Nault @ 2018-01-10 15:24 UTC (permalink / raw)
To: netdev; +Cc: Paul Mackerras, syzkaller-bugs
ppp_dev_uninit(), which is the .ndo_uninit() handler of PPP devices,
needs to lock pn->all_ppp_mutex. Therefore we mustn't call
register_netdevice() with pn->all_ppp_mutex already locked, or we'd
deadlock in case register_netdevice() fails and calls .ndo_uninit().
Fortunately, we can unlock pn->all_ppp_mutex before calling
register_netdevice(). This lock protects pn->units_idr, which isn't
used in the device registration process.
However, keeping pn->all_ppp_mutex locked during device registration
did ensure that no device in transient state would be published in
pn->units_idr. In practice, unlocking it before calling
register_netdevice() doesn't change this property: ppp_unit_register()
is called with 'ppp_mutex' locked and all searches done in
pn->units_idr hold this lock too.
Fixes: 8cb775bc0a34 ("ppp: fix device unregistration upon netns deletion")
Reported-and-tested-by: syzbot+367889b9c9e279219175@syzkaller.appspotmail.com
Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
---
drivers/net/ppp/ppp_generic.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
index d8e5747ff4e3..264d4af0bf69 100644
--- a/drivers/net/ppp/ppp_generic.c
+++ b/drivers/net/ppp/ppp_generic.c
@@ -1006,17 +1006,18 @@ static int ppp_unit_register(struct ppp *ppp, int unit, bool ifname_is_set)
if (!ifname_is_set)
snprintf(ppp->dev->name, IFNAMSIZ, "ppp%i", ppp->file.index);
+ mutex_unlock(&pn->all_ppp_mutex);
+
ret = register_netdevice(ppp->dev);
if (ret < 0)
goto err_unit;
atomic_inc(&ppp_unit_count);
- mutex_unlock(&pn->all_ppp_mutex);
-
return 0;
err_unit:
+ mutex_lock(&pn->all_ppp_mutex);
unit_put(&pn->units_idr, ppp->file.index);
err:
mutex_unlock(&pn->all_ppp_mutex);
--
2.15.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net] ppp: unlock all_ppp_mutex before registering device
2018-01-10 15:24 [PATCH net] ppp: unlock all_ppp_mutex before registering device Guillaume Nault
@ 2018-01-15 18:23 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2018-01-15 18:23 UTC (permalink / raw)
To: g.nault; +Cc: netdev, paulus, syzkaller-bugs
From: Guillaume Nault <g.nault@alphalink.fr>
Date: Wed, 10 Jan 2018 16:24:45 +0100
> ppp_dev_uninit(), which is the .ndo_uninit() handler of PPP devices,
> needs to lock pn->all_ppp_mutex. Therefore we mustn't call
> register_netdevice() with pn->all_ppp_mutex already locked, or we'd
> deadlock in case register_netdevice() fails and calls .ndo_uninit().
>
> Fortunately, we can unlock pn->all_ppp_mutex before calling
> register_netdevice(). This lock protects pn->units_idr, which isn't
> used in the device registration process.
>
> However, keeping pn->all_ppp_mutex locked during device registration
> did ensure that no device in transient state would be published in
> pn->units_idr. In practice, unlocking it before calling
> register_netdevice() doesn't change this property: ppp_unit_register()
> is called with 'ppp_mutex' locked and all searches done in
> pn->units_idr hold this lock too.
>
> Fixes: 8cb775bc0a34 ("ppp: fix device unregistration upon netns deletion")
> Reported-and-tested-by: syzbot+367889b9c9e279219175@syzkaller.appspotmail.com
> Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
Applied and queued up for -stable, thank you.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-01-15 18:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-10 15:24 [PATCH net] ppp: unlock all_ppp_mutex before registering device Guillaume Nault
2018-01-15 18:23 ` 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).