[RHEL7,COMMIT] vznetstat: Add protection to venet_acct_set_classes()

Submitted by Konstantin Khorenko on Dec. 20, 2017, 9:47 a.m.

Details

Message ID 201712200947.vBK9lE6E030051@finist_ce7.work
State New
Series "Series without cover letter"
Headers show

Commit Message

Konstantin Khorenko Dec. 20, 2017, 9:47 a.m.
The commit is pushed to "branch-rh7-3.10.0-693.11.1.vz7.39.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-693.11.1.vz7.39.8
------>
commit 68c9f986a45fa08c2f2d3fdb57f23239581c7213
Author: Kirill Tkhai <ktkhai@virtuozzo.com>
Date:   Wed Dec 20 12:47:14 2017 +0300

    vznetstat: Add protection to venet_acct_set_classes()
    
    It seems there was no synchronization since the time
    when ioctls in kernel were serialized via single mutex.
    
    Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
    Acked-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
---
 kernel/ve/vznetstat/vznetstat.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

Patch hide | download patch | download mbox

diff --git a/kernel/ve/vznetstat/vznetstat.c b/kernel/ve/vznetstat/vznetstat.c
index 3a53ce27bde2..92541dbc2a3f 100644
--- a/kernel/ve/vznetstat/vznetstat.c
+++ b/kernel/ve/vznetstat/vznetstat.c
@@ -88,15 +88,11 @@  static int venet_acct_set_classes(const void __user *user_info, int length, int
 			goto out_free;
 	}
 
-	rcu_read_lock();
-	if (v6) {
-		old = rcu_dereference(info_v6);
-		rcu_assign_pointer(info_v6, info);
-	} else {
-		old = rcu_dereference(info_v4);
-		rcu_assign_pointer(info_v4, info);
-	}
-	rcu_read_unlock();
+	if (v6)
+		old = xchg(&info_v6, info);
+	else
+		old = xchg(&info_v4, info);
+	/* xchg() implies rcu_assign_pointer() barriers */
 
 	synchronize_net();
 	/* IMPORTANT. I think reset of statistics collected should not be