Skip to contentSkip to conversation

netfilter: bitwise: fix reduce comparison

PATCH Superseded Jeremy Sowden 2 participants 3 messages Mar 27, 2022 – Mar 29, 2022

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

PATCH 1/1 netfilter: bitwise: fix reduce comparison

The nft_bitwise_reduce function should compare the bitwise operation in expr with the tracked operation associated with the destination register of expr. However, instead being called on expr and track->regs[priv->dreg].selector, nft_expr_priv is called on expr twice, so nft_bitwise_reduce returns true even when the operations differ.

Fixes be5650f8f47e ("netfilter: nft_bitwise: track register operations")
---
 net/netfilter/nft_bitwise.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nft_bitwise.c +1 -1
index 7b727d3ebf9d..120a657bf8ea 100644
@@ -287,7 +287,7 @@ static bool nft_bitwise_reduce(struct nft_regs_track *track,
 	if (!track->regs[priv->sreg].selector)
 		return false;
 
-	bitwise = nft_expr_priv(expr);
+	bitwise = nft_expr_priv(track->regs[priv->dreg].selector);
 	if (track->regs[priv->sreg].selector == track->regs[priv->dreg].selector &&
 	    track->regs[priv->dreg].bitwise &&
 	    track->regs[priv->dreg].bitwise->ops == expr->ops &&
Signature · 1 line
2.35.1
#1 lore raw

PATCH v2 1/1 netfilter: bitwise: fix reduce comparisons

The nft_bitwise_reduce and nft_bitwise_fast_reduce functions should compare the bitwise operation in expr with the tracked operation associated with the destination register of expr. However, instead of being called on expr and track->regs[priv->dreg].selector, nft_expr_priv is called on expr twice, so both reduce functions return true even when the operations differ.

Fixes be5650f8f47e ("netfilter: nft_bitwise: track register operations")

---
Since v1:

* fix nft_bitwise_fast_reduce as well as nft_bitwise_reduce.

 net/netfilter/nft_bitwise.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nft_bitwise.c +2 -2
index 7b727d3ebf9d..04bd2f89afe8 100644
@@ -287,7 +287,7 @@ static bool nft_bitwise_reduce(struct nft_regs_track *track,
 	if (!track->regs[priv->sreg].selector)
 		return false;
 
-	bitwise = nft_expr_priv(expr);
+	bitwise = nft_expr_priv(track->regs[priv->dreg].selector);
 	if (track->regs[priv->sreg].selector == track->regs[priv->dreg].selector &&
 	    track->regs[priv->dreg].bitwise &&
 	    track->regs[priv->dreg].bitwise->ops == expr->ops &&
@@ -434,7 +434,7 @@ static bool nft_bitwise_fast_reduce(struct nft_regs_track *track,
 	if (!track->regs[priv->sreg].selector)
 		return false;
 
-	bitwise = nft_expr_priv(expr);
+	bitwise = nft_expr_priv(track->regs[priv->dreg].selector);
 	if (track->regs[priv->sreg].selector == track->regs[priv->dreg].selector &&
 	    track->regs[priv->dreg].bitwise &&
 	    track->regs[priv->dreg].bitwise->ops == expr->ops &&
Signature · 1 line
2.35.1
#2 lore raw

Re: [nf PATCH v2] netfilter: bitwise: fix reduce comparisons

Quoted 6 lines · Jeremy Sowden

The nft_bitwise_reduce and nft_bitwise_fast_reduce functions should compare the bitwise operation in expr with the tracked operation associated with the destination register of expr. However, instead of being called on expr and track->regs[priv->dreg].selector, nft_expr_priv is called on expr twice, so both reduce functions return true even when the operations differ.

Good catch, applied thanks