mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: roblabla <linux@roblab.la>
To: "Andrii Nakryiko" <andrii.nakryiko@gmail.com>,
	"Paul Moore" <paul@paul-moore.com>,
	"Daan De Meyer" <daan@amutable.com>
Cc: bpf@vger.kernel.org, linux-security-module@vger.kernel.org,
	paul.mabileau@harfanglab.fr, linux-kernel@vger.kernel.org,
	"Andrii Nakryiko" <andrii@kernel.org>
Subject: Re: [BUG] bpf, lsm: new first argument in 7.4 inode hooks silently breaks BPF LSMs
Date: Mon, 09 Nov 2026 16:07:34 +0100	[thread overview]
Message-ID: <9d6bdc31-e57c-4187-be78-29d82471f710@app.fastmail.com> (raw)
In-Reply-To: <CAEf4BzZKmn6g0SK8OddjKFj_vAmZFvpZv32Hs_S+GHgT7VNfrg@mail.gmail.com>

Hi,

Thanks for the replies!

> LSMs that need to provide a stable API must provide an abstraction
> layer between the LSM hook callbacks and their stable API.  The LSM
> framework is not responsible for the stability of individual LSM APIs.

Understood, that lines up with my expectations. I think the biggest
thing here would not necessarily be stability guarantees, but rather to
make sure that the eBPFs fail to load when the compatibility is broken.
But that's probably a problem for the eBPF side, and not LSM, I assume.

> So, in short, would it be possible to send a follow up to Daan's
> commit and move `struct mnt_idmap *idmap` to the end of LSM argument
> list?

If this is possible, that'd be nice so that we avoid this breakage in
the short term, since the change isn't in a released kernel yet.

> Having said that, there is a way to handle this, although ugly and
> *everyone* using specific LSMs would need to do this on their own.
> Instead of using convenience BPF_PROG() macro to define BPF program,
> you just use raw `u64 ctx[]` access, and then cast ctx[0] to either
> `struct mnt_idmap *` on new kernel, or `struct dentry *` on old
> kernel.

So, we already do similar tricks in the software we ship (which uses
various eBPF program types, not just LSM) to cover kernels 4.11 to 7.3,
using a mixture of CO-RE tricks similar to what you describe and
per-kernel builds selected at runtime.

Here's the problem though: We ship to customers, and we don't control
when they upgrade their kernel relative to our agent. When the kernel
changes a hook signature, a program built before we could handle that
new version still loads fine and just reads the wrong arguments, which
causes some really gnarly bugs that can cause really bad breakage (such
as accidentally denying events that should have been allowed, often
resulting in machines left broken).

So what would be really nice is a way to make eBPF code robust against
kernel changes such that it either works, or fails to load, but doesn't
do the halfway "loads but silently misbehaves". Here are two ideas that
have been in the back of my mind that could help solve this issue (though
I understand that they may be rather large changes, I'm putting them out
there mostly as a conversation starter):

1. Could libbpf/the kernel have a mismatch check on hook arguments? I
   understand that libbpf and the verifier don't know the types a
   program expects, since BPF_PROG() only casts u64s. But the macro
   does know the types at compile time. Could it (or an opt-in variant)
   record the expected prototype in the program's BTF, so that libbpf
   can compare it against the LSM hook's prototype in vmlinux BTF and
   refuse to load on a mismatch?

2. Since kernel BTF has parameter names for the bpf_lsm_* functions,
   could we maybe have CO-RE-style relocation to resolve "the argument
   named dentry" to the argument index at load time? This way, adding a
   new argument could happen anywhere in the argument list without
   breaking eBPFs, and removing an argument will (correctly) cause our
   eBPF to stop loading. It does mean the eBPF programs must provide the
   same argument names, but maybe that's an acceptable tradeoff?

Thanks,
roblabla

      reply	other threads:[~2026-11-09 15:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <d85ece6e-27f9-4d9f-83af-4101bc76fef6@app.fastmail.com>
2026-11-06 13:38 ` roblabla
2026-11-06 15:41   ` Paul Moore
2026-11-06 19:33     ` Andrii Nakryiko
2026-11-09 15:07       ` roblabla [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=9d6bdc31-e57c-4187-be78-29d82471f710@app.fastmail.com \
    --to=linux@roblab.la \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daan@amutable.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=paul.mabileau@harfanglab.fr \
    --cc=paul@paul-moore.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®