[1/3,v2,RHEL7] ve/cgroup: change resource release order in ve_drop_context

Submitted by Valeriy Vdovin on Oct. 29, 2020, 11 a.m.

Details

Message ID 1603969246-958334-2-git-send-email-valeriy.vdovin@virtuozzo.com
State New
Series "cgroup: do not use cgroup_mutex in cgroup_show_options"
Headers show

Commit Message

Valeriy Vdovin Oct. 29, 2020, 11 a.m.
This fixes 87cb5fdb5b5c77ac617b46a0fe118a7d50a77b1c
In the mentioned patch in cgroup_show_options ve->ve_ns is checked to
ensure that ve->root_css_set is usable. But in ve_drop_context
root_css_set is being released before ve_ns, which is a bug.
root_css_set will now be set to NULL after ve_ns is released.
This reordering only affects the described piece of code in
cgroup_show_options.

https://jira.sw.ru/browse/PSBM-121438

Signed-off-by: Valeriy Vdovin <valeriy.vdovin@virtuozzo.com>
---
 kernel/ve/ve.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
index db26cbd4..f61b1fe 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -595,9 +595,6 @@  static void ve_drop_context(struct ve_struct *ve)
 	struct nsproxy *ve_ns = ve->ve_ns;
 	struct net *net = ve->ve_netns;
 
-	put_css_set_taskexit(ve->root_css_set);
-	ve->root_css_set = NULL;
-
 	ve->ve_netns = NULL;
 	put_net(net);
 
@@ -606,6 +603,9 @@  static void ve_drop_context(struct ve_struct *ve)
 	synchronize_rcu();
 	put_nsproxy(ve_ns);
 
+	put_css_set_taskexit(ve->root_css_set);
+	ve->root_css_set = NULL;
+
 	ve_hook_iterate_fini(VE_SHUTDOWN_CHAIN, ve);
 
 	put_cred(ve->init_cred);

Comments

Kirill Tkhai Oct. 29, 2020, 11:10 a.m.
On 29.10.2020 14:00, Valeriy Vdovin wrote:
> This fixes 87cb5fdb5b5c77ac617b46a0fe118a7d50a77b1c
> In the mentioned patch in cgroup_show_options ve->ve_ns is checked to
> ensure that ve->root_css_set is usable. But in ve_drop_context
> root_css_set is being released before ve_ns, which is a bug.
> root_css_set will now be set to NULL after ve_ns is released.
> This reordering only affects the described piece of code in
> cgroup_show_options.
> 
> https://jira.sw.ru/browse/PSBM-121438
> 
> Signed-off-by: Valeriy Vdovin <valeriy.vdovin@virtuozzo.com>

Reviewed-by: Kirill Tkhai <ktkhai@virtuozzo.com>

> ---
>  kernel/ve/ve.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
> index db26cbd4..f61b1fe 100644
> --- a/kernel/ve/ve.c
> +++ b/kernel/ve/ve.c
> @@ -595,9 +595,6 @@ static void ve_drop_context(struct ve_struct *ve)
>  	struct nsproxy *ve_ns = ve->ve_ns;
>  	struct net *net = ve->ve_netns;
>  
> -	put_css_set_taskexit(ve->root_css_set);
> -	ve->root_css_set = NULL;
> -
>  	ve->ve_netns = NULL;
>  	put_net(net);
>  
> @@ -606,6 +603,9 @@ static void ve_drop_context(struct ve_struct *ve)
>  	synchronize_rcu();
>  	put_nsproxy(ve_ns);
>  
> +	put_css_set_taskexit(ve->root_css_set);
> +	ve->root_css_set = NULL;
> +
>  	ve_hook_iterate_fini(VE_SHUTDOWN_CHAIN, ve);
>  
>  	put_cred(ve->init_cred);
>