Skip to content

Commit d79ddfb

Browse files
rlee287gregkh
authored andcommitted
apparmor: ensure WB_HISTORY_SIZE value is a power of 2
[ Upstream commit 6c055e6 ] 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: 136db99 ("apparmor: increase left match history buffer size") Signed-off-by: Ryan Lee <[email protected]> Signed-off-by: John Johansen <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent cb6657b commit d79ddfb

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

security/apparmor/include/match.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ aa_state_t aa_dfa_matchn_until(struct aa_dfa *dfa, aa_state_t start,
137137

138138
void aa_dfa_free_kref(struct kref *kref);
139139

140-
#define WB_HISTORY_SIZE 24
140+
/* This needs to be a power of 2 */
141+
#define WB_HISTORY_SIZE 32
141142
struct match_workbuf {
142143
unsigned int count;
143144
unsigned int pos;

security/apparmor/match.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,7 @@ aa_state_t aa_dfa_matchn_until(struct aa_dfa *dfa, aa_state_t start,
681681

682682
#define inc_wb_pos(wb) \
683683
do { \
684+
BUILD_BUG_ON_NOT_POWER_OF_2(WB_HISTORY_SIZE); \
684685
wb->pos = (wb->pos + 1) & (WB_HISTORY_SIZE - 1); \
685686
wb->len = (wb->len + 1) & (WB_HISTORY_SIZE - 1); \
686687
} while (0)

0 commit comments

Comments
 (0)