stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Masami Ichikawa <masami256@gmail.com>
To: "Michal Koutný" <mkoutny@suse.com>
Cc: cip-dev@lists.cip-project.org,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	Tabitha Sable <tabitha.c.sable@gmail.com>,
	stable@vger.kernel.org, Tejun Heo <tj@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Masami Ichikawa <masami.ichikawa@cybertrust.co.jp>
Subject: Re: [PATCH for 4.4.y-cip] cgroup-v1: Require capabilities to set release_agent
Date: Thu, 17 Feb 2022 11:17:27 +0900	[thread overview]
Message-ID: <CACOXgS8gpd+V=+iO5WnCXMuQakBMokTrwKfgp7TaC+D41SLc8w@mail.gmail.com> (raw)
In-Reply-To: <20220216121142.GB30035@blackbody.suse.cz>

On Wed, Feb 16, 2022 at 9:11 PM Michal Koutný <mkoutny@suse.com> wrote:
>
> Thanks for sharing this Masami, I've been looking into pre-cgroup_ns
> backport too.
>

Thank you for the review.

> On Wed, Feb 16, 2022 at 08:40:37AM +0900, Masami Ichikawa <masami256@gmail.com> wrote:
> > [masami: Backport patch from 4.9. Adjust to use current_user_ns() to get current user_ns.
> > Fix conflict in cgroup_release_agent_write().]
>
> The condition to allow modifying release_agent is two-fold:
> a) caller is capabable(CAP_SYS_ADMIN),
> b) cgroup_ns is owned by init_user_ns.
>
> In pre-cgroup_ns kernels, it is IMO safer to consider all (=the only)
> cgroup_ns owned by init_user_ns.
>
> So the (positive) condition translates into capable(CAP_SYS_ADMIN) only.
>

I see.  Thank you for the details.
If we treat cgroup_ns as only cgroup_ns that are owned by
init_user_ns,  we don't have to have an extra check.

> [
> Additionally, there's invariant/implication
>   capable(CAP_XXX) -> (current_user_ns() == &init_user_ns) ,
> so the expression
>   (current_user_ns() != &init_user_ns) || !capable(CAP_SYS_ADMIN)
> simplifies to
>   !capable(CAP_SYS_ADMIN) .
> ]
>
>
> > @@ -2839,6 +2856,14 @@ static ssize_t cgroup_release_agent_write(struct kernfs_open_file *of,
> >
> >       BUILD_BUG_ON(sizeof(cgrp->root->release_agent_path) < PATH_MAX);
> >
> > +     /*
> > +      * Release agent gets called with all capabilities,
> > +      * require capabilities to set release agent.
> > +      */
> > +     if ((of->file->f_cred->user_ns != &init_user_ns) ||
> > +             !capable(CAP_SYS_ADMIN))
> > +                     return -EPERM;
> > +
>
> Following the reasoning above, the check simplifies too but it should be
> be against the opener, not the writer:
>   file_ns_capable(of->file, &init_user_ns, CAP_SYS_ADMIN)
>

Thanks. I got it.

> (It seems to be to be incorrect even in the original commit.
> So I'll send a patch there to rectify that.)
>
>
> Michal
>
>

Regards,
-- 
/**
* Masami Ichikawa
* personal: masami256@gmail.com
* fedora project: masami@fedoraproject.org
*/

      reply	other threads:[~2022-02-17  2:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-15 23:40 [PATCH for 4.4.y-cip] cgroup-v1: Require capabilities to set release_agent Masami Ichikawa
2022-02-16 12:11 ` Michal Koutný
2022-02-17  2:17   ` Masami Ichikawa [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CACOXgS8gpd+V=+iO5WnCXMuQakBMokTrwKfgp7TaC+D41SLc8w@mail.gmail.com' \
    --to=masami256@gmail.com \
    --cc=cip-dev@lists.cip-project.org \
    --cc=ebiederm@xmission.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=masami.ichikawa@cybertrust.co.jp \
    --cc=mkoutny@suse.com \
    --cc=stable@vger.kernel.org \
    --cc=tabitha.c.sable@gmail.com \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).