Skip to contentSkip to conversation

patch 00/02: netfilter / textsearch fixes

DISCUSSION Patrick McHardy 2 participants 5 messages Jun 30, 2008

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi Dave,

these two patches fix an off-by-one if the TCP window tracking ACK sequence validation, leading to incorrectly marked INVALID packets, and another off-by-one in the Boyer-Moore text search algorithm. Both are also candidates for -stable which I'll pass on once they hit upstream.

Please apply, thanks.

 lib/ts_bm.c                            |    2 +-
 net/netfilter/nf_conntrack_proto_tcp.c |   13 +++++++------
 2 files changed, 8 insertions(+), 7 deletions(-)

Joonwoo Park (1):
textsearch: fix Boyer-Moore text search bug

Jozsef Kadlecsik (1):
netfilter: nf_conntrack_tcp: fixing to check the lower bound of valid ACK

#1 lore raw

netfilter: nf_conntrack_tcp: fixing to check the lower bound of valid ACK

netfilter: nf_conntrack_tcp: fixing to check the lower bound of valid ACK

Lost connections was reported by Thomas Bätzler (running 2.6.25 kernel) on the netfilter mailing list (see the thread "Weird nat/conntrack Problem with PASV FTP upload"). He provided tcpdump recordings which helped to find a long lingering bug in conntrack.

In TCP connection tracking, checking the lower bound of valid ACK could lead to mark valid packets as INVALID because:

- We have got a "higher or equal" inequality, but the test checked the "higher" condition only; fixed.
- If the packet contains a SACK option, it could occur that the ACK value was before the left edge of our (S)ACK "window": if a previous packet from the other party intersected the right edge of the window of the receiver, we could move forward the window parameters beyond accepting a valid ack. Therefore in this patch we check the rightmost SACK edge instead of the ACK value in the lower bound of valid (S)ACK test.

---
commit 5c61a61f0df27eba716646da0b7371bf49f13d89
tree d325c80abe018baac9cd492a76d38b998ae87d4c
parent d420895efb259a78dda50f95289571faa6e10e41
author Jozsef Kadlecsik <[email protected]> Mon, 30 Jun 2008 17:40:34 +0200 committer Patrick McHardy <[email protected]> Mon, 30 Jun 2008 17:40:34 +0200

 net/netfilter/nf_conntrack_proto_tcp.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
net/netfilter/nf_conntrack_proto_tcp.c +7 -6
index ba94004..271cd01 100644
@@ -331,12 +331,13 @@ static unsigned int get_conntrack_index(const struct tcphdr *tcph)
 
    I.   Upper bound for valid data:	seq <= sender.td_maxend
    II.  Lower bound for valid data:	seq + len >= sender.td_end - receiver.td_maxwin
-   III.	Upper bound for valid ack:      sack <= receiver.td_end
-   IV.	Lower bound for valid ack:	ack >= receiver.td_end - MAXACKWINDOW
+   III.	Upper bound for valid (s)ack:   sack <= receiver.td_end
+   IV.	Lower bound for valid (s)ack:	sack >= receiver.td_end - MAXACKWINDOW
 
-   where sack is the highest right edge of sack block found in the packet.
+   where sack is the highest right edge of sack block found in the packet
+   or ack in the case of packet without SACK option.
 
-   The upper bound limit for a valid ack is not ignored -
+   The upper bound limit for a valid (s)ack is not ignored -
    we doesn't have to deal with fragments.
 */
 
@@ -606,12 +607,12 @@ static bool tcp_in_window(const struct nf_conn *ct,
 		 before(seq, sender->td_maxend + 1),
 		 after(end, sender->td_end - receiver->td_maxwin - 1),
 		 before(sack, receiver->td_end + 1),
-		 after(ack, receiver->td_end - MAXACKWINDOW(sender)));
+		 after(sack, receiver->td_end - MAXACKWINDOW(sender) - 1));
 
 	if (before(seq, sender->td_maxend + 1) &&
 	    after(end, sender->td_end - receiver->td_maxwin - 1) &&
 	    before(sack, receiver->td_end + 1) &&
-	    after(ack, receiver->td_end - MAXACKWINDOW(sender))) {
+	    after(sack, receiver->td_end - MAXACKWINDOW(sender) - 1)) {
 		/*
 		 * Take into account window scaling (RFC 1323).
 		 */

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw

textsearch: fix Boyer-Moore text search bug

In reply to Patrick McHardy

textsearch: fix Boyer-Moore text search bug

The current logic has a bug which cannot find matching pattern, if the pattern is matched from the first character of target string. for example:
pattern=abc, string=abcdefg
pattern=a, string=abcdefg
Searching algorithm should return 0 for those things.

---
commit cf07ecdeb187d567890ade083f0c1fa298085dee
tree 6a7cf5c6bdc80c75ec843d8ee44cd98039ca6fd7
parent 5c61a61f0df27eba716646da0b7371bf49f13d89
author Joonwoo Park <[email protected]> Mon, 30 Jun 2008 17:40:34 +0200 committer Patrick McHardy <[email protected]> Mon, 30 Jun 2008 17:40:34 +0200

 lib/ts_bm.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
lib/ts_bm.c +1 -1
index d90822c..4a7fce7 100644
@@ -63,7 +63,7 @@ static unsigned int bm_find(struct ts_config *conf, struct ts_state *state)
 	struct ts_bm *bm = ts_config_priv(conf);
 	unsigned int i, text_len, consumed = state->offset;
 	const u8 *text;
-	int shift = bm->patlen, bs;
+	int shift = bm->patlen - 1, bs;
 
 	for (;;) {
 		text_len = conf->get_next_block(consumed, &text, conf, state);
maintainer
#2 lore raw

Re: netfilter: nf_conntrack_tcp: fixing to check the lower bound of valid ACK

In reply to Patrick McHardy

From: Patrick McHardy <[email protected]>
Date: Mon, 30 Jun 2008 17:56:10 +0200 (MEST)

Quoted 20 lines

netfilter: nf_conntrack_tcp: fixing to check the lower bound of valid ACK

Lost connections was reported by Thomas Bätzler (running 2.6.25 kernel) on the netfilter mailing list (see the thread "Weird nat/conntrack Problem with PASV FTP upload"). He provided tcpdump recordings which helped to find a long lingering bug in conntrack.

In TCP connection tracking, checking the lower bound of valid ACK could lead to mark valid packets as INVALID because:

- We have got a "higher or equal" inequality, but the test checked the "higher" condition only; fixed.
- If the packet contains a SACK option, it could occur that the ACK value was before the left edge of our (S)ACK "window": if a previous packet from the other party intersected the right edge of the window of the receiver, we could move forward the window parameters beyond accepting a valid ack. Therefore in this patch we check the rightmost SACK edge instead of the ACK value in the lower bound of valid (S)ACK test.

Quoted 2 lines

Applied.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#4 lore raw

Re: textsearch: fix Boyer-Moore text search bug

In reply to Patrick McHardy

From: Patrick McHardy <[email protected]>
Date: Mon, 30 Jun 2008 17:56:11 +0200 (MEST)

Quoted 11 lines

textsearch: fix Boyer-Moore text search bug

The current logic has a bug which cannot find matching pattern, if the pattern is matched from the first character of target string. for example:
pattern=abc, string=abcdefg
pattern=a, string=abcdefg
Searching algorithm should return 0 for those things.

Also applied, thanks everyone.