[RHEL8,COMMIT] ve/net: don't use RCU read lock in ve_dev_can_rename()

Submitted by Konstantin Khorenko on April 8, 2019, 3:44 p.m.

Details

Message ID 201904081544.x38FidU3020004@finist_el8beta.work.ct
State New
Series "connector: avoid RCU read-side critical section in cn_init_ve()"
Headers show

Commit Message

Konstantin Khorenko April 8, 2019, 3:44 p.m.
The commit is pushed to "branch-rh8-4.18.0-32.vz8.1.x" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-32.el8
------>
commit 5b71c68a2f2b4927215f4ade4916a8d75d1eb014
Author: Konstantin Khorenko <khorenko@virtuozzo.com>
Date:   Mon Apr 8 15:27:05 2019 +0300

    ve/net: don't use RCU read lock in ve_dev_can_rename()
    
    rcu_read_lock()/unlock won't help here anyway:
    "can" value can change right after rcu lock is dropped.
    
    Fixes: 13bed5e31b7c ("ve/net: allow to rename devices in non-ve
    namespaces")
    https://jira.sw.ru/browse/PSBM-93640
    
    Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
 net/core/dev.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/net/core/dev.c b/net/core/dev.c
index 29b0ebaeefe9..c7f317de17b8 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1170,9 +1170,12 @@  static bool ve_dev_can_rename(struct net_device *dev)
 	struct net *net;
 	bool can;
 
-	net = ve_net_lock(dev_net(dev)->owner_ve);
+	/*
+	 * rcu_read_lock()/unlock won't help here anyway:
+	 * "can" value can change right after rcu lock is dropped.
+	 */
+	net = rcu_dereference(dev_net(dev)->owner_ve->ve_ns)->net_ns;
 	can = !net || net == dev_net(dev);
-	ve_net_unlock(dev_net(dev)->owner_ve);
 	return can;
 }