]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
apparmor: ensure WB_HISTORY_SIZE value is a power of 2
authorRyan Lee <ryan.lee@canonical.com>
Thu, 1 May 2025 19:54:38 +0000 (12:54 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 15 Aug 2025 10:13:59 +0000 (12:13 +0200)
[ Upstream commit 6c055e62560b958354625604293652753d82bcae ]

WB_HISTORY_SIZE was defined to be a value not a power of 2, despite a
comment in the declaration of struct match_workbuf stating it is and a
modular arithmetic usage in the inc_wb_pos macro assuming that it is. Bump
WB_HISTORY_SIZE's value up to 32 and add a BUILD_BUG_ON_NOT_POWER_OF_2
line to ensure that any future changes to the value of WB_HISTORY_SIZE
respect this requirement.

Fixes: 136db994852a ("apparmor: increase left match history buffer size")
Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
security/apparmor/include/match.h
security/apparmor/match.c

index 4bb0405c91908a6adec2e48ca36a35a3d5bd9a98..0539abda328dff78bd3f71839f549cceb2ba4d13 100644 (file)
@@ -135,7 +135,8 @@ aa_state_t aa_dfa_matchn_until(struct aa_dfa *dfa, aa_state_t start,
 
 void aa_dfa_free_kref(struct kref *kref);
 
-#define WB_HISTORY_SIZE 24
+/* This needs to be a power of 2 */
+#define WB_HISTORY_SIZE 32
 struct match_workbuf {
        unsigned int count;
        unsigned int pos;
index 517d77d3c34cc908ad1f85843cc28c8f509c8837..0f791a58d9333e7e08b7df8b5d08e69321da8a95 100644 (file)
@@ -626,6 +626,7 @@ aa_state_t aa_dfa_matchn_until(struct aa_dfa *dfa, aa_state_t start,
 
 #define inc_wb_pos(wb)                                         \
 do {                                                           \
+       BUILD_BUG_ON_NOT_POWER_OF_2(WB_HISTORY_SIZE);                   \
        wb->pos = (wb->pos + 1) & (WB_HISTORY_SIZE - 1);                \
        wb->len = (wb->len + 1) & (WB_HISTORY_SIZE - 1);                \
 } while (0)