[PATCH net-next] net: core: fix the order in dev_put() and rtnl_lock()

Subsystems: networking [general], the rest

STALE1794d

3 messages, 3 authors, 2021-09-14 · open the first message on its own page

[PATCH net-next] net: core: fix the order in dev_put() and rtnl_lock()

From: Yajun Deng <hidden>
Date: 2021-09-14 03:02:11

The dev_put() should be after rtnl_lock() in case for race.

Fixes: 893b19587534 ("net: bridge: fix ioctl locking")
Signed-off-by: Yajun Deng <redacted>
---
 net/core/dev_ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
index 0e87237fd871..9796fa35fe88 100644
--- a/net/core/dev_ioctl.c
+++ b/net/core/dev_ioctl.c
@@ -384,8 +384,8 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, void __user *data,
 		dev_hold(dev);
 		rtnl_unlock();
 		err = br_ioctl_call(net, netdev_priv(dev), cmd, ifr, NULL);
-		dev_put(dev);
 		rtnl_lock();
+		dev_put(dev);
 		return err;
 
 	case SIOCSHWTSTAMP:
-- 
2.32.0

Re: [PATCH net-next] net: core: fix the order in dev_put() and rtnl_lock()

From: Eric Dumazet <hidden>
Date: 2021-09-14 05:18:18


On 9/13/21 8:01 PM, Yajun Deng wrote:
quoted hunk
The dev_put() should be after rtnl_lock() in case for race.

Fixes: 893b19587534 ("net: bridge: fix ioctl locking")
Signed-off-by: Yajun Deng <redacted>
---
 net/core/dev_ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
index 0e87237fd871..9796fa35fe88 100644
--- a/net/core/dev_ioctl.c
+++ b/net/core/dev_ioctl.c
@@ -384,8 +384,8 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, void __user *data,
 		dev_hold(dev);
 		rtnl_unlock();
 		err = br_ioctl_call(net, netdev_priv(dev), cmd, ifr, NULL);
-		dev_put(dev);
 		rtnl_lock();
+		dev_put(dev);
 		return err;
 
 	case SIOCSHWTSTAMP:
What race exactly are you trying to avoid ?

This patch does not look needed to me.

Re: [PATCH net-next] net: core: fix the order in dev_put() and rtnl_lock()

From: Nikolay Aleksandrov <hidden>
Date: 2021-09-14 07:53:07

On 14/09/2021 08:18, Eric Dumazet wrote:

On 9/13/21 8:01 PM, Yajun Deng wrote:
quoted
The dev_put() should be after rtnl_lock() in case for race.

Fixes: 893b19587534 ("net: bridge: fix ioctl locking")
Signed-off-by: Yajun Deng <redacted>
---
 net/core/dev_ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
index 0e87237fd871..9796fa35fe88 100644
--- a/net/core/dev_ioctl.c
+++ b/net/core/dev_ioctl.c
@@ -384,8 +384,8 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, void __user *data,
 		dev_hold(dev);
 		rtnl_unlock();
 		err = br_ioctl_call(net, netdev_priv(dev), cmd, ifr, NULL);
-		dev_put(dev);
 		rtnl_lock();
+		dev_put(dev);
 		return err;
 
 	case SIOCSHWTSTAMP:
What race exactly are you trying to avoid ?

This patch does not look needed to me.
+1 

There isn't a race there
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help