linux-stable/security/apparmor
Gaosheng Cui a5745b1110 apparmor: Fix memory leak in unpack_profile()
[ Upstream commit 8ead196be2 ]

The aa_put_pdb(rules->file) should be called when rules->file is
reassigned, otherwise there may be a memory leak.

This was found via kmemleak:

unreferenced object 0xffff986c17056600 (size 192):
  comm "apparmor_parser", pid 875, jiffies 4294893488
  hex dump (first 32 bytes):
    00 00 00 00 00 00 00 00 00 89 14 04 6c 98 ff ff  ............l...
    00 00 8c 11 6c 98 ff ff bc 0c 00 00 00 00 00 00  ....l...........
  backtrace (crc e28c80c4):
    [<ffffffffba25087f>] kmemleak_alloc+0x4f/0x90
    [<ffffffffb95ecd42>] kmalloc_trace+0x2d2/0x340
    [<ffffffffb98a7b3d>] aa_alloc_pdb+0x4d/0x90
    [<ffffffffb98ab3b8>] unpack_pdb+0x48/0x660
    [<ffffffffb98ac073>] unpack_profile+0x693/0x1090
    [<ffffffffb98acf5a>] aa_unpack+0x10a/0x6e0
    [<ffffffffb98a93e3>] aa_replace_profiles+0xa3/0x1210
    [<ffffffffb989a183>] policy_update+0x163/0x2a0
    [<ffffffffb989a381>] profile_replace+0xb1/0x130
    [<ffffffffb966cb64>] vfs_write+0xd4/0x3d0
    [<ffffffffb966d05b>] ksys_write+0x6b/0xf0
    [<ffffffffb966d10e>] __x64_sys_write+0x1e/0x30
    [<ffffffffba242316>] do_syscall_64+0x76/0x120
    [<ffffffffba4000e5>] entry_SYSCALL_64_after_hwframe+0x6c/0x74

So add aa_put_pdb(rules->file) to fix it when rules->file is reassigned.

Fixes: 98b824ff89 ("apparmor: refcount the pdb")
Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-01-25 15:45:25 -08:00
..
include apparmor: Fix regression in mount mediation 2023-10-18 16:01:32 -07:00
.gitignore .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
Kconfig + Features 2022-12-14 13:42:09 -08:00
Makefile + Features 2022-12-14 13:42:09 -08:00
apparmorfs.c apparmor: Fix move_mount mediation by detecting if source is detached 2024-01-03 12:10:29 -08:00
audit.c apparmor: add io_uring mediation 2023-10-18 15:58:49 -07:00
capability.c apparmor: Fix some kernel-doc comments 2023-10-23 00:25:49 -07:00
crypto.c apparmor: Return directly after a failed kzalloc() in two functions 2023-07-06 10:58:49 -07:00
domain.c apparmor: Fix one kernel-doc comment 2023-10-23 00:26:05 -07:00
file.c apparmor: refcount the pdb 2023-10-18 15:30:47 -07:00
ipc.c apparmor: refcount the pdb 2023-10-18 15:30:47 -07:00
label.c apparmor: refcount the pdb 2023-10-18 15:30:47 -07:00
lib.c apparmor: fix possible memory leak in unpack_trans_table 2024-01-25 15:45:24 -08:00
lsm.c apparmor: Fix ref count leak in task_kill 2024-01-25 15:45:23 -08:00
match.c apparmor: refcount the pdb 2023-10-18 15:30:47 -07:00
mount.c apparmor: Fix move_mount mediation by detecting if source is detached 2024-01-03 12:10:29 -08:00
net.c apparmor: refcount the pdb 2023-10-18 15:30:47 -07:00
nulldfa.in apparmor: cleanup add proper line wrapping to nulldfa.in 2018-02-09 11:30:01 -08:00
path.c security: apparmor: delete repeated words in comments 2021-02-07 04:15:46 -08:00
policy.c apparmor: free the allocated pdb objects 2024-01-25 15:45:24 -08:00
policy_compat.c apparmor: fixup return comments for kernel doc cleanups by Gaosheng Cui 2023-08-08 13:12:19 -07:00
policy_ns.c apparmor: remove unused functions in policy_ns.c/.h 2023-10-15 21:44:31 -07:00
policy_unpack.c apparmor: Fix memory leak in unpack_profile() 2024-01-25 15:45:25 -08:00
policy_unpack_test.c apparmor: fix use of strcpy in policy_unpack_test 2023-07-06 10:58:49 -07:00
procattr.c apparmor: fix obsoleted comments for aa_getprocattr() and audit_resource() 2022-10-24 22:35:23 -07:00
resource.c apparmor: pass cred through to audit info. 2023-10-18 15:30:38 -07:00
secid.c apparmor: fix kernel-doc complaints 2023-01-10 10:04:35 -08:00
stacksplitdfa.in apparmor: use the dfa to do label parse string splitting 2018-02-09 11:30:01 -08:00
task.c apparmor: add user namespace creation mediation 2023-10-18 15:49:02 -07:00