Skip to content

Commit aa94853

Browse files
a3a3elUlrich Hecht
authored andcommitted
lib/ts_bm: reset initial match offset for every block of text
[ Upstream commit 6f67fbf ] The `shift` variable which indicates the offset in the string at which to start matching the pattern is initialized to `bm->patlen - 1`, but it is not reset when a new block is retrieved. This means the implemen- tation may start looking at later and later positions in each successive block and miss occurrences of the pattern at the beginning. E.g., consider a HTTP packet held in a non-linear skb, where the HTTP request line occurs in the second block: [... 52 bytes of packet headers ...] GET /bmtest HTTP/1.1\r\nHost: www.example.com\r\n\r\n and the pattern is "GET /bmtest". Once the first block comprising the packet headers has been examined, `shift` will be pointing to somewhere near the end of the block, and so when the second block is examined the request line at the beginning will be missed. Reinitialize the variable for each new block. Fixes: 8082e4e ("[LIB]: Boyer-Moore extension for textsearch infrastructure strike #2") Link: https://bugzilla.netfilter.org/show_bug.cgi?id=1390 Signed-off-by: Jeremy Sowden <jeremy@azazel.net> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Ulrich Hecht <uli@kernel.org>
1 parent 80ab090 commit aa94853

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/ts_bm.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,12 @@ static unsigned int bm_find(struct ts_config *conf, struct ts_state *state)
6464
struct ts_bm *bm = ts_config_priv(conf);
6565
unsigned int i, text_len, consumed = state->offset;
6666
const u8 *text;
67-
int shift = bm->patlen - 1, bs;
67+
int bs;
6868
const u8 icase = conf->flags & TS_IGNORECASE;
6969

7070
for (;;) {
71+
int shift = bm->patlen - 1;
72+
7173
text_len = conf->get_next_block(consumed, &text, conf, state);
7274

7375
if (unlikely(text_len == 0))

0 commit comments

Comments
 (0)