mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Casey Schaufler <casey@schaufler-ca.com>
To: Linus Torvalds <torvalds@linux-foundation.org>,
	Stephen Smalley <stephen.smalley.work@gmail.com>
Cc: "Jeffrey Vander Stoep" <jeffv@google.com>,
	"Thiébaud Weksteen" <tweek@google.com>,
	"Paul Moore" <paul@paul-moore.com>,
	"Cameron K. Williams" <ckwilliams.work@gmail.com>,
	"Kipp N. Davis" <kippndavis.work@gmx.com>,
	selinux@vger.kernel.org, linux-security-module@vger.kernel.org,
	linux-kernel@vger.kernel.org, "Nick Kralevich" <nnk@google.com>,
	"Kees Cook" <kees@kernel.org>,
	"Casey Schaufler" <casey@schaufler-ca.com>
Subject: Re: [GIT PULL] selinux/selinux-pr-20250323
Date: Fri, 28 Mar 2025 10:24:30 -0700	[thread overview]
Message-ID: <e8106dbb-7044-4ae0-9554-6eae857ba7d0@schaufler-ca.com> (raw)
In-Reply-To: <CAHk-=whoXr5GCHZsarzUKELLMAtcw0Qpmz_i+nenCVtBY1iBig@mail.gmail.com>

On 3/28/2025 9:36 AM, Linus Torvalds wrote:
> On Fri, 28 Mar 2025 at 06:23, Stephen Smalley
> <stephen.smalley.work@gmail.com> wrote:
>> Yes, thank you. I think it would be easy enough to make that change to
>> selinux_inode_permission() and to clear that inode flag on file
>> relabels (e.g. in selinux_inode_post_setxattr() and
>> inode_invalidate_secctx()).
> So the thing that *really* made me go "I don't know how to do this in
> the security layer" is not so much the relabeling - that should be
> easy to handle by just clearing the bit, as you say.
>
> And I wasn't even so much worried about policy changes that would
> globally change meaning of existing labels:
>
>> Not as sure about handling policy reloads
>> / boolean changes at runtime without also caching the policy sequence
>> number in the inode too so that can be compared.
> Yeah, a sequence number seems like an obvious solution, even if it
> might be a bit awkward to find a place to store it that doesn't
> pollute the cache. The reason it would be _so_ nice to not call the
> security hooks at all in this path is that I think we otherwise can do
> all the inode security lookups by just looking at the very beginning
> of the inode (that's why we do that IOP_FASTPERM thing - just to avoid
> touching other cachelines). But if it avoids the
> security_inode_permission() call, it would definitely be a win even
> with a cache miss.
>
>> Further, I'm unclear
>> on how to implement this in a manner that works with the LSM stacking
>> support,
> So *this* was what made me go "I don't know how to to this AT ALL",
> along with the fact that the rule for the bit would have to be that it
> would be true for *all* execution contexts.
>
> IOW, it's a very different thing from the usual security hook calls,
> in that instead of saying "is this access ok for the current context",
> the bit setting would have to say "this lookup is ok for _all_ calling
> contexts for this inode for _all_ of the nested security things".

That is correct. But the LSMs we currently have don't do frequent
attribute changes on objects and generally constrain process attribute
changes to exec() and administrative actions. Invalidating the lookup ok
flag when any LSM changes attributes is most likely to occur at a time
when all LSMs could be expected to change attributes.

> The sequence number approach should take care of any races, so that
> part isn't a huge problem: just set the inode sequence number early,
> before doing any of the checks. And then only set the bit at the end
> if every stacked security layer says "yeah, this inode doesn't have
> extra lookup rules as far as I'm concerned". So if any of the rules
> changed in the meantime, the sequence number means that the bit won't
> take effect. So that part should be fine.
>
> But the "this inode doesn't have extra lookup rules" part is what
> needs low-level knowledge about how all the security models work. And
> it really would have to be true in all contexts - ie across different
> namespaces etc.

It would be nice if changing the rules for one LSM (e.g. adding a
Smack access rule: # echo Snap Pop rw > /sys/fs/smackfs/load2) didn't
affect the lookup ok flag for other LSMs, but I don't see how the
overhead would be justified. I'm also concerned about how detecting
and clearing the flag on a single LSM case on policy change is going
to be anything but brutal.


  reply	other threads:[~2025-03-28 17:34 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-23 19:39 Paul Moore
2025-03-25 23:02 ` Linus Torvalds
2025-03-26 18:36   ` Paul Moore
2025-03-26 19:40     ` Linus Torvalds
2025-03-26 20:48       ` Paul Moore
2025-03-26 21:06         ` Linus Torvalds
2025-03-26 23:02           ` Paul Moore
2025-03-27  0:43             ` Linus Torvalds
2025-03-27  1:06               ` Thiébaud Weksteen
2025-03-27  1:20                 ` Linus Torvalds
2025-03-27  3:27                   ` Thiébaud Weksteen
2025-03-27  4:09                     ` Linus Torvalds
2025-03-27  8:59                       ` Jeffrey Vander Stoep
2025-03-27 15:49                         ` Linus Torvalds
2025-03-27 16:55                           ` Stephen Smalley
2025-03-27 18:15                             ` Linus Torvalds
2025-03-27 19:03                               ` Linus Torvalds
2025-03-27 19:16                                 ` Stephen Smalley
2025-03-27 19:40                                   ` Linus Torvalds
2025-03-28 13:23                                     ` Stephen Smalley
2025-03-28 15:06                                       ` Paul Moore
2025-04-02 20:38                                         ` Paul Moore
2025-03-28 16:36                                       ` Linus Torvalds
2025-03-28 17:24                                         ` Casey Schaufler [this message]
2025-03-27 16:41                         ` Casey Schaufler
2025-03-25 23:17 ` pr-tracker-bot

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=e8106dbb-7044-4ae0-9554-6eae857ba7d0@schaufler-ca.com \
    --to=casey@schaufler-ca.com \
    --cc=ckwilliams.work@gmail.com \
    --cc=jeffv@google.com \
    --cc=kees@kernel.org \
    --cc=kippndavis.work@gmx.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=nnk@google.com \
    --cc=paul@paul-moore.com \
    --cc=selinux@vger.kernel.org \
    --cc=stephen.smalley.work@gmail.com \
    --cc=torvalds@linux-foundation.org \
    --cc=tweek@google.com \
    /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

all inboxes | Powered by JetHome®