[PATCH] LSM: check if lsmprop_to_secctx call is supported by LSM
Tomasz Unger
tomasz.unger at yahoo.pl
Wed Nov 11 21:17:22 UTC 2026
On Fri, 19 Jun 2026 19:19:45 +0200, Sebastian Bockholt wrote:
> In include/linux/lsm_hook_defs.h, lsmprop_to_secctx is defined with
> a default return value of -EOPNOTSUPP.
> The function bpf_lsm_lsmprop_to_secctx, defined in
> security/bpf/hooks.c, returns the hook's default value. Therefore,
> directly returning the result of the bpf_lsm_lsmprop_to_secctx call
> propagates an unchecked EOPNOTSUPP error.
[...]
> - return scall->hl->hook.lsmprop_to_secctx(prop, cp);
> + error = scall->hl->hook.lsmprop_to_secctx(prop, cp);
> + if (error == -EOPNOTSUPP)
> + continue;
> + return error;
Hi,
I ran into the same problem independently and would like to revive this
patch. It fixes a regression that is still present in v7.4-rc2, in
next-20261111 and in the current audit and lsm dev branches.
Symptom
On an Arch Linux system (7.2.15, AppArmor and auditd active, LSM order
"capability,landlock,lockdown,yama,bpf,apparmor") the log is flooded with
audit: error in audit_log_subj_ctx
about five times per sudo invocation, and the affected audit records are
emitted without their subj= field. No BPF LSM program is loaded. It is
enough that CONFIG_BPF_LSM is built in and "bpf" is listed before the LSM
that provides security contexts. So this is not only log noise: audit
records silently lose the subject label.
Cause
Before commit a59076f2669e ("lsm: security_lsmblob_to_secctx module
selection") security_lsmprop_to_secctx() used call_int_hook(), which
skips a hook that returns the hook's default value. Since that commit
the function returns the result of the first registered hook when it is
called with LSM_ID_UNDEF. The BPF LSM registers a stub for every hook,
and the stub returns the default, -EOPNOTSUPP, so the LSM that really
provides the context is never asked. audit_log_subj_ctx(),
audit_log_obj_ctx() and the AUDIT_SIGNAL_INFO handler all pass
LSM_ID_UNDEF. On the affected system a kretprobe shows
bpf_lsm_lsmprop_to_secctx() returning -95 and
apparmor_lsmprop_to_secctx() never being called.
The patch restores the old behaviour for this case, so I think it is a
fix for the commit above rather than a step towards BPF supporting
security contexts.
Testing
I applied the patch on top of 067c5c24cef2 (v7.4-rc2-92), where it
applies with an offset only, and booted the kernel in QEMU with audit=1,
without and with the patch. A write to /proc/self/loginuid was used to
generate AUDIT_LOGIN and AUDIT_SYSCALL records. No LSM policy was
loaded.
lsm= without the patch with the patch
bpf,apparmor error, no subj= subj=unconfined
apparmor,bpf subj=unconfined subj=unconfined
bpf,selinux error, no subj= subj=kernel
bpf,smack error, no subj= subj=_
With the patch there is no "error in audit_log_subj_ctx" message in any
of the four configurations, including the netlabel records logged during
boot. The problem is therefore not specific to AppArmor: SELinux and
Smack are affected in the same way when bpf comes first.
Not covered by this test: the obj= path (audit_log_obj_ctx()) and
AUDIT_SIGNAL_INFO. They use the same call, but no such record was
generated here.
The analysis and the QEMU runs were done with the help of an assistant
(Claude Code). I checked the logs and the results myself.
Suggestions for the commit message
- mention the audit symptom ("error in audit_log_subj_ctx", missing
subj=) so that people who hit it can find the fix,
- add
Fixes: a59076f2669e ("lsm: security_lsmblob_to_secctx module selection")
The commit is in v6.18-rc1, so this probably also wants to go to
stable.
Sebastian, do you plan to send a v2? If you do not have the time, I can
resend the patch with your authorship kept and the description extended
as above.
Tested-by: Tomasz Unger <tomasz.unger at yahoo.pl>
More information about the Linux-security-module-archive
mailing list