linux/security/apparmor/include
Ryan Lee 277bb68f65 apparmor: fix loop detection used in conflicting attachment resolution
[ Upstream commit a88db916b8 ]

Conflicting attachment resolution is based on the number of states
traversed to reach an accepting state in the attachment DFA, accounting
for DFA loops traversed during the matching process. However, the loop
counting logic had multiple bugs:

 - The inc_wb_pos macro increments both position and length, but length
   is supposed to saturate upon hitting buffer capacity, instead of
   wrapping around.
 - If no revisited state is found when traversing the history, is_loop
   would still return true, as if there was a loop found the length of
   the history buffer, instead of returning false and signalling that
   no loop was found. As a result, the adjustment step of
   aa_dfa_leftmatch would sometimes produce negative counts with loop-
   free DFAs that traversed enough states.
 - The iteration in the is_loop for loop is supposed to stop before
   i = wb->len, so the conditional should be < instead of <=.

This patch fixes the above bugs as well as the following nits:
 - The count and size fields in struct match_workbuf were not used,
   so they can be removed.
 - The history buffer in match_workbuf semantically stores aa_state_t
   and not unsigned ints, even if aa_state_t is currently unsigned int.
 - The local variables in is_loop are counters, and thus should be
   unsigned ints instead of aa_state_t's.

Fixes: 21f6066105 ("apparmor: improve overlapping domain attachment resolution")

Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
Co-developed-by: John Johansen <john.johansen@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
History 2025-08-15 12:13:59 +02:00
..
apparmor.h apparmor: add io_uring mediation 2023-10-18 15:58:49 -07:00
apparmorfs.h apparmor: make export of raw binary profile to userspace optional 2022-07-09 15:13:59 -07:00
audit.h ima: Avoid blocking in RCU read-side critical section 2024-06-13 14:26:50 -04:00
capability.h apparmor: pass cred through to audit info. 2023-10-18 15:30:38 -07:00
cred.h apparmor: try to avoid refing the label in apparmor_file_open 2024-07-24 11:05:14 -07:00
crypto.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 441 2019-06-05 17:37:17 +02:00
domain.h apparmor: extend permissions to support a label and tag string 2022-10-03 14:49:03 -07:00
file.h apparmor: pass cred through to audit info. 2023-10-18 15:30:38 -07:00
ipc.h apparmor: pass cred through to audit info. 2023-10-18 15:30:38 -07:00
label.h apparmor: refactor profile rules and attachments 2022-10-03 14:49:04 -07:00
lib.h apparmor: refcount the pdb 2023-10-18 15:30:47 -07:00
match.h apparmor: fix loop detection used in conflicting attachment resolution 2025-08-15 12:13:59 +02:00
mount.h apparmor: Fix regression in mount mediation 2023-10-18 16:01:32 -07:00
net.h lsm: infrastructure management of the sock security 2024-07-29 16:54:50 -04:00
path.h apparmor: allow label to carry debug flags 2022-07-19 02:55:45 -07:00
perms.h apparmor: add io_uring mediation 2023-10-18 15:58:49 -07:00
policy.h apparmor: allow restricting unprivileged change_profile 2023-10-18 15:48:44 -07:00
policy_compat.h apparmor: isolate policy backwards compatibility to its own file 2022-10-03 14:49:03 -07:00
policy_ns.h apparmor: remove unused functions in policy_ns.c/.h 2023-10-15 21:44:31 -07:00
policy_unpack.h + Features 2022-12-14 13:42:09 -08:00
procattr.h AppArmor: Add selfattr hooks 2023-11-12 22:54:42 -05:00
resource.h apparmor: pass cred through to audit info. 2023-10-18 15:30:38 -07:00
secid.h apparmor: disable showing the mode as part of a secid to secctx 2022-07-13 17:18:29 -07:00
sig_names.h apparmor: audit unknown signal numbers 2018-02-09 11:30:01 -08:00
task.h apparmor: add user namespace creation mediation 2023-10-18 15:49:02 -07:00