Skip to contentSkip to conversation

netfilter: nf_tables: check if payload length is a power of 2

PATCH Applied Nikolay Aleksandrov 3 participants 3 messages Feb 16, 2014 – Feb 17, 2014

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

PATCH v3 1/1 netfilter: nf_tables: check if payload length is a power of 2

Add a check if payload's length is a power of 2 when selecting ops. The fast ops were meant for well aligned loads, also this fixes a small bug when using a length of 3 with some offsets which causes only 1 byte to be loaded because the fast ops are chosen.

---
v3: Check the length, not the offset.
v2: use is_power_of_2, and adjust order of checks as per Patrick's comment

Sorry for the noise, I shouldn't hurry so much. This patch applies to Dave's -net tree.

 net/netfilter/nft_payload.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/netfilter/nft_payload.c +2 -1
index a2aeb31..85daa84 100644
@@ -135,7 +135,8 @@ nft_payload_select_ops(const struct nft_ctx *ctx,
 	if (len == 0 || len > FIELD_SIZEOF(struct nft_data, data))
 		return ERR_PTR(-EINVAL);
 
-	if (len <= 4 && IS_ALIGNED(offset, len) && base != NFT_PAYLOAD_LL_HEADER)
+	if (len <= 4 && is_power_of_2(len) && IS_ALIGNED(offset, len) &&
+	    base != NFT_PAYLOAD_LL_HEADER)
 		return &nft_payload_fast_ops;
 	else
 		return &nft_payload_ops;
Signature · 1 line
1.8.4.2
Acked-by on v3 1/1
#1 lore raw
Quoted 5 lines · Nikolay Aleksandrov

Add a check if payload's length is a power of 2 when selecting ops. The fast ops were meant for well aligned loads, also this fixes a small bug when using a length of 3 with some offsets which causes only 1 byte to be loaded because the fast ops are chosen.

Quoted 7 lines

---
v3: Check the length, not the offset.
v2: use is_power_of_2, and adjust order of checks as per Patrick's comment

Sorry for the noise, I shouldn't hurry so much. This patch applies to Dave's -net tree.

Thanks!

Quoted 20 lines
 net/netfilter/nft_payload.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/netfilter/nft_payload.c +2 -1
index a2aeb31..85daa84 100644
@@ -135,7 +135,8 @@ nft_payload_select_ops(const struct nft_ctx *ctx,
 	if (len == 0 || len > FIELD_SIZEOF(struct nft_data, data))
 		return ERR_PTR(-EINVAL);
 
-	if (len <= 4 && IS_ALIGNED(offset, len) && base != NFT_PAYLOAD_LL_HEADER)
+	if (len <= 4 && is_power_of_2(len) && IS_ALIGNED(offset, len) &&
+	    base != NFT_PAYLOAD_LL_HEADER)
 		return &nft_payload_fast_ops;
 	else
 		return &nft_payload_ops;
Signature · 1 line
1.8.4.2
maintainer Applied
#2 lore raw
Quoted 11 lines · Patrick McHardy
Quoted 10 lines · Nikolay Aleksandrov

Add a check if payload's length is a power of 2 when selecting ops. The fast ops were meant for well aligned loads, also this fixes a small bug when using a length of 3 with some offsets which causes only 1 byte to be loaded because the fast ops are chosen.

---
v3: Check the length, not the offset.
v2: use is_power_of_2, and adjust order of checks as per Patrick's comment

Quoted 6 lines
Quoted 2 lines

Sorry for the noise, I shouldn't hurry so much. This patch applies to Dave's -net tree.

Thanks!

Applied, thanks.