* re: cgroup: introduce cgroup namespaces @ 2016-02-17 18:58 Dan Carpenter 2016-02-18 16:46 ` [PATCH cgroup/for-4.5-fixes] cgroup: fix alloc_cgroup_ns() error handling in copy_cgroup_ns() Tejun Heo 0 siblings, 1 reply; 9+ messages in thread From: Dan Carpenter @ 2016-02-17 18:58 UTC (permalink / raw) To: adityakali-hpIqsD4AKlfQT0dZR+AlfA; +Cc: cgroups-u79uwXL29TY76Z2rM5mHXA Hello Aditya Kali, The patch a79a908fd2b0: "cgroup: introduce cgroup namespaces" from Jan 29, 2016, leads to the following static checker warning: kernel/cgroup.c:6091 copy_cgroup_ns() error: 'new_ns' dereferencing possible ERR_PTR() kernel/cgroup.c 6085 6086 err = -ENOMEM; 6087 new_ns = alloc_cgroup_ns(); 6088 if (!new_ns) ^^^^^^^ This should be an IS_ERR() check. 6089 goto err_out; 6090 6091 new_ns->user_ns = get_user_ns(user_ns); regards, dan carpenter ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH cgroup/for-4.5-fixes] cgroup: fix alloc_cgroup_ns() error handling in copy_cgroup_ns() 2016-02-17 18:58 cgroup: introduce cgroup namespaces Dan Carpenter @ 2016-02-18 16:46 ` Tejun Heo [not found] ` <20160218164658.GD13177-qYNAdHglDFBN0TnZuCh8vA@public.gmane.org> 0 siblings, 1 reply; 9+ messages in thread From: Tejun Heo @ 2016-02-18 16:46 UTC (permalink / raw) To: Dan Carpenter Cc: adityakali-hpIqsD4AKlfQT0dZR+AlfA, cgroups-u79uwXL29TY76Z2rM5mHXA From d22025570e2ebfc68819b35c5d457e53d9337217 Mon Sep 17 00:00:00 2001 From: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> Date: Thu, 18 Feb 2016 11:44:24 -0500 alloc_cgroup_ns() returns an ERR_PTR value on error but copy_cgroup_ns() was checking for NULL for error. Fix it. Signed-off-by: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> Reported-by: Dan Carpenter <dan.carpenter-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org> --- Hello, Dan. Applied to cgroup/for-4.5-fixes. Thanks. kernel/cgroup.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel/cgroup.c b/kernel/cgroup.c index afb1205..d92d91a 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c @@ -6083,10 +6083,11 @@ struct cgroup_namespace *copy_cgroup_ns(unsigned long flags, spin_unlock_bh(&css_set_lock); mutex_unlock(&cgroup_mutex); - err = -ENOMEM; new_ns = alloc_cgroup_ns(); - if (!new_ns) + if (IS_ERR(new_ns)) { + err = PTR_ERR(new_ns); goto err_out; + } new_ns->user_ns = get_user_ns(user_ns); new_ns->root_cset = cset; -- 2.5.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
[parent not found: <20160218164658.GD13177-qYNAdHglDFBN0TnZuCh8vA@public.gmane.org>]
* Re: [PATCH cgroup/for-4.5-fixes] cgroup: fix alloc_cgroup_ns() error handling in copy_cgroup_ns() [not found] ` <20160218164658.GD13177-qYNAdHglDFBN0TnZuCh8vA@public.gmane.org> @ 2016-02-18 16:57 ` Aditya Kali 2016-02-18 20:21 ` Dan Carpenter 1 sibling, 0 replies; 9+ messages in thread From: Aditya Kali @ 2016-02-18 16:57 UTC (permalink / raw) To: Tejun Heo; +Cc: Dan Carpenter, cgroups mailinglist Thanks for catching. On Thu, Feb 18, 2016 at 8:46 AM, Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> wrote: > From d22025570e2ebfc68819b35c5d457e53d9337217 Mon Sep 17 00:00:00 2001 > From: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> > Date: Thu, 18 Feb 2016 11:44:24 -0500 > > alloc_cgroup_ns() returns an ERR_PTR value on error but > copy_cgroup_ns() was checking for NULL for error. Fix it. > > Signed-off-by: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> > Reported-by: Dan Carpenter <dan.carpenter-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org> Acked-by: Aditya Kali (adityakali-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org) > --- > Hello, Dan. > > Applied to cgroup/for-4.5-fixes. > > Thanks. > > kernel/cgroup.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/kernel/cgroup.c b/kernel/cgroup.c > index afb1205..d92d91a 100644 > --- a/kernel/cgroup.c > +++ b/kernel/cgroup.c > @@ -6083,10 +6083,11 @@ struct cgroup_namespace *copy_cgroup_ns(unsigned long flags, > spin_unlock_bh(&css_set_lock); > mutex_unlock(&cgroup_mutex); > > - err = -ENOMEM; > new_ns = alloc_cgroup_ns(); > - if (!new_ns) > + if (IS_ERR(new_ns)) { > + err = PTR_ERR(new_ns); > goto err_out; > + } > > new_ns->user_ns = get_user_ns(user_ns); > new_ns->root_cset = cset; > -- > 2.5.0 > -- Aditya ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH cgroup/for-4.5-fixes] cgroup: fix alloc_cgroup_ns() error handling in copy_cgroup_ns() [not found] ` <20160218164658.GD13177-qYNAdHglDFBN0TnZuCh8vA@public.gmane.org> 2016-02-18 16:57 ` Aditya Kali @ 2016-02-18 20:21 ` Dan Carpenter 2016-02-18 20:26 ` Tejun Heo 1 sibling, 1 reply; 9+ messages in thread From: Dan Carpenter @ 2016-02-18 20:21 UTC (permalink / raw) To: Tejun Heo Cc: adityakali-hpIqsD4AKlfQT0dZR+AlfA, cgroups-u79uwXL29TY76Z2rM5mHXA Sorry, I was feeling like a jerk yesterday. I obviously could have fixed this myself but I wanted to make a point about one error label, do-everything style "future proof" error handling. It is a trap for the unwary. Now the code calls kfree(-ENOMEM). It's a very predictable mistake. regards, dan carpenter ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH cgroup/for-4.5-fixes] cgroup: fix alloc_cgroup_ns() error handling in copy_cgroup_ns() 2016-02-18 20:21 ` Dan Carpenter @ 2016-02-18 20:26 ` Tejun Heo [not found] ` <20160218202650.GH13177-qYNAdHglDFBN0TnZuCh8vA@public.gmane.org> 0 siblings, 1 reply; 9+ messages in thread From: Tejun Heo @ 2016-02-18 20:26 UTC (permalink / raw) To: Dan Carpenter Cc: adityakali-hpIqsD4AKlfQT0dZR+AlfA, cgroups-u79uwXL29TY76Z2rM5mHXA On Thu, Feb 18, 2016 at 11:21:12PM +0300, Dan Carpenter wrote: > Sorry, I was feeling like a jerk yesterday. > > I obviously could have fixed this myself but I wanted to make a point > about one error label, do-everything style "future proof" error > handling. It is a trap for the unwary. > > Now the code calls kfree(-ENOMEM). It's a very predictable mistake. lol let's take the chance and convert the NULL check in kfree() to IS_ERR_OR_NULL(). Seriously tho, I don't think this is a good evidence against merged error handling. It's not like we don't make repeated mistakes with split error labels. Anyways, care to submit a proper patch? Thanks. -- tejun ^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <20160218202650.GH13177-qYNAdHglDFBN0TnZuCh8vA@public.gmane.org>]
* Re: [PATCH cgroup/for-4.5-fixes] cgroup: fix alloc_cgroup_ns() error handling in copy_cgroup_ns() [not found] ` <20160218202650.GH13177-qYNAdHglDFBN0TnZuCh8vA@public.gmane.org> @ 2016-02-18 21:26 ` Dan Carpenter 2016-02-28 13:59 ` [PATCH cgroup/for-4.6-ns] cgroup: fix and restructure " Tejun Heo 0 siblings, 1 reply; 9+ messages in thread From: Dan Carpenter @ 2016-02-18 21:26 UTC (permalink / raw) To: Tejun Heo Cc: adityakali-hpIqsD4AKlfQT0dZR+AlfA, cgroups-u79uwXL29TY76Z2rM5mHXA I'm not sure what to write the patch against now. Can you just do this? regards, dan carpenter ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH cgroup/for-4.6-ns] cgroup: fix and restructure error handling in copy_cgroup_ns() 2016-02-18 21:26 ` Dan Carpenter @ 2016-02-28 13:59 ` Tejun Heo [not found] ` <20160228135933.GT3965-piEFEHQLUPpN0TnZuCh8vA@public.gmane.org> 0 siblings, 1 reply; 9+ messages in thread From: Tejun Heo @ 2016-02-28 13:59 UTC (permalink / raw) To: Serge Hallyn Cc: adityakali-hpIqsD4AKlfQT0dZR+AlfA, cgroups-u79uwXL29TY76Z2rM5mHXA, Dan Carpenter copy_cgroup_ns()'s error handling was broken and the attempt to fix it d22025570e2e ("cgroup: fix alloc_cgroup_ns() error handling in copy_cgroup_ns()") was broken too in that it ended up trying an ERR_PTR() value. There's only one place where copy_cgroup_ns() needs to perform cleanup after failure. Simplify and fix the error handling by removing the goto's. Signed-off-by: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> Reported-by: Dan Carpenter <dan.carpenter-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org> --- kernel/cgroup.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/kernel/cgroup.c b/kernel/cgroup.c index d92d91a..2c88149 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c @@ -6058,9 +6058,8 @@ struct cgroup_namespace *copy_cgroup_ns(unsigned long flags, struct user_namespace *user_ns, struct cgroup_namespace *old_ns) { - struct cgroup_namespace *new_ns = NULL; - struct css_set *cset = NULL; - int err; + struct cgroup_namespace *new_ns; + struct css_set *cset; BUG_ON(!old_ns); @@ -6070,9 +6069,8 @@ struct cgroup_namespace *copy_cgroup_ns(unsigned long flags, } /* Allow only sysadmin to create cgroup namespace. */ - err = -EPERM; if (!ns_capable(user_ns, CAP_SYS_ADMIN)) - goto err_out; + return ERR_PTR(-EPERM); mutex_lock(&cgroup_mutex); spin_lock_bh(&css_set_lock); @@ -6085,20 +6083,14 @@ struct cgroup_namespace *copy_cgroup_ns(unsigned long flags, new_ns = alloc_cgroup_ns(); if (IS_ERR(new_ns)) { - err = PTR_ERR(new_ns); - goto err_out; + put_css_set(cset); + return new_ns; } new_ns->user_ns = get_user_ns(user_ns); new_ns->root_cset = cset; return new_ns; - -err_out: - if (cset) - put_css_set(cset); - kfree(new_ns); - return ERR_PTR(err); } static inline struct cgroup_namespace *to_cg_ns(struct ns_common *ns) ^ permalink raw reply related [flat|nested] 9+ messages in thread
[parent not found: <20160228135933.GT3965-piEFEHQLUPpN0TnZuCh8vA@public.gmane.org>]
* Re: [PATCH cgroup/for-4.6-ns] cgroup: fix and restructure error handling in copy_cgroup_ns() [not found] ` <20160228135933.GT3965-piEFEHQLUPpN0TnZuCh8vA@public.gmane.org> @ 2016-02-29 8:50 ` Serge Hallyn 2016-02-29 21:23 ` Tejun Heo 0 siblings, 1 reply; 9+ messages in thread From: Serge Hallyn @ 2016-02-29 8:50 UTC (permalink / raw) To: Tejun Heo Cc: adityakali-hpIqsD4AKlfQT0dZR+AlfA, cgroups-u79uwXL29TY76Z2rM5mHXA, Dan Carpenter Quoting Tejun Heo (tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org): > copy_cgroup_ns()'s error handling was broken and the attempt to fix it > d22025570e2e ("cgroup: fix alloc_cgroup_ns() error handling in > copy_cgroup_ns()") was broken too in that it ended up trying an > ERR_PTR() value. > > There's only one place where copy_cgroup_ns() needs to perform cleanup > after failure. Simplify and fix the error handling by removing the > goto's. > > Signed-off-by: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> > Reported-by: Dan Carpenter <dan.carpenter-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org> It certainly looks cleaner, thanks. Acked-by: Serge E. Hallyn <serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org> > --- > kernel/cgroup.c | 18 +++++------------- > 1 file changed, 5 insertions(+), 13 deletions(-) > > diff --git a/kernel/cgroup.c b/kernel/cgroup.c > index d92d91a..2c88149 100644 > --- a/kernel/cgroup.c > +++ b/kernel/cgroup.c > @@ -6058,9 +6058,8 @@ struct cgroup_namespace *copy_cgroup_ns(unsigned long flags, > struct user_namespace *user_ns, > struct cgroup_namespace *old_ns) > { > - struct cgroup_namespace *new_ns = NULL; > - struct css_set *cset = NULL; > - int err; > + struct cgroup_namespace *new_ns; > + struct css_set *cset; > > BUG_ON(!old_ns); > > @@ -6070,9 +6069,8 @@ struct cgroup_namespace *copy_cgroup_ns(unsigned long flags, > } > > /* Allow only sysadmin to create cgroup namespace. */ > - err = -EPERM; > if (!ns_capable(user_ns, CAP_SYS_ADMIN)) > - goto err_out; > + return ERR_PTR(-EPERM); > > mutex_lock(&cgroup_mutex); > spin_lock_bh(&css_set_lock); > @@ -6085,20 +6083,14 @@ struct cgroup_namespace *copy_cgroup_ns(unsigned long flags, > > new_ns = alloc_cgroup_ns(); > if (IS_ERR(new_ns)) { > - err = PTR_ERR(new_ns); > - goto err_out; > + put_css_set(cset); > + return new_ns; > } > > new_ns->user_ns = get_user_ns(user_ns); > new_ns->root_cset = cset; > > return new_ns; > - > -err_out: > - if (cset) > - put_css_set(cset); > - kfree(new_ns); > - return ERR_PTR(err); > } > > static inline struct cgroup_namespace *to_cg_ns(struct ns_common *ns) ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH cgroup/for-4.6-ns] cgroup: fix and restructure error handling in copy_cgroup_ns() 2016-02-29 8:50 ` Serge Hallyn @ 2016-02-29 21:23 ` Tejun Heo 0 siblings, 0 replies; 9+ messages in thread From: Tejun Heo @ 2016-02-29 21:23 UTC (permalink / raw) To: Serge Hallyn Cc: adityakali-hpIqsD4AKlfQT0dZR+AlfA, cgroups-u79uwXL29TY76Z2rM5mHXA, Dan Carpenter On Mon, Feb 29, 2016 at 08:50:00AM +0000, Serge Hallyn wrote: > Quoting Tejun Heo (tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org): > > copy_cgroup_ns()'s error handling was broken and the attempt to fix it > > d22025570e2e ("cgroup: fix alloc_cgroup_ns() error handling in > > copy_cgroup_ns()") was broken too in that it ended up trying an > > ERR_PTR() value. > > > > There's only one place where copy_cgroup_ns() needs to perform cleanup > > after failure. Simplify and fix the error handling by removing the > > goto's. > > > > Signed-off-by: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> > > Reported-by: Dan Carpenter <dan.carpenter-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org> > > It certainly looks cleaner, thanks. > > Acked-by: Serge E. Hallyn <serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org> Applied to cgroup/for-4.6-ns. Thanks. -- tejun ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2016-02-29 21:23 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2016-02-17 18:58 cgroup: introduce cgroup namespaces Dan Carpenter 2016-02-18 16:46 ` [PATCH cgroup/for-4.5-fixes] cgroup: fix alloc_cgroup_ns() error handling in copy_cgroup_ns() Tejun Heo [not found] ` <20160218164658.GD13177-qYNAdHglDFBN0TnZuCh8vA@public.gmane.org> 2016-02-18 16:57 ` Aditya Kali 2016-02-18 20:21 ` Dan Carpenter 2016-02-18 20:26 ` Tejun Heo [not found] ` <20160218202650.GH13177-qYNAdHglDFBN0TnZuCh8vA@public.gmane.org> 2016-02-18 21:26 ` Dan Carpenter 2016-02-28 13:59 ` [PATCH cgroup/for-4.6-ns] cgroup: fix and restructure " Tejun Heo [not found] ` <20160228135933.GT3965-piEFEHQLUPpN0TnZuCh8vA@public.gmane.org> 2016-02-29 8:50 ` Serge Hallyn 2016-02-29 21:23 ` Tejun Heo
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).