Skip to contentSkip to conversation

Kill the correct protocol expression during payload parsing

PATCH In review Yanchuan Nian 2 participants 3 messages Aug 30, 2014 – Sep 1, 2014 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Kill the correct protocol expression during payload parsing

The protocol expression that should be killed when payload parsing isn't the first one but the last one. Look at the result of this command:

nft> add rule ip filter input ip protocol != tcp tcp sport 80 drop nft> list table ip filter

table ip filter {
	chain input {
		 type filter hook input priority 0;
		 ip protocol tcp tcp sport http drop
	}
}

nft>

With this patch, the result is:
nft> add rule ip filter input ip protocol != tcp tcp sport 80 drop nft> list table ip filter

table ip filter {
	chain input {
		 type filter hook input priority 0;
		 ip protocol != tcp tcp sport http drop
	}
}

nft>

---
 src/netlink_delinearize.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
src/netlink_delinearize.c +2 -3
index 195d432..322c7cc 100644
@@ -671,12 +671,11 @@ static void payload_match_postprocess(struct rule_pp_ctx *ctx,
 			nstmt = expr_stmt_alloc(&stmt->location, nexpr);
 			list_add_tail(&nstmt->list, &stmt->list);
 
-			/* Remember the first payload protocol expression to
+			/* Remember the last payload protocol expression to
 			 * kill it later on if made redundant by a higher layer
 			 * payload expression.
 			 */
-			if (ctx->pbase == PROTO_BASE_INVALID &&
-			    left->flags & EXPR_F_PROTOCOL)
+			if (left->flags & EXPR_F_PROTOCOL)
 				payload_dependency_store(ctx, nstmt,
 							 left->payload.base);
 			else
Signature · 1 line
1.9.3
#1 lore raw
Quoted 2 lines · Yanchuan Nian

The protocol expression that should be killed when payload parsing isn't the first one but the last one. Look at the result of this command:

That patch is competely wrong. Have you actually tested any other case? You're simply not killing any payload dependency anymore.

The correct fix is to check for OP_NEQ and deciding not to kill it based on that.

Quoted 49 lines

nft> add rule ip filter input ip protocol != tcp tcp sport 80 drop nft> list table ip filter

table ip filter {
	chain input {
		 type filter hook input priority 0;
		 ip protocol tcp tcp sport http drop
	}
}

nft>

With this patch, the result is:
nft> add rule ip filter input ip protocol != tcp tcp sport 80 drop nft> list table ip filter

table ip filter {
	chain input {
		 type filter hook input priority 0;
		 ip protocol != tcp tcp sport http drop
	}
}

nft>

---
 src/netlink_delinearize.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
src/netlink_delinearize.c +2 -3
index 195d432..322c7cc 100644
@@ -671,12 +671,11 @@ static void payload_match_postprocess(struct rule_pp_ctx *ctx,
 			nstmt = expr_stmt_alloc(&stmt->location, nexpr);
 			list_add_tail(&nstmt->list, &stmt->list);
 
-			/* Remember the first payload protocol expression to
+			/* Remember the last payload protocol expression to
 			 * kill it later on if made redundant by a higher layer
 			 * payload expression.
 			 */
-			if (ctx->pbase == PROTO_BASE_INVALID &&
-			    left->flags & EXPR_F_PROTOCOL)
+			if (left->flags & EXPR_F_PROTOCOL)
 				payload_dependency_store(ctx, nstmt,
 							 left->payload.base);
 			else
Signature · 1 line
1.9.3
#2 lore raw
Quoted 10 lines · Patrick McHardy
Quoted 2 lines · Yanchuan Nian

The protocol expression that should be killed when payload parsing isn't the first one but the last one. Look at the result of this command:

That patch is competely wrong. Have you actually tested any other case? You're simply not killing any payload dependency anymore.

The correct fix is to check for OP_NEQ and deciding not to kill it based on that.

Hi Patrick, Thanks to your replay. Yes, this patch is wrong. It was careless of me forgetting to test it. I am sorry and I will try to fix it. Thank you again.

Quoted 50 lines
Quoted 49 lines

nft> add rule ip filter input ip protocol != tcp tcp sport 80 drop nft> list table ip filter

table ip filter {
	chain input {
		 type filter hook input priority 0;
		 ip protocol tcp tcp sport http drop
	}
}

nft>

With this patch, the result is:
nft> add rule ip filter input ip protocol != tcp tcp sport 80 drop nft> list table ip filter

table ip filter {
	chain input {
		 type filter hook input priority 0;
		 ip protocol != tcp tcp sport http drop
	}
}

nft>

---
 src/netlink_delinearize.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
src/netlink_delinearize.c +2 -3
index 195d432..322c7cc 100644
@@ -671,12 +671,11 @@ static void payload_match_postprocess(struct rule_pp_ctx *ctx,
 			nstmt = expr_stmt_alloc(&stmt->location, nexpr);
 			list_add_tail(&nstmt->list, &stmt->list);
 
-			/* Remember the first payload protocol expression to
+			/* Remember the last payload protocol expression to
 			 * kill it later on if made redundant by a higher layer
 			 * payload expression.
 			 */
-			if (ctx->pbase == PROTO_BASE_INVALID &&
-			    left->flags & EXPR_F_PROTOCOL)
+			if (left->flags & EXPR_F_PROTOCOL)
 				payload_dependency_store(ctx, nstmt,
 							 left->payload.base);
 			else
Signature · 1 line
1.9.3