netfilter: nf_tables: check if payload offset is a power of 2
Subsystems (2)
PATCH 1/1 netfilter: nf_tables: check if payload offset is a power of 2
Add a check if payload's offset is a power of 2 when selecting ops. The fast ops were meant for well aligned offsets, also this fixes a small bug when using unaligned offset and length of 3 which causes only 1 byte to be loaded because the fast ops are chosen.
---
I broke the line since it was >80 chars.
This patch applies to Dave's -net tree.
net/netfilter/nft_payload.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/netfilter/nft_payload.c +3 -1
@@ -135,7 +135,9 @@ 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_ALIGNED (offset, len) && + base !=NFT_PAYLOAD_LL_HEADER && + !(offset & (offset -1 )))return &nft_payload_fast_ops;else return &nft_payload_ops;
Signature · 1 line
1.8.4.2
Quoted 18 lines · Nikolay Aleksandrov
Add a check if payload's offset is a power of 2 when selecting ops. The fast ops were meant for well aligned offsets, also this fixes a small bug when using unaligned offset and length of 3 which causes only 1 byte to be loaded because the fast ops are chosen.
Signed-off-by Nikolay Aleksandrov <[email protected]>---
I broke the line since it was >80 chars.
This patch applies to Dave's -net tree.net/netfilter/nft_payload.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)net/netfilter/nft_payload.c +0
-0
net/netfilter/nft_payload.c nft_payload_select_ops(const struct nft_ctx *ctx, · line 140
Quoted 7 lines
net/netfilter/nft_payload.c +3
-1@@ -135,7 +135,9 @@ 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_ALIGNED (offset, len) && + base !=NFT_PAYLOAD_LL_HEADER && + !(offset & (offset -1 )))
Small cosmetic note: we have is_power_of_2(), which does exactly this.
Also I think the more logical order would be:
len <= 4 && is_power_of_2 && IS_ALIGNED && base ...
Quoted 5 lines
net/netfilter/nft_payload.c +0
-0return &nft_payload_fast_ops; else return &nft_payload_ops;Signature · 1 line
1.8.4.2
Quoted 22 lines · Patrick McHardy
Quoted 21 lines · Nikolay Aleksandrov
Add a check if payload's offset is a power of 2 when selecting ops. The fast ops were meant for well aligned offsets, also this fixes a small bug when using unaligned offset and length of 3 which causes only 1 byte to be loaded because the fast ops are chosen.
Signed-off-by Nikolay Aleksandrov <[email protected]>---
I broke the line since it was >80 chars.
This patch applies to Dave's -net tree.net/netfilter/nft_payload.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)net/netfilter/nft_payload.c +0
-0@@ -135,7 +135,9 @@ nft_payload_select_ops(const struct nft_ctx *ctx, if (len == 0 || len > FIELD_SIZEOF(struct nft_data, data))return ERR_PTR (-EINVAL );
Quoted 7 lines
net/netfilter/nft_payload.c nft_payload_select_ops(const struct nft_ctx *ctx, · line 140
Quoted 4 lines
net/netfilter/nft_payload.c +3
-1-if (len <=4 &&IS_ALIGNED (offset, len) && base !=NFT_PAYLOAD_LL_HEADER ) +if (len <=4 &&IS_ALIGNED (offset, len) && + base !=NFT_PAYLOAD_LL_HEADER && + !(offset & (offset -1 )))Small cosmetic note: we have
is_power_of_2(), which does exactly this.
I didn't choose is_power_of_2 because it also checks if x is != 0, so I thought we can allow for 0 offset with the fast ops.
Quoted 4 lines
Also I think the more logical order would be:
len <= 4 &&
is_power_of_2&&IS_ALIGNED&& base ...
Okay :-)
Quoted 5 lines
Quoted 5 lines
net/netfilter/nft_payload.c +0
-0return &nft_payload_fast_ops; else return &nft_payload_ops;Signature · 1 line
1.8.4.2
Quoted 30 lines · Nikolay Aleksandrov
Quoted 22 lines · Patrick McHardy
Quoted 21 lines · Nikolay Aleksandrov
Add a check if payload's offset is a power of 2 when selecting ops. The fast ops were meant for well aligned offsets, also this fixes a small bug when using unaligned offset and length of 3 which causes only 1 byte to be loaded because the fast ops are chosen.
Signed-off-by Nikolay Aleksandrov <[email protected]>---
I broke the line since it was >80 chars.
This patch applies to Dave's -net tree.net/netfilter/nft_payload.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)net/netfilter/nft_payload.c +0
-0@@ -135,7 +135,9 @@ nft_payload_select_ops(const struct nft_ctx *ctx, if (len == 0 || len > FIELD_SIZEOF(struct nft_data, data))return ERR_PTR (-EINVAL );Quoted 7 lines
net/netfilter/nft_payload.c nft_payload_select_ops(const struct nft_ctx *ctx, · line 140
Quoted 4 lines
net/netfilter/nft_payload.c +3
-1-if (len <=4 &&IS_ALIGNED (offset, len) && base !=NFT_PAYLOAD_LL_HEADER ) +if (len <=4 &&IS_ALIGNED (offset, len) && + base !=NFT_PAYLOAD_LL_HEADER && + !(offset & (offset -1 )))Small cosmetic note: we have
is_power_of_2(), which does exactly this.
Quoted 3 lines
I didn't choose
is_power_of_2because it also checks if x is != 0, so I thought we can allow for 0 offset with the fast ops.
ugh, forget this, I'll fix it.
Quoted 17 lines
Quoted 4 lines
Also I think the more logical order would be:
len <= 4 &&
is_power_of_2&&IS_ALIGNED&& base ...Okay :-)
Quoted 5 lines
Quoted 5 lines
net/netfilter/nft_payload.c +0
-0return &nft_payload_fast_ops; else return &nft_payload_ops;Signature · 1 line
1.8.4.2--
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
Quoted 30 lines · Nikolay Aleksandrov
Quoted 22 lines · Patrick McHardy
Quoted 21 lines · Nikolay Aleksandrov
Add a check if payload's offset is a power of 2 when selecting ops. The fast ops were meant for well aligned offsets, also this fixes a small bug when using unaligned offset and length of 3 which causes only 1 byte to be loaded because the fast ops are chosen.
Signed-off-by Nikolay Aleksandrov <[email protected]>---
I broke the line since it was >80 chars.
This patch applies to Dave's -net tree.net/netfilter/nft_payload.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)net/netfilter/nft_payload.c +0
-0@@ -135,7 +135,9 @@ nft_payload_select_ops(const struct nft_ctx *ctx, if (len == 0 || len > FIELD_SIZEOF(struct nft_data, data))return ERR_PTR (-EINVAL );Quoted 7 lines
net/netfilter/nft_payload.c nft_payload_select_ops(const struct nft_ctx *ctx, · line 140
Quoted 4 lines
net/netfilter/nft_payload.c +3
-1-if (len <=4 &&IS_ALIGNED (offset, len) && base !=NFT_PAYLOAD_LL_HEADER ) +if (len <=4 &&IS_ALIGNED (offset, len) && + base !=NFT_PAYLOAD_LL_HEADER && + !(offset & (offset -1 )))Small cosmetic note: we have
is_power_of_2(), which does exactly this.
Quoted 2 lines
I didn't choose
is_power_of_2because it also checks if x is != 0, so I thought we can allow for 0 offset with the fast ops.
Sorry for not noticing before, but I'd propose to check length for power of two. We're trying to determine whether the load is well aligned.
Quoted 12 lines
Quoted 5 lines
Also I think the more logical order would be:
len <= 4 &&
is_power_of_2&&IS_ALIGNED&& base ...Okay :-)
Quoted 5 lines
Quoted 5 lines
net/netfilter/nft_payload.c +0
-0return &nft_payload_fast_ops; else return &nft_payload_ops;Signature · 1 line
1.8.4.2
Quoted 31 lines · Patrick McHardy
Quoted 30 lines · Nikolay Aleksandrov
Quoted 29 lines · Patrick McHardy
Quoted 18 lines · Nikolay Aleksandrov
Add a check if payload's offset is a power of 2 when selecting ops. The fast ops were meant for well aligned offsets, also this fixes a small bug when using unaligned offset and length of 3 which causes only 1 byte to be loaded because the fast ops are chosen.
Signed-off-by Nikolay Aleksandrov <[email protected]>---
I broke the line since it was >80 chars.
This patch applies to Dave's -net tree.net/netfilter/nft_payload.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)net/netfilter/nft_payload.c +0
-0net/netfilter/nft_payload.c nft_payload_select_ops(const struct nft_ctx *ctx, · line 140
Quoted 7 lines
net/netfilter/nft_payload.c +3
-1@@ -135,7 +135,9 @@ 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_ALIGNED (offset, len) && + base !=NFT_PAYLOAD_LL_HEADER && + !(offset & (offset -1 )))Small cosmetic note: we have
is_power_of_2(), which does exactly this.
Quoted 6 lines
Quoted 2 lines
I didn't choose
is_power_of_2because it also checks if x is != 0, so I thought we can allow for 0 offset with the fast ops.Sorry for not noticing before, but I'd propose to check length for power of two. We're trying to determine whether the load is well aligned.
hehe, I was wondering why the offset but decided to just go with it, should've asked.
Okay, going for v3 I guess.
Quoted 12 lines
Quoted 12 lines
Quoted 5 lines
Also I think the more logical order would be:
len <= 4 &&
is_power_of_2&&IS_ALIGNED&& base ...Okay :-)
Quoted 5 lines
Quoted 5 lines
net/netfilter/nft_payload.c +0
-0return &nft_payload_fast_ops; else return &nft_payload_ops;Signature · 1 line
1.8.4.2