From: Paul Moore <email@example.com> To: Ondrej Mosnacek <firstname.lastname@example.org> Cc: email@example.com, James Morris <firstname.lastname@example.org>, Steven Rostedt <email@example.com>, Ingo Molnar <firstname.lastname@example.org>, Steffen Klassert <email@example.com>, Herbert Xu <firstname.lastname@example.org>, "David S . Miller" <email@example.com>, Stephen Smalley <firstname.lastname@example.org>, email@example.com, firstname.lastname@example.org, email@example.com, firstname.lastname@example.org, email@example.com, firstname.lastname@example.org, email@example.com, firstname.lastname@example.org, email@example.com, firstname.lastname@example.org, email@example.com, firstname.lastname@example.org, email@example.com, firstname.lastname@example.org, Casey Schaufler <email@example.com>, Dan Williams <firstname.lastname@example.org> Subject: Re: [PATCH v4] lockdown,selinux: fix wrong subject in some SELinux lockdown checks Date: Thu, 23 Sep 2021 15:07:41 -0400 [thread overview] Message-ID: <CAHC9VhSzh90kFR8wzkmwR-YZNtHGAvYyATc2R1UDaBzZ944OFg@mail.gmail.com> (raw) In-Reply-To: <CAHC9VhQyejnmLn0NHQiWzikHs8ZdzAUdZ2WqNxgGM6xhJ4mvMQ@mail.gmail.com> On Wed, Sep 15, 2021 at 10:59 PM Paul Moore <email@example.com> wrote: > > On Mon, Sep 13, 2021 at 5:05 PM Paul Moore <firstname.lastname@example.org> wrote: > > > > On Mon, Sep 13, 2021 at 10:02 AM Ondrej Mosnacek <email@example.com> wrote: > > > > > > Commit 59438b46471a ("security,lockdown,selinux: implement SELinux > > > lockdown") added an implementation of the locked_down LSM hook to > > > SELinux, with the aim to restrict which domains are allowed to perform > > > operations that would breach lockdown. > > > > > > However, in several places the security_locked_down() hook is called in > > > situations where the current task isn't doing any action that would > > > directly breach lockdown, leading to SELinux checks that are basically > > > bogus. > > > > > > To fix this, add an explicit struct cred pointer argument to > > > security_lockdown() and define NULL as a special value to pass instead > > > of current_cred() in such situations. LSMs that take the subject > > > credentials into account can then fall back to some default or ignore > > > such calls altogether. In the SELinux lockdown hook implementation, use > > > SECINITSID_KERNEL in case the cred argument is NULL. > > > > > > Most of the callers are updated to pass current_cred() as the cred > > > pointer, thus maintaining the same behavior. The following callers are > > > modified to pass NULL as the cred pointer instead: > > > 1. arch/powerpc/xmon/xmon.c > > > Seems to be some interactive debugging facility. It appears that > > > the lockdown hook is called from interrupt context here, so it > > > should be more appropriate to request a global lockdown decision. > > > 2. fs/tracefs/inode.c:tracefs_create_file() > > > Here the call is used to prevent creating new tracefs entries when > > > the kernel is locked down. Assumes that locking down is one-way - > > > i.e. if the hook returns non-zero once, it will never return zero > > > again, thus no point in creating these files. Also, the hook is > > > often called by a module's init function when it is loaded by > > > userspace, where it doesn't make much sense to do a check against > > > the current task's creds, since the task itself doesn't actually > > > use the tracing functionality (i.e. doesn't breach lockdown), just > > > indirectly makes some new tracepoints available to whoever is > > > authorized to use them. > > > 3. net/xfrm/xfrm_user.c:copy_to_user_*() > > > Here a cryptographic secret is redacted based on the value returned > > > from the hook. There are two possible actions that may lead here: > > > a) A netlink message XFRM_MSG_GETSA with NLM_F_DUMP set - here the > > > task context is relevant, since the dumped data is sent back to > > > the current task. > > > b) When adding/deleting/updating an SA via XFRM_MSG_xxxSA, the > > > dumped SA is broadcasted to tasks subscribed to XFRM events - > > > here the current task context is not relevant as it doesn't > > > represent the tasks that could potentially see the secret. > > > It doesn't seem worth it to try to keep using the current task's > > > context in the a) case, since the eventual data leak can be > > > circumvented anyway via b), plus there is no way for the task to > > > indicate that it doesn't care about the actual key value, so the > > > check could generate a lot of "false alert" denials with SELinux. > > > Thus, let's pass NULL instead of current_cred() here faute de > > > mieux. > > > > > > Improvements-suggested-by: Casey Schaufler <firstname.lastname@example.org> > > > Improvements-suggested-by: Paul Moore <email@example.com> > > > Fixes: 59438b46471a ("security,lockdown,selinux: implement SELinux lockdown") > > > Acked-by: Dan Williams <firstname.lastname@example.org> [cxl] > > > Acked-by: Steffen Klassert <email@example.com> [xfrm] > > > Signed-off-by: Ondrej Mosnacek <firstname.lastname@example.org> > > > --- > > > > > > v4: > > > - rebase on top of TODO > > > - fix rebase conflicts: > > > * drivers/cxl/pci.c > > > - trivial: the lockdown reason was corrected in mainline > > > * kernel/bpf/helpers.c, kernel/trace/bpf_trace.c > > > - trivial: LOCKDOWN_BPF_READ was renamed to LOCKDOWN_BPF_READ_KERNEL > > > in mainline > > > * kernel/power/hibernate.c > > > - trivial: !secretmem_active() was added to the condition in > > > hibernation_available() > > > - cover new security_locked_down() call in kernel/bpf/helpers.c > > > (LOCKDOWN_BPF_WRITE_USER in BPF_FUNC_probe_write_user case) > > > > > > v3: https://email@example.com/ > > > - add the cred argument to security_locked_down() and adapt all callers > > > - keep using current_cred() in BPF, as the hook calls have been shifted > > > to program load time (commit ff40e51043af ("bpf, lockdown, audit: Fix > > > buggy SELinux lockdown permission checks")) > > > - in SELinux, don't ignore hook calls where cred == NULL, but use > > > SECINITSID_KERNEL as the subject instead > > > - update explanations in the commit message > > > > > > v2: https://firstname.lastname@example.org/ > > > - change to a single hook based on suggestions by Casey Schaufler > > > > > > v1: https://email@example.com/ > > > > The changes between v3 and v4 all seem sane to me, but I'm going to > > let this sit for a few days in hopes that we can collect a few more > > Reviewed-bys and ACKs. If I don't see any objections I'll merge it > > mid-week(ish) into selinux/stable-5.15 and plan on sending it to Linus > > after it goes through a build/test cycle. > > Time's up, I just merged this into selinux/stable-5.15 and I'll send > this to Linus once it passes testing. ... and it's back out of selinux/stable-5.15 in spectacular fashion. I'll be following up with another SELinux patch today or tomorrow. -- paul moore www.paul-moore.com
prev parent reply other threads:[~2021-09-23 19:07 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-09-13 14:02 Ondrej Mosnacek 2021-09-13 17:13 ` Rafael J. Wysocki 2021-09-13 21:05 ` Paul Moore 2021-09-16 2:59 ` Paul Moore 2021-09-16 6:57 ` Ondrej Mosnacek 2021-09-23 19:07 ` Paul Moore [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=CAHC9VhSzh90kFR8wzkmwR-YZNtHGAvYyATc2R1UDaBzZ944OFg@mail.gmail.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --subject='Re: [PATCH v4] lockdown,selinux: fix wrong subject in some SELinux lockdown checks' \ /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
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).