Carried kernel patches#
The kernel changes shirudo needs. testing/kernel/patches/ carries
these changes for the test suite. A production kernel needs the same
changes.
Summary#
Patch |
Author |
In bpf-next |
Architectures |
|---|---|---|---|
|
KP Singh |
No |
All |
|
Daniel Borkmann |
No |
All |
|
Daniel Borkmann |
No |
All |
|
Daniel Borkmann |
No |
All |
|
Daniel Borkmann |
No |
All |
“In bpf-next” was checked against the bpf-next tree at commit
57fae4059380: include/linux/lsm_hook_defs.h there has no
tpm_command hook, fs/bpf_fs_kfuncs.c checks the calling task’s
read permission before it returns a security.bpf. xattr to an LSM
program, the sleepable hook set of kernel/bpf/bpf_lsm.c lacks
inode_mkdir, inode_link, inode_set_acl, inode_remove_acl,
inode_file_setattr and inode_copy_up, the verifier trusts
d_inode of a dentry but not d_parent, and may_access_mm()
grants a read-mode access to CAP_PERFMON without asking an LSM.
An x86-64 target also needs upstream commit 31ac959c915c
(“x86/ftrace: Mark jmp mode by clearing bit 63 of trampoline address”),
which bpf-next and the bpf fixes tree for 7.4 contain and which the
tree does not carry; System requirements says
why.
How the test kernel includes them#
testing/kernel/build-kernel.sh applies the patches to the pinned
bpf-next commit and builds the kernel package with the configuration in
testing/kernel/. CI checks the BTF ABI and LSM hooks before it
stages the image for the test VM.
TPM command LSM hook#
- Subject
tpm: Let LSMs inspect userspace commands
- Files
drivers/char/tpm/tpm-dev-common.c,include/linux/lsm_hook_defs.h,include/linux/security.h,security/security.c.- What it changes
tpm_common_write(), the write handler of both/dev/tpm0and/dev/tpmrm0, calls a new hook,security_tpm_command(file, command, command_len), after it has copied the command from userspace and validated the header, and before it sends or queues the command.command_lenis the length the header declares, so trailing bytes of the write are not part of the decision; the command stays in the device buffer until the hook returns. The patch also refuses a header whose declared length is smaller than the header itself.- Why shirudo needs it
The key that authorizes extensions of shirudo’s NV register lives in the TPM and is recreatable by any process that knows its public input, which the identity map holds. A guard on the key cannot work, so
lsm/tpm_commandguards the command: it refusesTPM2_NV_Extendof the frozen index to tasks without runtime authority. A check when the device is opened would miss descriptors opened earlier or inherited from another process; the hook sees every command. Measurement register and attestation explains the writer.- Without it
The kernel’s BTF has no
bpf_lsm_tpm_command, so the pre-flight checkkernel_lsm_hooksfails andinitstops before it loads anything. The boot is not stopped, and the target runs without enforcement, as Boot from initrd to root describes.
Label reads without the caller’s permission#
- Subject
bpf: Read security.bpf xattrs for LSM programs without the caller’s permission
- Files
fs/bpf_fs_kfuncs.c.- What it changes
bpf_get_dentry_xattr()andbpf_get_file_xattr()check that the calling task may read the inode before they return an extended attribute, foruser.andsecurity.bpf.names alike. The patch skips that check forsecurity.bpf.names, which a BPF LSM program keeps for itself, as SELinux, Smack and EVM read their labels with__vfs_getxattr()in kernel context.user.names keep the check.- Why shirudo needs it
The seal reads
security.bpf.shirudoin the hooks that decide the calling task’s operation, and that task is the one the seal may refuse. With the check, the task’s read permission decides whether the seal sees the label, and root arranges a read that fails: an idmapped bind mount shows its files as another id’s, an ACL grants another id a write without a read, a file system uid set withsetfsuid()keepsCAP_SYS_ADMINwithout the DAC capabilities, and another LSM’sinode_permissionpolicy refuses the read. Seal labels and task marks explains the verdict.- Without it
The seal loads and runs. A label read that fails with
EACCESorEPERMis decided by the mark of the inode, or of the directory the operation changes, and a labeled inode without a mark looks unlabeled to the seal. Seal labels and task marks lists this under its limits.
Sleepable programs on the remaining inode hooks#
- Subject
bpf: Let sleepable LSM programs attach to the remaining inode hooks
- Files
kernel/bpf/bpf_lsm.c.- What it changes
The kernel keeps a list of the LSM hooks that take a sleepable BPF program. The patch adds
inode_mkdir,inode_link,inode_set_acl,inode_remove_acl,inode_file_setattrandinode_copy_upto it. Each is called from process context with the inode lock held, as the hooks already in the list are, and may sleep.- Why shirudo needs it
The seal reads labels with
bpf_get_dentry_xattr(), which sleeps, so only a sleepable program can decide an operation by a label.lsm.s/inode_mkdirandlsm.s/inode_linkread the label of the directory the entry goes into,lsm.s/inode_set_acl,lsm.s/inode_remove_aclandlsm.s/inode_file_setattrthe label of the inode they change, andlsm.s/inode_copy_upthe label of the inode an overlay copies up, instead of a mark that an eviction of the inode empties.- Without it
The kernel refuses the
lsm.s/form of those programs, so thesealobject fails to load andinitfails at “loading enforcement”, with the result the TPM command hook describes.
Trusted dentry parent#
- Subject
bpf: Treat dentry->d_parent as a trusted pointer
- Files
kernel/bpf/verifier.c.- What it changes
The verifier lists the fields of a kernel structure that a program may read as trusted pointers. For
struct dentryit listsd_inode; the patch addsd_parentbeside it, as trusted or null, so a program checks it for NULL before use. The parent of a dentry an inode hook receives is stable while the hook runs, under the parent’s inode lock the caller holds, and is never NULL, since the root’s points to itself.- Why shirudo needs it
inode_create,inode_mkdir,inode_symlink,inode_mknod,inode_linkandinode_renamereceive the directory an entry goes into as astruct inodeand the entry as a dentry.bpf_get_dentry_xattr()takes a dentry, and the only one the seal has for the directory isdentry->d_parent. The seal reads the directory’s label from it and refreshes the directory’s mark on the way, whichinode_init_securitylabels the new inode from.- Without it
The verifier refuses
d_parentas the kfunc’s argument, so thesealobject fails to load andinitfails at “loading enforcement”, with the result the TPM command hook describes.
Read-only mm access hook#
- Subject
mm: Let LSMs check read-only remote mm access under CAP_PERFMON
- Files
kernel/fork.c,include/linux/lsm_hook_defs.h,include/linux/security.h,security/security.c.- What it changes
may_access_mm(), whichmm_access()asks before it hands out another task’s memory, grants a read-mode access to a caller withCAP_PERFMONorCAP_SYS_ADMINafterptrace_may_access()refused it, since commit0c555a3c1bc9(“mm,procfs: allow read-only remote mm access under CAP_PERFMON”). The patch has it call a new hook,security_mm_read_access(task, mode), before it grants the access that way, and refuse it when the hook does. An accessptrace_may_access()allows is not checked again.- Why shirudo needs it
The seal refuses every ptrace mode against a task with runtime authority, and
ptrace_may_access()asks it, but the perfmon path comes after that refusal: root opened/proc/<pid>/environ,maps,smaps,numa_maps,pagemapandauxvof a running command, its environment and the layout of its memory. The seal attacheslsm/mm_read_accessand refuses a marked task there too.- Without it
The kernel’s BTF has no
bpf_lsm_mm_read_access, so the pre-flight checkkernel_lsm_hooksfails andinitstops before it loads anything, with the result the TPM command hook describes.