selinux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ondrej Mosnacek <omosnace@redhat.com>
To: Casey Schaufler <casey@schaufler-ca.com>
Cc: Tejun Heo <tj@kernel.org>,
	selinux@vger.kernel.org, Paul Moore <paul@paul-moore.com>,
	Stephen Smalley <sds@tycho.nsa.gov>,
	Linux Security Module list 
	<linux-security-module@vger.kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-fsdevel@vger.kernel.org, cgroups@vger.kernel.org
Subject: Re: [PATCH v3 5/5] kernfs: initialize security of newly created nodes
Date: Mon, 4 Feb 2019 10:48:35 +0100	[thread overview]
Message-ID: <CAFqZXNuGUE4oq-=PK9mb=9V5wiETQR4UHYs5XF44-aWoZRrqdg@mail.gmail.com> (raw)
In-Reply-To: <ebe3c70e-2bde-9fca-bb05-b46173e09b69@schaufler-ca.com>

On Thu, Jan 31, 2019 at 5:39 PM Casey Schaufler <casey@schaufler-ca.com> wrote:
> On 1/31/2019 2:20 AM, Ondrej Mosnacek wrote:
> > Hi Tejun,
> >
> > On Wed, Jan 30, 2019 at 6:09 PM Tejun Heo <tj@kernel.org> wrote:
> >> Hello,
> >>
> >> On Wed, Jan 30, 2019 at 12:41:50PM +0100, Ondrej Mosnacek wrote:
> >>> @@ -673,6 +698,12 @@ static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root,
> >>>                       goto err_out3;
> >>>       }
> >>>
> >>> +     if (parent) {
> >>> +             ret = kernfs_node_init_security(parent, kn);
> >>> +             if (ret)
> >>> +                     goto err_out3;
> >>> +     }
> >> So, doing this unconditionally isn't a good idea.  kernfs doesn't use
> >> the usual dentry/inode because there are machines with 6, even 7 digit
> >> number of kernfs nodes and some of them even failed to boot due to
> >> memory shortage.  Please don't blow it up by default.
> > Hm, I see... basically the only thing that gets allocated in
> > kernfs_node_init_security() by default (at least under SELinux/ no
> > LSM) is the kernfs_iattrs structures, so I assume you are pointing at
> > that. I think this can be easily fixed, if we again use the assumption
> > that whenever the parent node has only default attributes
> > (parent->iattrs == NULL), then the child node should also have just
> > default attributes (and so we don't need to call kernfs_iattrs() on it
> > nor call the security hook). Something along these lines:
> >
> > [...]
> > +static int kernfs_node_init_security(struct kernfs_node *parent,
> > +                                    struct kernfs_node *kn)
> > +{
> > +       struct kernfs_iattrs *attrs, *pattrs;
> > +       struct qstr q;
> > +
> > +       pattrs = parent->iattrs;
> > +       if (!pattrs)
> > +               return 0;
> > +
> > +       attrs = kernfs_iattrs(kn);
> > +       if (!attrs)
> > +               return -ENOMEM;
> > +
> > +       q.name = kn->name;
> > +       q.hash_len = hashlen_string(parent, kn->name);
> > [...]
> >
> > Technically this might make some LSMs unhappy, if they want to set
> > some non-default context even if parent is all default,
>
> The only possibility I see as a potential problem is a kernfs
> mounted with the smackfstransmute=Something option. This sets
> the security.SMACK64 to "Something" and the security.SMACK64TRANSMUTE
> to true on the root node. But that doesn't seem like a rational
> thing to do for a kernfs based filesystem.

Actually... I am now experimenting with a slightly different
kernfs_node_init_security() implementation that should allow for
calling the hook every time and only allocating kernfs_iattrs when it
detects that the hook actually did add some security xattrs. It is
somewhat more hacky and complex, but it should provide the best
possible compromise. I will post it for review soon.

>
> > but this is
> > already impossible now and in this case I think we have no better
> > choice than sacrificing a bit of flexibility for memory efficiency,
> > which is apparently critical here.
> >
> > Tejun, Casey, would the above modification be fine with you?
>
> I *think so*, but I can't say 100% that I really understand the
> entire issue.
>
> >
> > --
> > Ondrej Mosnacek <omosnace at redhat dot com>
> > Associate Software Engineer, Security Technologies
> > Red Hat, Inc.
> >

-- 
Ondrej Mosnacek <omosnace at redhat dot com>
Associate Software Engineer, Security Technologies
Red Hat, Inc.

      reply	other threads:[~2019-02-04  9:48 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-30 11:41 [PATCH v3 0/5] Allow initializing the kernfs node's secctx based on its parent Ondrej Mosnacek
2019-01-30 11:41 ` [PATCH v3 1/5] selinux: try security xattr after genfs for kernfs filesystems Ondrej Mosnacek
2019-01-30 11:41 ` [PATCH v3 2/5] kernfs: use simple_xattrs for security attributes Ondrej Mosnacek
2019-01-30 11:41 ` [PATCH v3 3/5] LSM: add new hook for kernfs node initialization Ondrej Mosnacek
2019-01-30 11:41 ` [PATCH v3 4/5] selinux: implement the kernfs_init_security hook Ondrej Mosnacek
2019-01-30 11:41 ` [PATCH v3 5/5] kernfs: initialize security of newly created nodes Ondrej Mosnacek
2019-01-30 17:09   ` Tejun Heo
2019-01-31 10:20     ` Ondrej Mosnacek
2019-01-31 14:22       ` Tejun Heo
2019-01-31 16:39       ` Casey Schaufler
2019-02-04  9:48         ` Ondrej Mosnacek [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='CAFqZXNuGUE4oq-=PK9mb=9V5wiETQR4UHYs5XF44-aWoZRrqdg@mail.gmail.com' \
    --to=omosnace@redhat.com \
    --cc=casey@schaufler-ca.com \
    --cc=cgroups@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=paul@paul-moore.com \
    --cc=sds@tycho.nsa.gov \
    --cc=selinux@vger.kernel.org \
    --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).