** Description changed:

+ [ Impact ]
+ 
+ libapparmor did not correctly parse the features file when some of the 
features are prefixes of other features.
+ This first showed up with network ABI changes, which could cause issues with 
HWE kernels.
+ 
+ [ Test Plan ]
+ 
+ A test for this bug has been added to the libapparmor test suite, which can 
be run as part of AppArmor's QRT test suite.
+  * To prepare the QRT test suite (can be done on any machine):
+    - `git clone https://git.launchpad.net/qa-regression-testing`
+    - `./scripts/make-test-tarball ./scripts/test-apparmor.py`
+  * To run the QRT test suite:
+    - Copy the tarball onto the machine with the new AppArmor installed and 
extract it
+    - `sudo ./install-packages test-apparmor.py`
+    - Reboot after dependency installation
+    - `sudo ./test-apparmor.py -v`
+ 
+ [ Where problems could occur ]
+ 
+ This fix might introduce additional bugs in the libapparmor feature parsing. 
If it does so, it might lead to
+ incorrect feature detection and result in reduced mediation of features 
incorrectly detected to be present or missing from
+ the kernel side of the AppArmor mediation.
+ 
+ [ Other Info ]
+ 
+ This issue was originally fixed in 4.1.0~beta5-0ubuntu13 for Plucky. For
+ releases after Plucky, this LP bug tracks the backporting of a test for
+ this bug. For releases before Plucky, this LP bug tracks backporting the
+ fix along with the test.
+ 
+ ----Original bug report:
  
  Kernel version:
  ```
  Linux ubuntu-25-04 6.14.0-13-generic #13-Ubuntu SMP PREEMPT_DYNAMIC Wed Mar 
26 22:00:40 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
  ```
  
  With a simple profile with the network feature:
  ```
  profile "foo" {
-       network,
+  network,
  }
  ```
  
  The parser doesn't find the feature:
  
  ```
- # gdb --args /usr/sbin/apparmor_parser --verbose --skip-cache 
--skip-kernel-load foo.aa -o foo.bin                                        
+ # gdb --args /usr/sbin/apparmor_parser --verbose --skip-cache 
--skip-kernel-load foo.aa -o foo.bin
  
  (gdb) b set_supported_features
  Breakpoint 1 at 0x22d1c: file parser_main.c, line 627.
  (gdb) r
  Breakpoint 1, set_supported_features () at parser_main.c:627
  627             if (!features && aa_features_new_from_kernel(&features) == 
-1) {
  (gdb) n
  632             perms_create = 1;
- (gdb) 
+ (gdb)
  633             kernel_supports_policydb = aa_features_supports(features, 
"file");
- (gdb) 
+ (gdb)
  634             kernel_supports_network = aa_features_supports(features, 
"network");
- (gdb) 
+ (gdb)
  635             kernel_supports_unix = aa_features_supports(features,
  (gdb) print kernel_supports_network
  $1 = 0
  ```
  
  It looks like during `walk_one`, it encounters first the `network_v9`
  feature that causes a premature exit in the searching loop, which makes
  the algorithm fail:
  
  ```
  (gdb) print *features
- $3 = {ref_count = 1, 
-   string = "io_uring {mask {sqpoll override_creds\n}\n}\nquery {label 
{multi_transaction {yes\n}\ndata {yes\n}\nperms {allow deny audit 
quiet\n}\n}\n}\ndbus {mask {acquire send receive\n}\n}\nsignal {mask {hup int 
quit ill trap abrt bus fpe kill usr1 segv usr2 pipe alrm term stkflt chld cont 
stop stp ttin ttou urg xcpu xfsz vtalrm prof winch io pwr sys emt 
lost\n}\n}\nptrace {mask {read trace\n}\n}\ncaps {extended {yes\n}\nmask {chown 
dac_override dac_read_search fowner fsetid kill setgid setuid setpcap 
linux_immutable net_bind_service net_broadcast net_admin net_raw ipc_lock 
ipc_owner sys_module sys_rawio sys_chroot sys_ptrace sys_pacct sys_admin 
sys_boot sys_nice sys_resource sys_time sys_tty_config mknod lease audit_write 
audit_control setfcap mac_override mac_admin syslog wake_alarm block_suspend 
audit_read perfmon bpf checkpoint_restore\n}\n}\nrlimit {mask {cpu fsize data 
stack core rss nproc nofile memlock as locks sigpending msgqueue nice rtprio 
rttime\n}\n}\ncapability {0xffffff\n}\nnamespaces {userns_create 
{pciu&\n}\nmask {userns_create\n}\npivot_root {no\n}\nprofile {yes\n}\n}\nmount 
{move_mount {detached\n}\nmask {mount umount pivot_root\n}\n}\nnetwork_v9 
{af_unix {yes\n}\naf_mask {unspec unix inet ax25 ipx appletalk netrom bridge 
atmpvc x25 inet6 rose netbeui security key netlink packet ash econet atmsvc rds 
sna irda pppox wanpipe llc ib mpls can tipc bluetooth iucv rxrpc isdn phonet 
ieee802154 caif alg nfc vsock kcm qipcrtr smc xdp mctp\n}\n}\nnetwork_v8 
{af_inet {yes\n}\naf_mask {unspec unix inet ax25 ipx appletalk netrom bridge 
atmpvc x25 inet6 rose netbeui security key netlink packet ash econet atmsvc rds 
sna irda pppox wanpipe llc ib mpls can tipc bluetooth iucv rxrpc isdn phonet 
ieee802154 caif alg nfc vsock kcm qipcrtr smc xdp mctp\n}\n}\nnetwork {af_unix 
{yes\n}\naf_mask {unspec unix inet ax25 ipx appletalk netrom bridge atmpvc x25 
inet6 rose netbeui security key netlink packet ash econet atmsvc rds sna irda 
pppox wanpipe llc ib mpls can tipc bluetooth iucv rxrpc isdn phonet ieee802154 
caif alg nfc vsock kcm qipcrtr smc xdp mctp\n}\n}\nipc {posix_mqueue {create 
read write open delete setattr getattr\n}\n}\nfile {mask {create read write 
exec append mmap_exec link lock\n}\n}\ndomain {version {1.2\n}\nkill.signal 
{yes\n}\ndisconnected.ipc {yes\n}\ndisconnected.path {yes\n}\ninterruptible 
{yes\n}\nattach_conditions {xattr {yes\n}\n}\ncomputed_longest_left 
{yes\n}\npost_nnp_subset {yes\n}\nfix_binfmt_elf_mmap {yes\n}\nstack 
{yes\n}\nchange_profile {yes\n}\nchange_onexec 
{yes\n}\nunconfined_allowed_children {yes\n}\nchange_hatv {yes\n}\nchange_hat 
{yes\n}\n}\npolicy {notify {user {file\n}\n}\nunconfined_restrictions {io_uring 
{1\n}\nuserns {1\n}\nchange_profile {yes\n}\n}\nstate32 
{0x000001\n}\npermstable32 {allow deny subtree cond kill complain prompt audit 
quiet hide xindex tag label\n}\npermstable32_version {0x000003\n}\noutofband 
{0x000001\n}\nset_load {yes\n}\nversions {v9 {yes\n}\nv8 {yes\n}\nv7 
{yes\n}\nv6 {yes\n}\nv5 {yes\n}\n}\n}\n", '\000' <repeats 5323 times>}
+ $3 = {ref_count = 1,
+   string = "io_uring {mask {sqpoll override_creds\n}\n}\nquery {label 
{multi_transaction {yes\n}\ndata {yes\n}\nperms {allow deny audit 
quiet\n}\n}\n}\ndbus {mask {acquire send receive\n}\n}\nsignal {mask {hup int 
quit ill trap abrt bus fpe kill usr1 segv usr2 pipe alrm term stkflt chld cont 
stop stp ttin ttou urg xcpu xfsz vtalrm prof winch io pwr sys emt 
lost\n}\n}\nptrace {mask {read trace\n}\n}\ncaps {extended {yes\n}\nmask {chown 
dac_override dac_read_search fowner fsetid kill setgid setuid setpcap 
linux_immutable net_bind_service net_broadcast net_admin net_raw ipc_lock 
ipc_owner sys_module sys_rawio sys_chroot sys_ptrace sys_pacct sys_admin 
sys_boot sys_nice sys_resource sys_time sys_tty_config mknod lease audit_write 
audit_control setfcap mac_override mac_admin syslog wake_alarm block_suspend 
audit_read perfmon bpf checkpoint_restore\n}\n}\nrlimit {mask {cpu fsize data 
stack core rss nproc nofile memlock as locks sigpending msgqueue nice rtprio 
rttime\n}\n}\ncapability {0xffffff\n}\nnamespaces {userns_create 
{pciu&\n}\nmask {userns_create\n}\npivot_root {no\n}\nprofile {yes\n}\n}\nmount 
{move_mount {detached\n}\nmask {mount umount pivot_root\n}\n}\nnetwork_v9 
{af_unix {yes\n}\naf_mask {unspec unix inet ax25 ipx appletalk netrom bridge 
atmpvc x25 inet6 rose netbeui security key netlink packet ash econet atmsvc rds 
sna irda pppox wanpipe llc ib mpls can tipc bluetooth iucv rxrpc isdn phonet 
ieee802154 caif alg nfc vsock kcm qipcrtr smc xdp mctp\n}\n}\nnetwork_v8 
{af_inet {yes\n}\naf_mask {unspec unix inet ax25 ipx appletalk netrom bridge 
atmpvc x25 inet6 rose netbeui security key netlink packet ash econet atmsvc rds 
sna irda pppox wanpipe llc ib mpls can tipc bluetooth iucv rxrpc isdn phonet 
ieee802154 caif alg nfc vsock kcm qipcrtr smc xdp mctp\n}\n}\nnetwork {af_unix 
{yes\n}\naf_mask {unspec unix inet ax25 ipx appletalk netrom bridge atmpvc x25 
inet6 rose netbeui security key netlink packet ash econet atmsvc rds sna irda 
pppox wanpipe llc ib mpls can tipc bluetooth iucv rxrpc isdn phonet ieee802154 
caif alg nfc vsock kcm qipcrtr smc xdp mctp\n}\n}\nipc {posix_mqueue {create 
read write open delete setattr getattr\n}\n}\nfile {mask {create read write 
exec append mmap_exec link lock\n}\n}\ndomain {version {1.2\n}\nkill.signal 
{yes\n}\ndisconnected.ipc {yes\n}\ndisconnected.path {yes\n}\ninterruptible 
{yes\n}\nattach_conditions {xattr {yes\n}\n}\ncomputed_longest_left 
{yes\n}\npost_nnp_subset {yes\n}\nfix_binfmt_elf_mmap {yes\n}\nstack 
{yes\n}\nchange_profile {yes\n}\nchange_onexec 
{yes\n}\nunconfined_allowed_children {yes\n}\nchange_hatv {yes\n}\nchange_hat 
{yes\n}\n}\npolicy {notify {user {file\n}\n}\nunconfined_restrictions {io_uring 
{1\n}\nuserns {1\n}\nchange_profile {yes\n}\n}\nstate32 
{0x000001\n}\npermstable32 {allow deny subtree cond kill complain prompt audit 
quiet hide xindex tag label\n}\npermstable32_version {0x000003\n}\noutofband 
{0x000001\n}\nset_load {yes\n}\nversions {v9 {yes\n}\nv8 {yes\n}\nv7 
{yes\n}\nv6 {yes\n}\nv5 {yes\n}\n}\n}\n", '\000' <repeats 5323 times>}
  ```
  
  ```
  Breakpoint 2, walk_one (str=0x7fffffffd9c8, component=0x7fffffffd9e0, 
is_top_level=true) at features.c:346
  346                             i++;
- (gdb) print cur                                                               
                 
+ (gdb) print cur
  $4 = 0x55555572b063 "network_v9 {af_unix {yes\n}\naf_mask {unspec unix inet 
ax25 ipx appletalk netrom bridge atmpvc x25 inet6 rose netbeui security key 
netlink packet ash econet atmsvc rds s
  na irda pppox wanpipe llc ib mpls"...
  ```
  
  ```
  (gdb) print component->str
  $8 = 0x5555556ab53d "network"
  ```
  
  ```
- (gdb) 
+ (gdb)
  323             while(!isnul(*cur) && i < component->len) {
- (gdb) 
+ (gdb)
  354             if (i != component->len) {
- (gdb) 
+ (gdb)
  356             } else if (!isbrace_space_or_nul(*cur))
- (gdb) 
+ (gdb)
  357                     return false;
  (gdb) print *cur
  $9 = 95 '_'
  ```

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2105986

Title:
  Apparmor parser 2.12 doesn't find kernel feature that is a substring
  of another that appears first in search algorithm

To manage notifications about this bug go to:
https://bugs.launchpad.net/apparmor/+bug/2105986/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to