linux/security/apparmor
John Johansen 3daad923a8 apparmor: policy_int make sure list heads are initialized before fail path
If profile create fails before policy_init is complete the list heads
are not properly initialized causing profile_free() sanity checks to
trigger the following splat.

AppArmor WARN aa_policy_destroy: (((!list_empty(&policy->profiles) && (&policy->profiles)->prev != ((void *) 0x122 + (0xdead000000000000UL))))):
WARNING: security/apparmor/lib.c:509 at aa_policy_destroy+0x164/0x1b0 security/apparmor/lib.c:509, CPU#0: syz.0.17/5541
Modules linked in:
CPU: 0 UID: 0 PID: 5541 Comm: syz.0.17 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
RIP: 0010:aa_policy_destroy+0x16b/0x1b0 security/apparmor/lib.c:509
Code: 85 ed 7e 4d e8 96 bc 37 fd 5b 41 5c 41 5e 41 5f 5d e9 19 27 4e 07 cc e8 83 bc 37 fd 48 8d 3d 0c f0 d3 0b 48 c7 c6 a4 eb 38 8e <67> 48 0f b9 3a e9 04 ff ff ff e8 66 bc 37 fd 48 8d 3d ff ef d3 0b
RSP: 0018:ffffc9000345eaa0 EFLAGS: 00010293
RAX: ffffffff848f530d RBX: ffff88803f734800 RCX: ffff88801af2a580
RDX: 0000000000000000 RSI: ffffffff8e38eba4 RDI: ffffffff90634320
RBP: 0000000000000000 R08: 0000000000000cc0 R09: 00000000ffffffff
R10: dffffc0000000000 R11: fffffbfff1d95913 R12: dead000000000122
R13: ffff88803f734800 R14: ffff88803f734828 R15: dffffc0000000000
FS:  00007f5f6a1836c0(0000) GS:ffff88808c519000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 000055d02407b048 CR3: 0000000012aa9000 CR4: 0000000000352ef0
Call Trace:
 <TASK>
 aa_free_profile+0x9d/0x9f0 security/apparmor/policy.c:334
 aa_alloc_profile+0x1e4/0x3e0 security/apparmor/policy.c:416
 unpack_profile security/apparmor/policy_unpack.c:1153 [inline]
 aa_unpack+0x17db/0x7430 security/apparmor/policy_unpack.c:1748
 aa_replace_profiles+0x226/0x2a20 security/apparmor/policy.c:1183
 policy_update+0x234/0x4a0 security/apparmor/apparmorfs.c:505
 profile_load+0x1cb/0x320 security/apparmor/apparmorfs.c:522
 vfs_write+0x296/0xba0 fs/read_write.c:685
 ksys_write+0x150/0x270 fs/read_write.c:739
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x166/0x520 arch/x86/entry/syscall_64.c:84
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f5f6939e0d9
Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f5f6a183028 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 00007f5f69625fa0 RCX: 00007f5f6939e0d9
RDX: 0000000000000041 RSI: 0000200000000400 RDI: 0000000000000003
RBP: 00007f5f6a183090 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000001
R13: 00007f5f69626038 R14: 00007f5f69625fa0 R15: 00007ffe23725c18

Reported-by: syzbot+faed97c4ed43bfe7fee5@syzkaller.appspotmail.com
Link: https://syzkaller.appspot.com/bug?extid=faed97c4ed43bfe7fee5
Fixes: fe6bb31f59 ("apparmor: split out shared policy_XXX fns to lib")
Signed-off-by: John Johansen <john.johansen@canonical.com>
2026-08-26 00:03:13 -07:00
..
include apparmor: fix deadlock in complain-mode change_hat 2026-08-15 23:39:38 -07:00
.gitignore .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
.kunitconfig apparmor: add .kunitconfig 2026-02-01 12:01:19 -08:00
af_inet.c apparmor: push inet mediation into profile callbacks, and improve auditing 2026-08-10 22:49:41 -07:00
af_unix.c apparmor: constify aa_dfa parameters on read-only compute paths 2026-08-10 22:49:43 -07:00
apparmorfs.c apparmor: constify aa_profile parameters on read-only compute paths 2026-08-10 22:49:43 -07:00
audit.c apparmor: refactory mount to use check_perms 2026-08-10 22:49:42 -07:00
capability.c apparmor: constify aa_profile parameters on read-only compute paths 2026-08-10 22:49:43 -07:00
crypto.c apparmor: move initcalls to the LSM framework 2025-10-22 19:24:27 -04:00
domain.c apparmor: fix deadlock in complain-mode change_hat 2026-08-15 23:39:38 -07:00
file.c apparmor: add audit mode to provide a mechanism to silence complain messages 2026-08-10 22:49:42 -07:00
ipc.c apparmor: transition from a list of rules to a vector of rules 2025-07-20 02:31:06 -07:00
Kconfig apparmor: Fix build failure when ZSTD_DECOMPRESS is not enabled 2026-07-30 06:42:58 -07:00
label.c apparmor: constify aa_label parameters on read-only query helpers 2026-08-10 22:49:43 -07:00
lib.c apparmor: policy_int make sure list heads are initialized before fail path 2026-08-26 00:03:13 -07:00
lsm.c apparmor: mark static tables and structs as read only 2026-08-10 22:49:42 -07:00
Makefile apparmor: refactor network sock mediation in preparation for inet mediation 2026-08-10 22:49:41 -07:00
match.c apparmor: constify aa_dfa parameters on read-only compute paths 2026-08-10 22:49:43 -07:00
mount.c apparmor: constify aa_dfa parameters on read-only compute paths 2026-08-10 22:49:43 -07:00
net.c apparmor: constify aa_dfa parameters on read-only compute paths 2026-08-10 22:49:43 -07:00
nulldfa.in apparmor: cleanup add proper line wrapping to nulldfa.in 2018-02-09 11:30:01 -08:00
path.c apparmor: Fix string overrun due to missing termination 2026-04-22 20:09:05 -07:00
policy_compat.c apparmor: constify aa_dfa parameters on read-only compute paths 2026-08-10 22:49:43 -07:00
policy_ns.c apparmor: fix: limit the number of levels of policy namespaces 2026-03-09 16:05:43 -07:00
policy_unpack_test.c + Features 2025-08-04 08:17:28 -07:00
policy_unpack.c apparmor: constify aa_dfa parameters on read-only compute paths 2026-08-10 22:49:43 -07:00
policy.c apparmor: fix deadlock in complain-mode change_hat 2026-08-15 23:39:38 -07:00
procattr.c apparmor: aa_getprocattr free procattr leak on format failure 2026-06-13 20:18:30 -07:00
resource.c apparmor: fix rlimit for posix cpu timers 2026-01-29 01:27:54 -08:00
secid.c lsm: secctx provider check on release 2024-12-04 14:59:57 -05:00
stacksplitdfa.in apparmor: use the dfa to do label parse string splitting 2018-02-09 11:30:01 -08:00
task.c apparmor: fix cred UAF caused by begin_current_label_crit_section() 2026-08-06 16:15:33 -07:00