The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Nicolas Bouchinet <nicolas.bouchinet@oss.cyber.gouv.fr>
To: Xiujianfeng <xiujianfeng@huaweicloud.com>
Cc: Justin Suess <utilityemal77@gmail.com>,
	 Alexei Starovoitov <ast@kernel.org>,
	Paul Moore <paul@paul-moore.com>,
	 Xiujianfeng <xiujianfeng@huawei.com>,
	linux-kernel@vger.kernel.org,
	 linux-security-module@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 0/2] lsm: give BPF programs a way to query locked_down state
Date: Tue, 18 Aug 2026 11:08:25 +0000	[thread overview]
Message-ID: <aoQndOlUPKN84WTm@archlinux> (raw)
In-Reply-To: <6ab57477-69f8-4c60-852e-58ce7ef25023@huaweicloud.com>

On Tue, Aug 18, 2026 at 11:47:55AM +0800, Xiujianfeng wrote:
> +cc Nicolas
> 
> On 8/15/2026 7:20 PM, Justin Suess wrote:
> > Howdy,
> > 
> > BPF programs can attach to the locked_down LSM hook and contribute a
> > verdict, but they have never been able to ask the locked_down question
> > themselves: there is no way for a program to invoke the hook and learn
> > whether a given operation is locked down. (i.e be a caller of
> > security_locked_down rather than a consumer).
> > 
> > Today the state has to be fed in out of band, for example userspace
> > reading /sys/kernel/security/lockdown and writing the result into a
> > map. That is a time-of-check/time-of-use race: a security_locked_down
> > verdict can be raised at runtime, so the cached answer can be stale
> > by the time the program acts on it.
> 
> Adding the bpf_security_locked_down() kfunc does not actually solve the
> TOCTOU issue you mentioned. Even after bpf_security_locked_down() is
> called, userspace can still change the lockdown state via /sys/kernel/
> security/lockdown.
> 
> I fail to see the necessity for a BPF program to know whether a specific
> operation is locked down.

I agree with Xiu.

> The test case provided in patch 2 does not
> clearly demonstrate a scenario where this is required. In my view, the
> verdict should happen exactly where security_locked_down() is currently
> invoked.
> 

> Furthermore, based on the current implementation of Lockdown, integrity
> is the prerequisite for confidentiality. It is designed to be coarse-
> grained and does not support per-operation lockdown. The fact that LSM
> BPF can already hook into locked_down seems to violate this foundational
> model, this is is analogous to the bitmap implementation [1], I’m
> considering whether we should restrict BPF from attaching to the
> locked_down hook. Nicolas, what are your thoughts on this?

I do not see any issue about LSM BPF being able to hook into
security_locked_down. If Lockdown is enabled in integrity mode, and a
BPF LSM hook authorizes let's say the LOCKDOWN_DEV_MEM reason, Lockdown
will deny it anyway.

IMHO, if one wants to disable the Lockdown LSM and implement it through
eBPF, if the implementation is bad, it is not our problem. Exactly as
for other LSM hooks.
> 
> [1]
> https://lore.kernel.org/all/20250728111517.134116-1-nik.borisov@suse.com/
> 
> > 
> > Add a bpf_security_locked_down() kfunc that calls
> > security_locked_down() and returns its verdict, letting LSM and
> > syscall programs query locked_down state at decision time. Out-of-range
> > reasons are rejected with -EINVAL before dispatching the hook, and the
> > kfunc is refused to programs attached to the locked_down hook itself,
> > which would recurse into the dispatch. (how the obvious recursion issue
> > is addressed).
> > 
> > As this is the first pure-lsm-hook kfunc, add a new file security/lsm_kfuncs.c
> > to host it.
> > 
> > This kfunc has no reliance on / relation to the Lockdown LSM, despite the
> > similar naming. It is an LSM-agnostic caller of security_locked_down, and
> > Lockdown just happens to be the only in-tree subscriber to this hook at the
> > moment.
> > 
> > In fact, the test environment does not rely on CONFIG_SECURITY_LOCKDOWN at
> > all, and uses a BPF implementation of security_locked_down.
> > 
> > This kfunc can cause notices to be printed with kmsg if the Lockdown LSM is
> > enabled due to this line in security/lockdown/lockdown.c:
> > 
> >    pr_notice_ratelimited("Lockdown: %s: %s is restricted; see man kernel_lockdown.7\n",
> > 				                 current->comm, lockdown_reasons[what]);
> > 
> > Patch 1 adds the kfunc, patch 2 the selftests. This is based on bpf-next/master, but
> > applies cleanly to the lsm tree.
> > 
> > Justin

Nicolas

  parent reply	other threads:[~2026-08-18 11:08 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-15 11:20 [PATCH bpf-next 0/2] lsm: give BPF programs a way to query locked_down state Justin Suess
2026-08-15 11:20 ` [PATCH bpf-next 1/2] lsm: add bpf_security_locked_down() kfunc Justin Suess
2026-08-15 12:19   ` bot+bpf-ci
2026-08-15 11:20 ` [PATCH bpf-next 2/2] selftests/bpf: Test bpf_security_locked_down kfunc Justin Suess
2026-08-15 12:19   ` bot+bpf-ci
2026-08-18  3:47 ` [PATCH bpf-next 0/2] lsm: give BPF programs a way to query locked_down state Xiujianfeng
2026-08-18  4:46   ` Justin Suess
2026-08-18 10:54     ` Xiujianfeng
2026-08-18 11:08   ` Nicolas Bouchinet [this message]
2026-08-18  9:42 ` Kumar Kartikeya Dwivedi
2026-08-18 11:12   ` Justin Suess
2026-08-18 17:24   ` Justin Suess
2026-08-18 17:41   ` David Windsor
2026-08-18 19:48     ` Paul Moore

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=aoQndOlUPKN84WTm@archlinux \
    --to=nicolas.bouchinet@oss.cyber.gouv.fr \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=paul@paul-moore.com \
    --cc=utilityemal77@gmail.com \
    --cc=xiujianfeng@huawei.com \
    --cc=xiujianfeng@huaweicloud.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