All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Borkmann <daniel@iogearbox.net>
To: Paul Moore <paul@paul-moore.com>
Cc: Ondrej Mosnacek <omosnace@redhat.com>,
	linux-security-module@vger.kernel.org,
	James Morris <jmorris@namei.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ingo Molnar <mingo@redhat.com>,
	Stephen Smalley <stephen.smalley.work@gmail.com>,
	selinux@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
	linux-fsdevel@vger.kernel.org, bpf@vger.kernel.org,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Casey Schaufler <casey@schaufler-ca.com>,
	jolsa@redhat.com
Subject: Re: [PATCH v2] lockdown,selinux: avoid bogus SELinux lockdown permission checks
Date: Mon, 31 May 2021 10:24:10 +0200	[thread overview]
Message-ID: <2e541bdc-ae21-9a07-7ac7-6c6a4dda09e8@iogearbox.net> (raw)
In-Reply-To: <CAHC9VhS1XRZjKcTFgH1+n5uA-CeT+9BeSP5jvT2+RE5ougLpUg@mail.gmail.com>

On 5/29/21 8:48 PM, Paul Moore wrote:
[...]
> Daniel's patch side steps that worry by just doing the lockdown
> permission check when the BPF program is loaded, but that isn't a
> great solution if the policy changes afterward.  I was hoping there
> might be some way to perform the permission check as needed, but the
> more I look the more that appears to be difficult, if not impossible
> (once again, corrections are welcome).

Your observation is correct, will try to clarify below a bit.

> I'm now wondering if the right solution here is to make use of the LSM
> notifier mechanism.  I'm not yet entirely sure if this would work from
> a BPF perspective, but I could envision the BPF subsystem registering
> a LSM notification callback via register_blocking_lsm_notifier(), see
> if Infiniband code as an example, and then when the LSM(s) policy
> changes the BPF subsystem would get a notification and it could
> revalidate the existing BPF programs and take block/remove/whatever
> the offending BPF programs.  This obviously requires a few things
> which I'm not sure are easily done, or even possible:
> 
> 1. Somehow the BPF programs would need to be "marked" at
> load/verification time with respect to their lockdown requirements so
> that decisions can be made later.  Perhaps a flag in bpf_prog_aux?
> 
> 2. While it looks like it should be possible to iterate over all of
> the loaded BPF programs in the LSM notifier callback via
> idr_for_each(prog_idr, ...), it is not clear to me if it is possible
> to safely remove, or somehow disable, BPF programs once they have been
> loaded.  Hopefully the BPF folks can help answer that question.
> 
> 3. Disabling of BPF programs might be preferable to removing them
> entirely on LSM policy changes as it would be possible to make the
> lockdown state less restrictive at a future point in time, allowing
> for the BPF program to be executed again.  Once again, not sure if
> this is even possible.

Part of why this gets really complex/impossible is that BPF programs in
the kernel are reference counted from various sides, be it that there
are references from user space to them (fd from application, BPF fs, or
BPF links), hooks where they are attached to as well as tail call maps
where one BPF prog calls into another. There is currently also no global
infra of some sort where you could piggy back to atomically keep track of
all the references in a list or such. And the other thing is that BPF progs
have no ownership that is tied to a specific task after they have been
loaded. Meaning, once they are loaded into the kernel by an application
and attached to a specific hook, they can remain there potentially until
reboot of the node, so lifecycle of the user space application != lifecycle
of the BPF program.

It's maybe best to compare this aspect to kernel modules in the sense that
you have an application that loads it into the kernel (insmod, etc, where
you could also enforce lockdown signature check), but after that, they can
be managed by other entities as well (implicitly refcounted from kernel,
removed by other applications, etc).

My understanding of the lockdown settings are that users have options
to select/enforce a lockdown level of CONFIG_LOCK_DOWN_KERNEL_FORCE_{INTEGRITY,
CONFIDENTIALITY} at compilation time, they have a lockdown={integrity|
confidentiality} boot-time parameter, /sys/kernel/security/lockdown,
and then more fine-grained policy via 59438b46471a ("security,lockdown,selinux:
implement SELinux lockdown"). Once you have set a global policy level,
you cannot revert back to a less strict mode. So the SELinux policy is
specifically tied around tasks to further restrict applications in respect
to the global policy. I presume that would mean for those users that majority
of tasks have the confidentiality option set via SELinux with just a few
necessary using the integrity global policy. So overall the enforcing
option when BPF program is loaded is the only really sensible option to
me given only there we have the valid current task where such policy can
be enforced.

Best,
Daniel

WARNING: multiple messages have this Message-ID (diff)
From: Daniel Borkmann <daniel@iogearbox.net>
To: Paul Moore <paul@paul-moore.com>
Cc: jolsa@redhat.com, selinux@vger.kernel.org,
	netdev@vger.kernel.org,
	Stephen Smalley <stephen.smalley.work@gmail.com>,
	Ondrej Mosnacek <omosnace@redhat.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	James Morris <jmorris@namei.org>,
	Casey Schaufler <casey@schaufler-ca.com>,
	linux-security-module@vger.kernel.org,
	Ingo Molnar <mingo@redhat.com>,
	linux-fsdevel@vger.kernel.org, bpf@vger.kernel.org,
	linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] lockdown,selinux: avoid bogus SELinux lockdown permission checks
Date: Mon, 31 May 2021 10:24:10 +0200	[thread overview]
Message-ID: <2e541bdc-ae21-9a07-7ac7-6c6a4dda09e8@iogearbox.net> (raw)
In-Reply-To: <CAHC9VhS1XRZjKcTFgH1+n5uA-CeT+9BeSP5jvT2+RE5ougLpUg@mail.gmail.com>

On 5/29/21 8:48 PM, Paul Moore wrote:
[...]
> Daniel's patch side steps that worry by just doing the lockdown
> permission check when the BPF program is loaded, but that isn't a
> great solution if the policy changes afterward.  I was hoping there
> might be some way to perform the permission check as needed, but the
> more I look the more that appears to be difficult, if not impossible
> (once again, corrections are welcome).

Your observation is correct, will try to clarify below a bit.

> I'm now wondering if the right solution here is to make use of the LSM
> notifier mechanism.  I'm not yet entirely sure if this would work from
> a BPF perspective, but I could envision the BPF subsystem registering
> a LSM notification callback via register_blocking_lsm_notifier(), see
> if Infiniband code as an example, and then when the LSM(s) policy
> changes the BPF subsystem would get a notification and it could
> revalidate the existing BPF programs and take block/remove/whatever
> the offending BPF programs.  This obviously requires a few things
> which I'm not sure are easily done, or even possible:
> 
> 1. Somehow the BPF programs would need to be "marked" at
> load/verification time with respect to their lockdown requirements so
> that decisions can be made later.  Perhaps a flag in bpf_prog_aux?
> 
> 2. While it looks like it should be possible to iterate over all of
> the loaded BPF programs in the LSM notifier callback via
> idr_for_each(prog_idr, ...), it is not clear to me if it is possible
> to safely remove, or somehow disable, BPF programs once they have been
> loaded.  Hopefully the BPF folks can help answer that question.
> 
> 3. Disabling of BPF programs might be preferable to removing them
> entirely on LSM policy changes as it would be possible to make the
> lockdown state less restrictive at a future point in time, allowing
> for the BPF program to be executed again.  Once again, not sure if
> this is even possible.

Part of why this gets really complex/impossible is that BPF programs in
the kernel are reference counted from various sides, be it that there
are references from user space to them (fd from application, BPF fs, or
BPF links), hooks where they are attached to as well as tail call maps
where one BPF prog calls into another. There is currently also no global
infra of some sort where you could piggy back to atomically keep track of
all the references in a list or such. And the other thing is that BPF progs
have no ownership that is tied to a specific task after they have been
loaded. Meaning, once they are loaded into the kernel by an application
and attached to a specific hook, they can remain there potentially until
reboot of the node, so lifecycle of the user space application != lifecycle
of the BPF program.

It's maybe best to compare this aspect to kernel modules in the sense that
you have an application that loads it into the kernel (insmod, etc, where
you could also enforce lockdown signature check), but after that, they can
be managed by other entities as well (implicitly refcounted from kernel,
removed by other applications, etc).

My understanding of the lockdown settings are that users have options
to select/enforce a lockdown level of CONFIG_LOCK_DOWN_KERNEL_FORCE_{INTEGRITY,
CONFIDENTIALITY} at compilation time, they have a lockdown={integrity|
confidentiality} boot-time parameter, /sys/kernel/security/lockdown,
and then more fine-grained policy via 59438b46471a ("security,lockdown,selinux:
implement SELinux lockdown"). Once you have set a global policy level,
you cannot revert back to a less strict mode. So the SELinux policy is
specifically tied around tasks to further restrict applications in respect
to the global policy. I presume that would mean for those users that majority
of tasks have the confidentiality option set via SELinux with just a few
necessary using the integrity global policy. So overall the enforcing
option when BPF program is loaded is the only really sensible option to
me given only there we have the valid current task where such policy can
be enforced.

Best,
Daniel

  reply	other threads:[~2021-05-31  8:24 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-17  9:20 [PATCH v2] lockdown,selinux: avoid bogus SELinux lockdown permission checks Ondrej Mosnacek
2021-05-17  9:20 ` [PATCH v2] lockdown, selinux: " Ondrej Mosnacek
2021-05-17 11:00 ` [PATCH v2] lockdown,selinux: " Michael Ellerman
2021-05-17 11:00   ` Michael Ellerman
2021-05-26 11:44   ` Ondrej Mosnacek
2021-05-26 11:44     ` Ondrej Mosnacek
2021-05-27  4:28     ` James Morris
2021-05-27  4:28       ` James Morris
2021-05-27 14:18       ` Paul Moore
2021-05-27 14:18         ` Paul Moore
2021-05-28  1:37 ` Paul Moore
2021-05-28  1:37   ` Paul Moore
2021-05-28  7:09   ` Daniel Borkmann
2021-05-28  7:09     ` Daniel Borkmann
2021-05-28  9:53     ` Jiri Olsa
2021-05-28  9:53       ` Jiri Olsa
2021-05-28  9:56     ` Daniel Borkmann
2021-05-28  9:56       ` Daniel Borkmann
2021-05-28 10:16       ` Jiri Olsa
2021-05-28 10:16         ` Jiri Olsa
2021-05-28 11:47       ` Jiri Olsa
2021-05-28 11:47         ` Jiri Olsa
2021-05-28 11:54         ` Daniel Borkmann
2021-05-28 11:54           ` Daniel Borkmann
2021-05-28 13:42       ` Ondrej Mosnacek
2021-05-28 13:42         ` Ondrej Mosnacek
2021-05-28 14:20         ` Daniel Borkmann
2021-05-28 14:20           ` Daniel Borkmann
2021-05-28 15:54           ` Paul Moore
2021-05-28 15:54             ` Paul Moore
2021-05-28 15:47     ` Paul Moore
2021-05-28 15:47       ` Paul Moore
2021-05-28 18:10       ` Daniel Borkmann
2021-05-28 18:10         ` Daniel Borkmann
2021-05-28 22:52         ` Paul Moore
2021-05-28 22:52           ` Paul Moore
2021-05-29 18:48         ` Paul Moore
2021-05-29 18:48           ` Paul Moore
2021-05-31  8:24           ` Daniel Borkmann [this message]
2021-05-31  8:24             ` Daniel Borkmann
2021-06-01 20:47             ` Paul Moore
2021-06-01 20:47               ` Paul Moore
2021-06-02 12:40               ` Daniel Borkmann
2021-06-02 12:40                 ` Daniel Borkmann
2021-06-02 15:13                 ` Paul Moore
2021-06-02 15:13                   ` Paul Moore
2021-06-03 18:52                   ` Daniel Borkmann
2021-06-03 18:52                     ` Daniel Borkmann
2021-06-04  4:50                     ` Paul Moore
2021-06-04  4:50                       ` Paul Moore
2021-06-04 18:02                       ` Daniel Borkmann
2021-06-04 18:02                         ` Daniel Borkmann
2021-06-04 23:34                         ` Paul Moore
2021-06-04 23:34                           ` Paul Moore
2021-06-05  0:08                           ` Alexei Starovoitov
2021-06-05  0:08                             ` Alexei Starovoitov
2021-06-05 18:10                             ` Casey Schaufler
2021-06-05 18:10                               ` Casey Schaufler
2021-06-05 18:17                               ` Linus Torvalds
2021-06-05 18:17                                 ` Linus Torvalds
2021-06-06  2:11                                 ` Paul Moore
2021-06-06  2:11                                   ` Paul Moore
2021-06-06  1:30                             ` Paul Moore
2021-06-06  1:30                               ` Paul Moore
2021-06-02 13:39   ` Ondrej Mosnacek
2021-06-02 13:39     ` Ondrej Mosnacek
2021-06-03 17:46     ` Paul Moore
2021-06-03 17:46       ` Paul Moore
2021-06-08 11:01       ` Ondrej Mosnacek
2021-06-08 11:01         ` Ondrej Mosnacek
2021-06-09  2:40         ` Paul Moore
2021-06-09  2:40           ` Paul Moore
2021-05-28 13:58 ` Steven Rostedt
2021-05-28 13:58   ` Steven Rostedt

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=2e541bdc-ae21-9a07-7ac7-6c6a4dda09e8@iogearbox.net \
    --to=daniel@iogearbox.net \
    --cc=bpf@vger.kernel.org \
    --cc=casey@schaufler-ca.com \
    --cc=jmorris@namei.org \
    --cc=jolsa@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mingo@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=omosnace@redhat.com \
    --cc=paul@paul-moore.com \
    --cc=rostedt@goodmis.org \
    --cc=selinux@vger.kernel.org \
    --cc=stephen.smalley.work@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.