[RHEL7,COMMIT] ve: Reorder ve->ve_ns assignment in ve_grab_context()

Submitted by Vasily Averin on Nov. 10, 2020, 10:43 a.m.


Message ID 202011101043.0AAAhVpk010085@vz7build.vvs.sw.ru
State New
Series "ve: Reorder ve->ve_ns assignment in ve_grab_context()"
Headers show

Commit Message

Vasily Averin Nov. 10, 2020, 10:43 a.m.
The commit is pushed to "branch-rh7-3.10.0-1160.2.2.vz7.170.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1160.2.2.el7
commit e3f54fa771eb942f51e1a1260fbfd8d6ec2d5c75
Author: Kirill Tkhai <ktkhai@virtuozzo.com>
Date:   Tue Nov 10 13:43:31 2020 +0300

    ve: Reorder ve->ve_ns assignment in ve_grab_context()
    This function must provide guarantees for readers, that
    ve_ns != NULL under rcu_read_lock means the rest of context
    (say, ve->init_task) is table.
    But now order is wrong, and it does not guarantee that. Fix it.
    v2: Use local variable for ve_ns, otherwise net_ns write results
    in NULL pointer derefence.
    Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
 kernel/ve/ve.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
index 482d658..068b7b5 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -580,15 +580,18 @@  static void ve_stop_kthread(struct ve_struct *ve)
 static void ve_grab_context(struct ve_struct *ve)
 	struct task_struct *tsk = current;
+	struct nsproxy *ve_ns;
 	ve->init_task = tsk;
 	ve->root_css_set = tsk->cgroups;
 	ve->init_cred = (struct cred *)get_current_cred();
-	rcu_assign_pointer(ve->ve_ns, get_nsproxy(tsk->nsproxy));
-	ve->ve_netns =  get_net(ve->ve_ns->net_ns);
+	ve_ns = get_nsproxy(tsk->nsproxy);
+	ve->ve_netns =  get_net(ve_ns->net_ns);
+	rcu_assign_pointer(ve->ve_ns, ve_ns);
 static void ve_drop_context(struct ve_struct *ve)