Skip to content

R5 AppArmor and SELinux: the LSM framework, permissive and then enforcing #540

Open

Description

@tamnd

Part of #14.

rukernel has no LSM framework. The permission checks are the capability and mode checks of rk_vfs::cred and seccomp. There is no securityfs, no /sys/kernel/security/lsm, no /proc/PID/attr, no lsm_* system call, and no Landlock or Yama. The security.* xattrs can be stored and read. LTP tests that read /sys/kernel/security/lsm take the path for a kernel with no LSM. spec/13-security.md section 13.2 has the scope.

Scope

Done when

Ubuntu boots with AppArmor enforcing. Fedora boots with SELinux enforcing. This is the exit of the fifth item of #14.

Test each task on x86_64 and on arm64. Give the result of both in the PR body.

Linux reference: security/security.c, include/linux/lsm_hook_defs.h, security/inode.c, security/lsm_syscalls.c, security/apparmor/policy_unpack.c, security/selinux/hooks.c, security/selinux/ss/services.c, kernel/audit.c.

Activity

  1. added
    kind/feature
    area/security
    on Nov 2, 2026
  2. tamnd commented on Nov 5, 2026

    @tamnd
    OwnerAuthor

    #596 is merged. It adds the LSM framework: the hook table with the names of Linux, the first error of the modules as call_int_hook, the security blobs, the boot order with lsm= and security=, the capability module first, and the hooks of the file, exec, task and socket paths. After the rebase on #594, Cred::capable checks ns_capable in the first user namespace and then calls the capable hooks. Tests: cargo test -p rk-vfs --lib 107 passed, and -- only lsm passed on x86_64 and arm64 (-- only userns also passed on x86_64). Item 1 is ticked after the next PR, which gives the super blocks and the IPC objects their blobs.

  3. tamnd commented on Nov 5, 2026

    @tamnd
    OwnerAuthor

    #601 is merged. The super blocks get their blob in get_tree, and each message queue, semaphore set and shared memory segment has a security part with the alloc, free and associate hooks and the ipc_permission hook after the mode check. Tests: cargo test -p rk-vfs --lib 108 passed, and -- only lsm passed on x86_64 and arm64. Item 1 is now ticked. The next PR adds securityfs, /proc/PID/attr and the lsm_* system calls.

  4. tamnd commented on Nov 5, 2026

    @tamnd
    OwnerAuthor

    #604 is merged. It adds securityfs at /sys/kernel/security with the file lsm, the system calls lsm_get_self_attr, lsm_set_self_attr and lsm_list_modules, and /proc/PID/attr. Tests: the rk-vfs unit tests passed, and -- only lsm passed on x86_64 and arm64. With the LTP, lsm_get_self_attr02, lsm_list_modules01 and lsm_list_modules02 pass. The other three give TCONF until a module gives LSM_ATTR_CURRENT. Item 2 is not ticked yet: the next PR adds Yama and the lsm kselftests.

  5. tamnd commented on Nov 5, 2026

    @tamnd
    OwnerAuthor

    #605 is merged. It adds Yama with kernel.yama.ptrace_scope (0 to 3, and 3 stays) and PR_SET_PTRACER, and it adds the lsm tests to tools/kselftest/build.sh. Tests: lsm_get_self_attr_test 6/6, lsm_list_modules_test 5/5 and lsm_set_self_attr_test 4/4 pass. LTP ptrace01 to ptrace11: 9 pass, and ptrace04 and ptrace07 give TCONF, as in the baseline. -- only lsm passed on x86_64 and arm64. Item 2 is now ticked. The next PR adds NETLINK_AUDIT (item 7, part 1).

  6. tamnd commented on Nov 5, 2026

    @tamnd
    OwnerAuthor

    #613 is merged. It adds NETLINK_AUDIT with AUDIT_GET, AUDIT_SET and the user messages (#540, item 7, part 1). The records go to auditd, or to the kernel log if auditd is not there, and a copy goes to the group AUDIT_NLGRP_READLOG. Tests: cargo test -p rk-net --lib 83 passed, and -- only audit passed on x86_64 (with the bzImage and UEFI) and arm64, with 24 checks. Item 7 is not ticked: the AVC and AppArmor records need the modules, and the fedora test with ausearch -m AVC needs them too.

  7. tamnd commented on Nov 7, 2026

    @tamnd
    OwnerAuthor

    Item 3, part 1 of 5: #657 adds the AppArmor module and its securityfs tree. The module is on with apparmor=1 or when lsm= names it. /sys/kernel/security/apparmor has features/, profiles, revision, .load, .replace, .remove and policy/. A load gives EPROTO for now. Next: the unpack of the binary policy and the profile tree. Item 3 stays open.

  8. tamnd commented on Nov 8, 2026

    @tamnd
    OwnerAuthor

    Item 3, part 2 of 6: #662 unpacks the binary policy of apparmor_parser and keeps the tree of profiles. .load, .replace and .remove change the tree, and profiles and revision show it. The audit records of the changes go to the kernel log, as on Linux. Next: the label of a task, the attach at exec, the learning profiles and /proc/PID/attr. Item 3 stays open.

  9. tamnd commented on Nov 8, 2026

    @tamnd
    OwnerAuthor

    Item 3, part 3 of 6: #666 attaches the profiles at exec. The cred of a task holds its label. A program gets the profile that matches its path, with the conflict check of Linux. The exec rules give the next label, with the ix, px, cx and ux fallbacks. In complain mode, an exec with no rule makes a learning profile PARENT//null-NAME and an ALLOWED record in the kernel log. /proc/PID/attr/current shows the label and the mode. Next: the file hooks with the DFA match of the path. Item 3 stays open.

  10. tamnd commented on Nov 9, 2026

    @tamnd
    OwnerAuthor

    Item 3, part 4 of 6: #672 checks the open files with the file rules of the profiles: an open, a read, a write, an flock and an mmap. The name of a directory ends with /, and an open file keeps the label and the permissions that the rules checked. In complain mode, an operation that the rules do not allow goes on with an ALLOWED record in the kernel log, as on Linux. Next: change_profile and change_hat. Item 3 stays open.

  11. tamnd commented on Nov 9, 2026

    @tamnd
    OwnerAuthor

    Item 3, part 5 of 6: #677 lets a task change its label with changehat, changeprofile and exec in /proc/self/attr and with lsm_set_self_attr. A hat keeps the label before it with a token, and a wrong token kills the task. In complain mode, a missing hat or profile gives a learning profile. The records in the kernel log are as on Linux. Next: the tests of apparmor_parser and aa-status and the regression tests. Item 3 stays open.

  12. tamnd commented on Nov 11, 2026

    @tamnd
    OwnerAuthor

    Item 3, part 6 of 6: #693 adds the child policy namespaces and the stacks of AppArmor, and a fix of the exec hook for a script. With it, apparmor_parser loads the 162 profiles of Ubuntu 26.04, and aa-status lists them with the same modes as on Linux. tools/apparmor runs the AppArmor regression tests in complain mode under QEMU, on rukernel and on Linux 6.8.0-147-generic. The reference passes 5 of the 16 tests of the load and the attach (profiles, at_secure, complain, environ, longpath), with 198 checks. rukernel passes all these tests and checks, so it reaches the pass set of the reference. tools/apparmor/report.md has the results. Item 3 is done.

  13. 11 remaining items

  14. tamnd commented on Nov 14, 2026

    @tamnd
    OwnerAuthor

    Item 4 is done. AppArmor works in enforce mode with the file, capability, signal, ptrace, network, user namespace, mount and Unix socket rules (#698, #710, #715, #716, #718, #723, #725, #727, #728, #731). A denial gives EACCES and a record with the fields of Linux. The AppArmor regression tests reach the pass set of Linux 6.8. userns and net_inet fail on Linux 6.8 too. The ubuntu boot test boots Ubuntu 26.04 with AppArmor in enforce mode to multi-user.target (#736).

  15. tamnd commented on Nov 14, 2026

    @tamnd
    OwnerAuthor

    Item 7: #739 is merged. The apparmor boot test now checks that a denial of AppArmor goes to auditd as an AUDIT_AVC record with the fields of Linux, and that the group AUDIT_NLGRP_READLOG gets the same record, as journald reads it. A record that goes to auditd does not go to the kernel log. The test passes on x86_64 and arm64. The item stays open: its exit needs ausearch -m AVC on the fedora boot test of the SELinux items.

  16. tamnd commented on Nov 18, 2026

    @tamnd
    OwnerAuthor

    Item 5, part 5: #799 is merged. It adds the first permission checks of SELinux, as hooks.c of Linux: selinux_inode_permission for a path walk, access and an open, selinux_file_open with the policy capability open_perms, selinux_inode_getattr for stat, and selinux_inode_setattr for chmod, chown, utimensat and a truncate. The records of the log have the name, path, dev and ino fields of Linux. The selinux boot test passes on x86_64 and arm64 with 83 of 83 checks. The earlier parts are #757, #787, #790 and #795. The directory operations and the labels of new files come next.

  17. tamnd commented on Nov 20, 2026

    @tamnd
    OwnerAuthor

    Item 5, part 6: #803 is merged. It adds the SELinux checks of the operations on the names of the directories, as may_create, may_link and may_rename of hooks.c of Linux: add_name, remove_name, search, reparent and rmdir on the directory, create, link, unlink and rename on the file, and associate with the file system, for a create, mkdir, mknod, symlink, link, unlink, rmdir and rename. The label for the checks of a new file comes from fscreate or from the type_transition rule for its name. The selinux boot test passes on x86_64 and arm64 with 95 of 95 checks. The earlier parts are #757, #787, #790, #795 and #799. The label of the new inode and a write of security.selinux come next.

  18. tamnd commented on Nov 20, 2026

    @tamnd
    OwnerAuthor

    Item 5, part 7: #804 is merged. A new file now gets its SELinux label when the VFS makes it, from fscreate or from the type_transition rule for its name, and a file system that keeps the labels gets the attribute security.selinux, as selinux_inode_init_security of Linux. A setxattr of security.selinux needs the owner or CAP_FOWNER, relabelfrom, relabelto, the validatetrans rules and associate, and removexattr of the label gives EACCES, as selinux_inode_setxattr, selinux_inode_post_setxattr, selinux_inode_setsecurity and selinux_inode_removexattr. The selinux boot test has 104 checks on x86_64 and arm64. Next: file_permission, ioctl, mmap, mprotect, locks and fcntl.

  19. tamnd commented on Nov 20, 2026

    @tamnd
    OwnerAuthor

    Item 5, part 8: #805 is merged. An open file now keeps the SID of the task that made it, the label of the inode and the number of the policy load, as struct file_security_struct of Linux. A read or a write checks the permissions again if one of them changed, and a write to a file with O_APPEND needs append, as selinux_file_permission. A file of another SID needs use of the class fd, a lock needs lock, and an F_SETFL that removes O_APPEND needs write, as file_has_perm, selinux_file_lock and selinux_file_fcntl. The test policy has the new rule allow kernel_t self : fd use, because the kernel opens the console with the SID kernel and init runs with the SID init. The selinux boot test has 112 checks on x86_64 and arm64. Next: ioctl with the extended permissions, then mmap and mprotect.

  20. tamnd commented on Nov 20, 2026

    @tamnd
    OwnerAuthor

    Item 5, part 9: #812 is merged. An ioctl now has the SELinux checks of Linux, as selinux_file_ioctl and ioctl_has_perm, with the extended permissions of the allowxperm, auditallowxperm and dontauditxperm rules, as avc_has_extended_perms and security_compute_xperms_decision. A command needs ioctl and, if the policy has rules for its driver, the rule for its function. The AVC keeps the decisions of each driver, and the records have ioctlcmd. FIONREAD, FIBMAP, FIGETBSZ and the commands that read the flags need getattr, the commands that change them need setattr, FIONBIO and FIOASYNC need only use of the descriptor, and KDSKBENT and KDSKBSENT need sys_tty_config, as cred_has_capability. The selinux boot test has 116 checks on x86_64 and arm64. Next: mmap_file (part 10), then file_mprotect in four small parts after the reclaim change of #752 merges.

  21. tamnd commented on Nov 21, 2026

    @tamnd
    OwnerAuthor

    Item 5, part 10: #821 is merged. A map of a file or of anonymous memory now has the SELinux checks of Linux, as selinux_mmap_file and file_map_prot_check. A map of a file needs map, read, write if it is shared and can write, and execute if it can run code. A map that can run code needs execmem of the process if it is anonymous memory, a file without an inode, or a private map that can also write. The selinux boot test has 122 checks, and they pass on x86_64 and arm64. The 52 unit tests pass. Next: file_mprotect, after the PR of #752 item 3 merges, and the checks of the processes (signals, ptrace, the scheduler and the capabilities), which do not need #752.

  22. tamnd commented on Nov 21, 2026

    @tamnd
    OwnerAuthor

    Item 5, part 11: #822 is merged. The operations on other tasks now have the SELinux checks of Linux, as selinux_task_kill, the other task hooks, selinux_capget, selinux_capset, selinux_ptrace_access_check and selinux_ptrace_traceme. A signal needs sigkill, sigstop, sigchld, signull for the signal 0, or signal. getpgid, getsid and setpgid of a PID need getpgid, getsession and setpgid. A change of the nice value, of the I/O priority or of the scheduler needs setsched, and a read of them needs getsched. prlimit on another process needs getrlimit or setrlimit, capget needs getcap, capset needs setcap, and PTRACE_ATTACH and PTRACE_TRACEME need ptrace. As check_prlimit_permission of Linux, prlimit on the caller itself does not call the hook. The selinux boot test has 134 checks, and they pass on x86_64 and arm64. The 53 unit tests pass. Next: the checks of the mounts (mounton, remount, unmount), which do not need #752, and file_mprotect after the PR of #752 item 3 merges.

  23. tamnd commented on Nov 21, 2026

    @tamnd
    OwnerAuthor

    Item 5, part 12: #824 is merged. The mounts now have the SELinux checks of Linux, as selinux_mount, selinux_move_mount and selinux_umount. A new mount and a move of a mount need mounton on the place of the mount, a remount needs remount of the file system, and an unmount needs unmount of the file system. The selinux boot test has 140 checks, and they pass on x86_64 and arm64. The 55 unit tests pass. Next: file_mprotect after the PR of #752 item 3 merges. Other parts that do not need #752: selinux_capable, the checks of the sockets and the checks of System V IPC.

  24. tamnd commented on Nov 23, 2026

    @tamnd
    OwnerAuthor

    Item 5, part 13: #828 is merged. The capable hook gets the user namespace, and SELinux checks each capability through the AVC in the classes capability and capability2, or cap_userns and cap2_userns in a user namespace that is not the first one, as cred_has_capability of Linux. The checks of CAP_MAC_ADMIN for the labels use the same function. Tests: 56 unit tests, and 145 of 145 boot tests on x86_64 and arm64. Next: the checks of the System V IPC objects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/securitykind/feature

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions