lsm= with bpf before selinux breaks fscreate with EINVAL
Subsystems (3)
Hi,
We have boot failure when CONFIG_LSM has "bpf" listed before "selinux" (without bpf lsm scripts loaded). (This also happens with a boot with "security=selinux" if selinux was not in LSM= list but bpf is.)
systemd reports on the failing boot attempt:
Failed to set SELinux security context generic_u:object_r:device:s0 for /dev/shm: Invalid argument Mounting tmpfs to /dev/shm of type tmpfs with options mode=01777.
Mounting tmpfs (tmpfs) on /dev/shm (MS_NOSUID|MS_NODEV|MS_STRICTATIME "mode=01777")...
Failed to mount tmpfs (type tmpfs) on /dev/shm (MS_NOSUID|MS_NODEV|MS_STRICTATIME "mode=01777"): No such file or directory Failed to set SELinux security context generic_u:object_r:device:s0 for /dev/pts: Invalid argument Mounting devpts to /dev/pts of type devpts with options mode=0620,gid=5.
Mounting devpts (devpts) on /dev/pts (MS_NOSUID|MS_NOEXEC "mode=0620,gid=5")...
Failed to mount devpts (type devpts) on /dev/pts (MS_NOSUID|MS_NOEXEC "mode=0620,gid=5"): No such file or directory No filesystem is currently mounted on /sys/fs/cgroup.
Failed to set SELinux security context generic_u:object_r:def_t:s0 for /sys/fs/cgroup: Invalid argument Mounting cgroup2 to /sys/fs/cgroup of type cgroup2 with options nsdelegate,memory_recursiveprot. Mounting cgroup2 (cgroup2) on /sys/fs/cgroup (MS_NOSUID|MS_NODEV|MS_NOEXEC "nsdelegate,memory_recursiveprot")... Failed to set SELinux security context generic_u:object_r:def_t:s0 for /sys/fs/pstore: Invalid argument Mounting pstore to /sys/fs/pstore of type pstore with options n/a.
Mounting pstore (pstore) on /sys/fs/pstore (MS_NOSUID|MS_NODEV|MS_NOEXEC "")...
Failed to set SELinux security context generic_u:object_r:def_t:s0 for /sys/fs/bpf: Invalid argument Mounting bpf to /sys/fs/bpf of type bpf with options mode=0700.
Mounting bpf (bpf) on /sys/fs/bpf (MS_NOSUID|MS_NODEV|MS_NOEXEC "mode=0700")...
[!!!!!!] Failed to mount API filesystems.
Freezing execution
'Invalid arguments' seems from setfscreatecon_raw.
Reproducer:
Boot with lsm=lockdown,capability,landlock,yama,safesetid,bpf,selinux,ima,evm
(none):~# cat /proc/thread-self/attr/current cat: /proc/thread-self/attr/current: Invalid argument (none):~# echo > /proc/thread-self/attr/fscreate bash: echo: write error: Invalid argument
This appears to be caused by security_getprocattr / security_setprocattr iterating until the first hook defined (which is bpf) and returning with default value -EINVAL before selinux even sees them.
Perhaps, bpf LSM should avoid registering getprocattr/setprocattr hooks that it does not implement, or the legacy LSM_ID_UNDEF procattr dispatch should skip LSMs that cannot handle the requested attribute and continue to seLinux (or whatever).
Thanks,
Paul Moore
maintainerQuoted 36 lines · Vitaly Chikunov
Hi,
We have boot failure when
CONFIG_LSMhas "bpf" listed before "selinux" (without bpf lsm scripts loaded). (This also happens with a boot with "security=selinux" if selinux was not in LSM= list but bpf is.)systemd reports on the failing boot attempt:
Failed to set SELinux security context generic_u:object_r:device:s0 for
/dev/shm: Invalid argument Mounting tmpfs to/dev/shmof type tmpfs with options mode=01777.
Mounting tmpfs (tmpfs) on/dev/shm(MS_NOSUID|MS_NODEV|MS_STRICTATIME "mode=01777")...
Failed to mount tmpfs (type tmpfs) on/dev/shm(MS_NOSUID|MS_NODEV|MS_STRICTATIME "mode=01777"): No such file or directory Failed to set SELinux security context generic_u:object_r:device:s0 for/dev/pts: Invalid argument Mounting devpts to/dev/ptsof type devpts with options mode=0620,gid=5.
Mounting devpts (devpts) on/dev/pts(MS_NOSUID|MS_NOEXEC "mode=0620,gid=5")...
Failed to mount devpts (type devpts) on/dev/pts(MS_NOSUID|MS_NOEXEC "mode=0620,gid=5"): No such file or directory No filesystem is currently mounted on/sys/fs/cgroup.
Failed to set SELinux security context generic_u:object_r:def_t:s0 for/sys/fs/cgroup: Invalid argument Mounting cgroup2 to/sys/fs/cgroupof type cgroup2 with options nsdelegate,memory_recursiveprot. Mounting cgroup2 (cgroup2) on/sys/fs/cgroup(MS_NOSUID|MS_NODEV|MS_NOEXEC "nsdelegate,memory_recursiveprot")... Failed to set SELinux security context generic_u:object_r:def_t:s0 for/sys/fs/pstore: Invalid argument Mounting pstore to/sys/fs/pstoreof type pstore with options n/a.
Mounting pstore (pstore) on/sys/fs/pstore(MS_NOSUID|MS_NODEV|MS_NOEXEC "")...
Failed to set SELinux security context generic_u:object_r:def_t:s0 for/sys/fs/bpf: Invalid argument Mounting bpf to/sys/fs/bpfof type bpf with options mode=0700.
Mounting bpf (bpf) on/sys/fs/bpf(MS_NOSUID|MS_NODEV|MS_NOEXEC "mode=0700")...
[!!!!!!] Failed to mount API filesystems.
Freezing execution'Invalid arguments' seems from
setfscreatecon_raw.Reproducer:
Boot with lsm=lockdown,capability,landlock,yama,safesetid,bpf,selinux,ima,evm
Quoted 8 lines
(none):~# cat /proc/thread-self/attr/current cat: /proc/thread-self/attr/current: Invalid argument (none):~# echo > /proc/thread-self/attr/fscreate bash: echo: write error: Invalid argumentThis appears to be caused by
security_getprocattr/security_setprocattriterating until the first hook defined (which is bpf) and returning with default value-EINVALbefore selinux even sees them.
Thanks for the problem report, the general recommendation is to place the BPF LSM towards the end of the list (see the CONFIG_LSM Kconfig help text), but we're trying to ensure that the BPF LSM works properly when placed anywhere in that list.
My apologies if you're abilities are well beyond this, but if you are familiar with patching and building your own kernel, have you tried changing the LSM_RET_DEFAULT value for those functions to zero/0? Assuming userspace is happy with that, I believe it may solve this problem.
Signature · 1 line
paul-moore.com
Paul,
Quoted 42 lines · Paul Moore
Quoted 41 lines · Vitaly Chikunov
Hi,
We have boot failure when
CONFIG_LSMhas "bpf" listed before "selinux" (without bpf lsm scripts loaded). (This also happens with a boot with "security=selinux" if selinux was not in LSM= list but bpf is.)systemd reports on the failing boot attempt:
Failed to set SELinux security context generic_u:object_r:device:s0 for
/dev/shm: Invalid argument Mounting tmpfs to/dev/shmof type tmpfs with options mode=01777.
Mounting tmpfs (tmpfs) on/dev/shm(MS_NOSUID|MS_NODEV|MS_STRICTATIME "mode=01777")...
Failed to mount tmpfs (type tmpfs) on/dev/shm(MS_NOSUID|MS_NODEV|MS_STRICTATIME "mode=01777"): No such file or directory Failed to set SELinux security context generic_u:object_r:device:s0 for/dev/pts: Invalid argument Mounting devpts to/dev/ptsof type devpts with options mode=0620,gid=5.
Mounting devpts (devpts) on/dev/pts(MS_NOSUID|MS_NOEXEC "mode=0620,gid=5")...
Failed to mount devpts (type devpts) on/dev/pts(MS_NOSUID|MS_NOEXEC "mode=0620,gid=5"): No such file or directory No filesystem is currently mounted on/sys/fs/cgroup.
Failed to set SELinux security context generic_u:object_r:def_t:s0 for/sys/fs/cgroup: Invalid argument Mounting cgroup2 to/sys/fs/cgroupof type cgroup2 with options nsdelegate,memory_recursiveprot. Mounting cgroup2 (cgroup2) on/sys/fs/cgroup(MS_NOSUID|MS_NODEV|MS_NOEXEC "nsdelegate,memory_recursiveprot")... Failed to set SELinux security context generic_u:object_r:def_t:s0 for/sys/fs/pstore: Invalid argument Mounting pstore to/sys/fs/pstoreof type pstore with options n/a.
Mounting pstore (pstore) on/sys/fs/pstore(MS_NOSUID|MS_NODEV|MS_NOEXEC "")...
Failed to set SELinux security context generic_u:object_r:def_t:s0 for/sys/fs/bpf: Invalid argument Mounting bpf to/sys/fs/bpfof type bpf with options mode=0700.
Mounting bpf (bpf) on/sys/fs/bpf(MS_NOSUID|MS_NODEV|MS_NOEXEC "mode=0700")...
[!!!!!!] Failed to mount API filesystems.
Freezing execution'Invalid arguments' seems from
setfscreatecon_raw.Reproducer:
Boot with lsm=lockdown,capability,landlock,yama,safesetid,bpf,selinux,ima,evm
(none):~# cat /proc/thread-self/attr/current cat: /proc/thread-self/attr/current: Invalid argument (none):~# echo > /proc/thread-self/attr/fscreate bash: echo: write error: Invalid argument
Quoted 8 lines
Quoted 3 lines
This appears to be caused by
security_getprocattr/security_setprocattriterating until the first hook defined (which is bpf) and returning with default value-EINVALbefore selinux even sees them.Thanks for the problem report, the general recommendation is to place the BPF LSM towards the end of the list (see the
CONFIG_LSMKconfighelp text), but we're trying to ensure that the BPF LSM works properly when placed anywhere in that list.
I think if the order is important it should be handled in the code like for capabilities and ima/evm LSMs, not by forcing the user to discover the correct order with trial and error.
Quoted 6 lines
My apologies if you're abilities are well beyond this, but if you are familiar with patching and building your own kernel, have you tried changing the
LSM_RET_DEFAULTvalue for those functions to zero/0? Assuming userspace is happy with that, I believe it may solve this problem.
I can patch and test if this is useful to find the correct solution, but the description is a bit vague. Did you mean
include/linux/lsm_hook_defs.h:301:LSM_HOOK(int, -EINVAL, getprocattr, struct task_struct *p, const char *name, include/linux/lsm_hook_defs.h:303:LSM_HOOK(int, -EINVAL, setprocattr, const char *name, void *value, size_t size)
In these lines to replace -EINVAL with 0?
I would never try this on my own, because it looks like -EINVAL is a meaningful value, and I would never claim to understand all the intricacies of LSMs.
3892 int security_setprocattr(int lsmid, const char *name, void *value, size_t size)
3893 {
3894 struct lsm_static_call *scall;
3895
3896 lsm_for_each_hook(scall, setprocattr) {
3897 if (lsmid != 0 && lsmid != scall->hl->lsmid->id)
3898 continue;
3899 return scall->hl->hook.setprocattr(name, value, size);
3900 }
3901 return LSM_RET_DEFAULT(setprocattr);
3902 }If my first hypothesis is correct, and the lsm_for_each_hook goes into bpf before selinux, setting the default to 0 will make selinux hook unreachable.
With all this, I conclude that I perhaps misunderstood your request.
Thanks,
Quoted 3 lines
Signature · 2 lines
-- paul-moore.com
Paul Moore
maintainerQuoted 47 lines · Vitaly Chikunov
Quoted 46 lines · Paul Moore
Quoted 44 lines · Vitaly Chikunov
Hi,
We have boot failure when
CONFIG_LSMhas "bpf" listed before "selinux" (without bpf lsm scripts loaded). (This also happens with a boot with "security=selinux" if selinux was not in LSM= list but bpf is.)systemd reports on the failing boot attempt:
Failed to set SELinux security context generic_u:object_r:device:s0 for
/dev/shm: Invalid argument Mounting tmpfs to/dev/shmof type tmpfs with options mode=01777.
Mounting tmpfs (tmpfs) on/dev/shm(MS_NOSUID|MS_NODEV|MS_STRICTATIME "mode=01777")...
Failed to mount tmpfs (type tmpfs) on/dev/shm(MS_NOSUID|MS_NODEV|MS_STRICTATIME "mode=01777"): No such file or directory Failed to set SELinux security context generic_u:object_r:device:s0 for/dev/pts: Invalid argument Mounting devpts to/dev/ptsof type devpts with options mode=0620,gid=5.
Mounting devpts (devpts) on/dev/pts(MS_NOSUID|MS_NOEXEC "mode=0620,gid=5")...
Failed to mount devpts (type devpts) on/dev/pts(MS_NOSUID|MS_NOEXEC "mode=0620,gid=5"): No such file or directory No filesystem is currently mounted on/sys/fs/cgroup.
Failed to set SELinux security context generic_u:object_r:def_t:s0 for/sys/fs/cgroup: Invalid argument Mounting cgroup2 to/sys/fs/cgroupof type cgroup2 with options nsdelegate,memory_recursiveprot. Mounting cgroup2 (cgroup2) on/sys/fs/cgroup(MS_NOSUID|MS_NODEV|MS_NOEXEC "nsdelegate,memory_recursiveprot")... Failed to set SELinux security context generic_u:object_r:def_t:s0 for/sys/fs/pstore: Invalid argument Mounting pstore to/sys/fs/pstoreof type pstore with options n/a.
Mounting pstore (pstore) on/sys/fs/pstore(MS_NOSUID|MS_NODEV|MS_NOEXEC "")...
Failed to set SELinux security context generic_u:object_r:def_t:s0 for/sys/fs/bpf: Invalid argument Mounting bpf to/sys/fs/bpfof type bpf with options mode=0700.
Mounting bpf (bpf) on/sys/fs/bpf(MS_NOSUID|MS_NODEV|MS_NOEXEC "mode=0700")...
[!!!!!!] Failed to mount API filesystems.
Freezing execution'Invalid arguments' seems from
setfscreatecon_raw.Reproducer:
Boot with lsm=lockdown,capability,landlock,yama,safesetid,bpf,selinux,ima,evm
(none):~# cat /proc/thread-self/attr/current cat: /proc/thread-self/attr/current: Invalid argument (none):~# echo > /proc/thread-self/attr/fscreate bash: echo: write error: Invalid argumentThis appears to be caused by
security_getprocattr/security_setprocattriterating until the first hook defined (which is bpf) and returning with default value-EINVALbefore selinux even sees them.
Quoted 8 lines
Quoted 4 lines
Thanks for the problem report, the general recommendation is to place the BPF LSM towards the end of the list (see the
CONFIG_LSMKconfighelp text), but we're trying to ensure that the BPF LSM works properly when placed anywhere in that list.I think if the order is important it should be handled in the code like for capabilities and ima/evm LSMs, not by forcing the user to discover the correct order with trial and error.
Patches are always welcome, although as I mentioned to you previously we are working towards supporting arbitrary ordering for BPF LSMs.
Quoted 6 lines
Quoted 5 lines
My apologies if you're abilities are well beyond this, but if you are familiar with patching and building your own kernel, have you tried changing the
LSM_RET_DEFAULTvalue for those functions to zero/0? Assuming userspace is happy with that, I believe it may solve this problem.
Quoted 7 lines
I can patch and test if this is useful to find the correct solution, but the description is a bit vague. Did you mean
include/linux/lsm_hook_defs.h:301:LSM_HOOK(int,
-EINVAL, getprocattr, structtask_struct*p, const char *name, include/linux/lsm_hook_defs.h:303:LSM_HOOK(int,-EINVAL, setprocattr, const char *name, void *value,size_tsize)In these lines to replace
-EINVALwith 0?
The patch below is what I had in mind (although be warned that was just a cut-n-paste into this email so it is likely whitespace damaged). If you are able to give that a test it would be great, if not, I can throw it on the todo pile.
include/linux/lsm_hook_defs.h +0 -0
@@ -298,9 +298,9 @@ LSM_HOOK(int, -EOPNOTSUPP, getselfattr, unsigned int attr, struct lsm_ctx __user *ctx, u32 *size, u32 flags)
LSM_HOOK(int, -EOPNOTSUPP, setselfattr, unsigned int attr,
struct lsm_ctx *ctx, u32 size, u32 flags)
-LSM_HOOK(int, -EINVAL, getprocattr, struct task_struct *p, const char *name, +LSM_HOOK(int, 0, getprocattr, struct task_struct *p, const char *name,
char **value)
-LSM_HOOK(int, -EINVAL, setprocattr, const char *name, void *value, size_t size) +LSM_HOOK(int, 0, setprocattr, const char *name, void *value, size_t size) LSM_HOOK(int, 0, ismaclabel, const char *name)LSM_HOOK(int, -EOPNOTSUPP, secid_to_secctx, u32 secid, struct lsm_context *cp) LSM_HOOK(int, -EOPNOTSUPP, lsmprop_to_secctx, struct lsm_prop *prop,
Signature · 1 line
paul-moore.com
Paul,
Quoted 85 lines · Paul Moore
Quoted 47 lines · Vitaly Chikunov
Quoted 46 lines · Paul Moore
Quoted 44 lines · Vitaly Chikunov
Hi,
We have boot failure when
CONFIG_LSMhas "bpf" listed before "selinux" (without bpf lsm scripts loaded). (This also happens with a boot with "security=selinux" if selinux was not in LSM= list but bpf is.)systemd reports on the failing boot attempt:
Failed to set SELinux security context generic_u:object_r:device:s0 for
/dev/shm: Invalid argument Mounting tmpfs to/dev/shmof type tmpfs with options mode=01777.
Mounting tmpfs (tmpfs) on/dev/shm(MS_NOSUID|MS_NODEV|MS_STRICTATIME "mode=01777")...
Failed to mount tmpfs (type tmpfs) on/dev/shm(MS_NOSUID|MS_NODEV|MS_STRICTATIME "mode=01777"): No such file or directory Failed to set SELinux security context generic_u:object_r:device:s0 for/dev/pts: Invalid argument Mounting devpts to/dev/ptsof type devpts with options mode=0620,gid=5.
Mounting devpts (devpts) on/dev/pts(MS_NOSUID|MS_NOEXEC "mode=0620,gid=5")...
Failed to mount devpts (type devpts) on/dev/pts(MS_NOSUID|MS_NOEXEC "mode=0620,gid=5"): No such file or directory No filesystem is currently mounted on/sys/fs/cgroup.
Failed to set SELinux security context generic_u:object_r:def_t:s0 for/sys/fs/cgroup: Invalid argument Mounting cgroup2 to/sys/fs/cgroupof type cgroup2 with options nsdelegate,memory_recursiveprot. Mounting cgroup2 (cgroup2) on/sys/fs/cgroup(MS_NOSUID|MS_NODEV|MS_NOEXEC "nsdelegate,memory_recursiveprot")... Failed to set SELinux security context generic_u:object_r:def_t:s0 for/sys/fs/pstore: Invalid argument Mounting pstore to/sys/fs/pstoreof type pstore with options n/a.
Mounting pstore (pstore) on/sys/fs/pstore(MS_NOSUID|MS_NODEV|MS_NOEXEC "")...
Failed to set SELinux security context generic_u:object_r:def_t:s0 for/sys/fs/bpf: Invalid argument Mounting bpf to/sys/fs/bpfof type bpf with options mode=0700.
Mounting bpf (bpf) on/sys/fs/bpf(MS_NOSUID|MS_NODEV|MS_NOEXEC "mode=0700")...
[!!!!!!] Failed to mount API filesystems.
Freezing execution'Invalid arguments' seems from
setfscreatecon_raw.Reproducer:
Boot with lsm=lockdown,capability,landlock,yama,safesetid,bpf,selinux,ima,evm
(none):~# cat /proc/thread-self/attr/current cat: /proc/thread-self/attr/current: Invalid argument (none):~# echo > /proc/thread-self/attr/fscreate bash: echo: write error: Invalid argumentThis appears to be caused by
security_getprocattr/security_setprocattriterating until the first hook defined (which is bpf) and returning with default value-EINVALbefore selinux even sees them.Quoted 8 lines
Quoted 4 lines
Thanks for the problem report, the general recommendation is to place the BPF LSM towards the end of the list (see the
CONFIG_LSMKconfighelp text), but we're trying to ensure that the BPF LSM works properly when placed anywhere in that list.I think if the order is important it should be handled in the code like for capabilities and ima/evm LSMs, not by forcing the user to discover the correct order with trial and error.
Patches are always welcome, although as I mentioned to you previously we are working towards supporting arbitrary ordering for BPF LSMs.
Quoted 6 lines
Quoted 5 lines
My apologies if you're abilities are well beyond this, but if you are familiar with patching and building your own kernel, have you tried changing the
LSM_RET_DEFAULTvalue for those functions to zero/0? Assuming userspace is happy with that, I believe it may solve this problem.Quoted 7 lines
I can patch and test if this is useful to find the correct solution, but the description is a bit vague. Did you mean
include/linux/lsm_hook_defs.h:301:LSM_HOOK(int,
-EINVAL, getprocattr, structtask_struct*p, const char *name, include/linux/lsm_hook_defs.h:303:LSM_HOOK(int,-EINVAL, setprocattr, const char *name, void *value,size_tsize)In these lines to replace
-EINVALwith 0?The patch below is what I had in mind (although be warned that was just a cut-n-paste into this email so it is likely whitespace damaged). If you are able to give that a test it would be great, if not, I can throw it on the todo pile.
include/linux/lsm_hook_defs.h +0
-0@@ -298,9 +298,9 @@ LSM_HOOK(int, -EOPNOTSUPP, getselfattr, unsigned int attr, struct lsm_ctx __user *ctx, u32 *size, u32 flags)
include/linux/lsm_hook_defs.h LSM_HOOK(int, -EOPNOTSUPP, getselfattr, unsigned int attr, · line 306
Quoted 10 lines
include/linux/lsm_hook_defs.h +2
-2LSM_HOOK(int, -EOPNOTSUPP, setselfattr, unsigned int attr, struct lsm_ctx *ctx, u32 size, u32 flags) -LSM_HOOK(int, -EINVAL, getprocattr, struct task_struct *p, const char *name, +LSM_HOOK(int, 0, getprocattr, struct task_struct *p, const char *name, char **value) -LSM_HOOK(int, -EINVAL, setprocattr, const char *name, void *value, size_t size) +LSM_HOOK(int, 0, setprocattr, const char *name, void *value, size_t size) LSM_HOOK(int, 0, ismaclabel, const char *name) LSM_HOOK(int, -EOPNOTSUPP, secid_to_secctx, u32 secid, struct lsm_context *cp) LSM_HOOK(int, -EOPNOTSUPP, lsmprop_to_secctx, struct lsm_prop *prop,
We will test it and report, but this may take some time.
Thanks,
Quoted 3 lines
Signature · 2 lines
-- paul-moore.com
Paul,
Quoted 90 lines · Vitaly Chikunov
Quoted 89 lines · Paul Moore
Quoted 47 lines · Vitaly Chikunov
Quoted 46 lines · Paul Moore
Quoted 44 lines · Vitaly Chikunov
Hi,
We have boot failure when
CONFIG_LSMhas "bpf" listed before "selinux" (without bpf lsm scripts loaded). (This also happens with a boot with "security=selinux" if selinux was not in LSM= list but bpf is.)systemd reports on the failing boot attempt:
Failed to set SELinux security context generic_u:object_r:device:s0 for
/dev/shm: Invalid argument Mounting tmpfs to/dev/shmof type tmpfs with options mode=01777.
Mounting tmpfs (tmpfs) on/dev/shm(MS_NOSUID|MS_NODEV|MS_STRICTATIME "mode=01777")...
Failed to mount tmpfs (type tmpfs) on/dev/shm(MS_NOSUID|MS_NODEV|MS_STRICTATIME "mode=01777"): No such file or directory Failed to set SELinux security context generic_u:object_r:device:s0 for/dev/pts: Invalid argument Mounting devpts to/dev/ptsof type devpts with options mode=0620,gid=5.
Mounting devpts (devpts) on/dev/pts(MS_NOSUID|MS_NOEXEC "mode=0620,gid=5")...
Failed to mount devpts (type devpts) on/dev/pts(MS_NOSUID|MS_NOEXEC "mode=0620,gid=5"): No such file or directory No filesystem is currently mounted on/sys/fs/cgroup.
Failed to set SELinux security context generic_u:object_r:def_t:s0 for/sys/fs/cgroup: Invalid argument Mounting cgroup2 to/sys/fs/cgroupof type cgroup2 with options nsdelegate,memory_recursiveprot. Mounting cgroup2 (cgroup2) on/sys/fs/cgroup(MS_NOSUID|MS_NODEV|MS_NOEXEC "nsdelegate,memory_recursiveprot")... Failed to set SELinux security context generic_u:object_r:def_t:s0 for/sys/fs/pstore: Invalid argument Mounting pstore to/sys/fs/pstoreof type pstore with options n/a.
Mounting pstore (pstore) on/sys/fs/pstore(MS_NOSUID|MS_NODEV|MS_NOEXEC "")...
Failed to set SELinux security context generic_u:object_r:def_t:s0 for/sys/fs/bpf: Invalid argument Mounting bpf to/sys/fs/bpfof type bpf with options mode=0700.
Mounting bpf (bpf) on/sys/fs/bpf(MS_NOSUID|MS_NODEV|MS_NOEXEC "mode=0700")...
[!!!!!!] Failed to mount API filesystems.
Freezing execution'Invalid arguments' seems from
setfscreatecon_raw.Reproducer:
Boot with lsm=lockdown,capability,landlock,yama,safesetid,bpf,selinux,ima,evm
(none):~# cat /proc/thread-self/attr/current cat: /proc/thread-self/attr/current: Invalid argument (none):~# echo > /proc/thread-self/attr/fscreate bash: echo: write error: Invalid argumentThis appears to be caused by
security_getprocattr/security_setprocattriterating until the first hook defined (which is bpf) and returning with default value-EINVALbefore selinux even sees them.Quoted 8 lines
Quoted 4 lines
Thanks for the problem report, the general recommendation is to place the BPF LSM towards the end of the list (see the
CONFIG_LSMKconfighelp text), but we're trying to ensure that the BPF LSM works properly when placed anywhere in that list.I think if the order is important it should be handled in the code like for capabilities and ima/evm LSMs, not by forcing the user to discover the correct order with trial and error.
Patches are always welcome, although as I mentioned to you previously we are working towards supporting arbitrary ordering for BPF LSMs.
Quoted 6 lines
Quoted 5 lines
My apologies if you're abilities are well beyond this, but if you are familiar with patching and building your own kernel, have you tried changing the
LSM_RET_DEFAULTvalue for those functions to zero/0? Assuming userspace is happy with that, I believe it may solve this problem.Quoted 7 lines
I can patch and test if this is useful to find the correct solution, but the description is a bit vague. Did you mean
include/linux/lsm_hook_defs.h:301:LSM_HOOK(int,
-EINVAL, getprocattr, structtask_struct*p, const char *name, include/linux/lsm_hook_defs.h:303:LSM_HOOK(int,-EINVAL, setprocattr, const char *name, void *value,size_tsize)In these lines to replace
-EINVALwith 0?The patch below is what I had in mind (although be warned that was just a cut-n-paste into this email so it is likely whitespace damaged). If you are able to give that a test it would be great, if not, I can throw it on the todo pile.
include/linux/lsm_hook_defs.h +1
-1@@ -298,9 +298,9 @@ LSM_HOOK(int, -EOPNOTSUPP, getselfattr, unsigned int attr, struct lsm_ctx __user *ctx, u32 *size, u32 flags) LSM_HOOK(int, -EOPNOTSUPP, setselfattr, unsigned int attr, struct lsm_ctx *ctx, u32 size, u32 flags) -LSM_HOOK(int, -EINVAL, getprocattr, struct task_struct *p, const char *name, +LSM_HOOK(int, 0, getprocattr, struct task_struct *p, const char *name,
Quoted 8 lines
include/linux/lsm_hook_defs.h LSM_HOOK(int, -EOPNOTSUPP, getselfattr, unsigned int attr, · line 306
Quoted 6 lines
include/linux/lsm_hook_defs.h +1
-1char **value) -LSM_HOOK(int, -EINVAL, setprocattr, const char *name, void *value, size_t size) +LSM_HOOK(int, 0, setprocattr, const char *name, void *value, size_t size) LSM_HOOK(int, 0, ismaclabel, const char *name) LSM_HOOK(int, -EOPNOTSUPP, secid_to_secctx, u32 secid, struct lsm_context *cp) LSM_HOOK(int, -EOPNOTSUPP, lsmprop_to_secctx, struct lsm_prop *prop,We will test it and report, but this may take some time.
Before trying the full system boot test, I tried to reproducer I posted before. With this patch applied (just ensure it's correct) over v6.12.87:
include/linux/lsm_hook_defs.h +2 -2
@@ -288,9 +288,9 @@ LSM_HOOK(int, -EOPNOTSUPP, getselfattr, unsigned int attr, struct lsm_ctx __user *ctx, u32 *size, u32 flags) LSM_HOOK(int, -EOPNOTSUPP, setselfattr, unsigned int attr, struct lsm_ctx *ctx, u32 size, u32 flags) -LSM_HOOK(int, -EINVAL, getprocattr, struct task_struct *p, const char *name, +LSM_HOOK(int, 0, getprocattr, struct task_struct *p, const char *name, char **value) -LSM_HOOK(int, -EINVAL, setprocattr, const char *name, void *value, size_t size) +LSM_HOOK(int, 0, setprocattr, const char *name, void *value, size_t size) LSM_HOOK(int, 0, ismaclabel, const char *name) LSM_HOOK(int, -EOPNOTSUPP, secid_to_secctx, u32 secid, char **secdata, u32 *seclen)
1. cat /proc/thread-self/attr/current does not report kernel as before.
2. echo > /proc/thread-self/attr/fscreate process hangs in R state, with strace showing infinite loop of
write(1, "\n", 1) = 0 write(1, "\n", 1) = 0 write(1, "\n", 1) = 0
Thanks,
Quoted 6 lines
Thanks,
Quoted 3 lines
Signature · 2 lines
-- paul-moore.com
Paul Moore
maintainerQuoted 5 lines · Vitaly Chikunov
Quoted 4 lines · Vitaly Chikunov
Quoted 3 lines · Paul Moore
Quoted 2 lines · Vitaly Chikunov
Quoted 1 line · Paul Moore
On Sun, May 10, 2026 at 5:17 PM Vitaly Chikunov <[email protected]> wrote:
...
Quoted 44 lines
Quoted 15 lines
Quoted 15 lines
The patch below is what I had in mind (although be warned that was just a cut-n-paste into this email so it is likely whitespace damaged). If you are able to give that a test it would be great, if not, I can throw it on the todo pile.
include/linux/lsm_hook_defs.h +1
-1@@ -298,9 +298,9 @@ LSM_HOOK(int, -EOPNOTSUPP, getselfattr, unsigned int attr, struct lsm_ctx __user *ctx, u32 *size, u32 flags) LSM_HOOK(int, -EOPNOTSUPP, setselfattr, unsigned int attr, struct lsm_ctx *ctx, u32 size, u32 flags) -LSM_HOOK(int, -EINVAL, getprocattr, struct task_struct *p, const char *name, +LSM_HOOK(int, 0, getprocattr, struct task_struct *p, const char *name,Quoted 8 lines
include/linux/lsm_hook_defs.h LSM_HOOK(int, -EOPNOTSUPP, getselfattr, unsigned int attr,
Quoted 6 lines
include/linux/lsm_hook_defs.h +1
-1char **value) -LSM_HOOK(int, -EINVAL, setprocattr, const char *name, void *value, size_t size) +LSM_HOOK(int, 0, setprocattr, const char *name, void *value, size_t size) LSM_HOOK(int, 0, ismaclabel, const char *name) LSM_HOOK(int, -EOPNOTSUPP, secid_to_secctx, u32 secid, struct lsm_context *cp) LSM_HOOK(int, -EOPNOTSUPP, lsmprop_to_secctx, struct lsm_prop *prop,We will test it and report, but this may take some time.
Before trying the full system boot test, I tried to reproducer I posted before. With this patch applied (just ensure it's correct) over v6.12.87:
include/linux/lsm_hook_defs.h +2
-2@@ -288,9 +288,9 @@ LSM_HOOK(int, -EOPNOTSUPP, getselfattr, unsigned int attr, struct lsm_ctx __user *ctx, u32 *size, u32 flags) LSM_HOOK(int, -EOPNOTSUPP, setselfattr, unsigned int attr, struct lsm_ctx *ctx, u32 size, u32 flags) -LSM_HOOK(int, -EINVAL, getprocattr, struct task_struct *p, const char *name, +LSM_HOOK(int, 0, getprocattr, struct task_struct *p, const char *name, char **value) -LSM_HOOK(int, -EINVAL, setprocattr, const char *name, void *value, size_t size) +LSM_HOOK(int, 0, setprocattr, const char *name, void *value, size_t size) LSM_HOOK(int, 0, ismaclabel, const char *name) LSM_HOOK(int, -EOPNOTSUPP, secid_to_secctx, u32 secid, char **secdata, u32 *seclen)
Quoted 6 lines
1.
cat /proc/thread-self/attr/currentdoes not reportkernelas before.
2.echo > /proc/thread-self/attr/fscreateprocess hangs in R state, with strace showing infinite loop ofwrite(1, "\n", 1) = 0 write(1, "\n", 1) = 0 write(1, "\n", 1) = 0
Bummer, I was worried userspace would be expecting something, but wasn't sure.
Thanks for giving that a test, it looks like we'll need some special handling for these hooks (which is okay, you'll see they already have special handling if you look at the code). In the meantime the workaround would be to place the BPF LSM after SELinux in your LSM ordering.
Signature · 1 line
paul-moore.com