Linux-Fsdevel Archive on lore.kernel.org
 help / color / Atom feed
From: Casey Schaufler <casey@schaufler-ca.com>
To: Ondrej Mosnacek <omosnace@redhat.com>, Tejun Heo <tj@kernel.org>
Cc: 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: Thu, 31 Jan 2019 08:39:02 -0800
Message-ID: <ebe3c70e-2bde-9fca-bb05-b46173e09b69@schaufler-ca.com> (raw)
In-Reply-To: <CAFqZXNt0jNg2-bNbtsCX2=7bcb_GaxCnHfSyck=GksXBTkWJ-g@mail.gmail.com>

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.

> 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.
>

  parent reply index

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 [this message]
2019-02-04  9:48         ` Ondrej Mosnacek

Reply instructions:

You may reply publically 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=ebe3c70e-2bde-9fca-bb05-b46173e09b69@schaufler-ca.com \
    --to=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=omosnace@redhat.com \
    --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

Linux-Fsdevel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-fsdevel/0 linux-fsdevel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-fsdevel linux-fsdevel/ https://lore.kernel.org/linux-fsdevel \
		linux-fsdevel@vger.kernel.org linux-fsdevel@archiver.kernel.org
	public-inbox-index linux-fsdevel


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-fsdevel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox