]> 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 14:39:15 +0000 (16:39 +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 536ce3abd5986a598ef1f6f4de5e04e0fd5662f1..b45fc39fa837524bc1f3f3e54d355b4bcba6da4a 100644 (file)
@@ -137,7 +137,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 f2d9c57f879439a7fd2bee16a8cf3d5506e8bcf0..1ceabde550f2c7520daca499c6dac5ba9e793df7 100644 (file)
@@ -681,6 +681,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)