net: skb_find_text: Ignore patterns extending past 'to'
Subsystems (4)
Phil Sutter
reviewerPATCH v2 1/1 net: skb_find_text: Ignore patterns extending past 'to'
Assume that caller's 'to' offset really represents an upper boundary for the pattern search, so patterns extending past this offset are to be rejected.
The old behaviour also was kind of inconsistent when it comes to fragmentation (or otherwise non-linear skbs): If the pattern started in between 'to' and 'from' offsets but extended to the next fragment, it was not found if 'to' offset was still within the current fragment.
Test the new behaviour in a kselftest using iptables' string match.
---
Changes since v1:
- Hook test into respective Makefile
- Reduce checkpatch.pl output by "fixing" Fixes: tag ref to 12 chars of hash from 13
--- net/core/skbuff.c | 3 +- tools/testing/selftests/netfilter/Makefile | 2 +- .../testing/selftests/netfilter/xt_string.sh | 128 ++++++++++++++++++ 3 files changed, 131 insertions(+), 2 deletions(-) create mode 100755 tools/testing/selftests/netfilter/xt_string.sh
net/core/skbuff.c +2 -1
@@ -4267,6 +4267,7 @@ static void skb_ts_finish(struct ts_config *conf, struct ts_state *state)unsigned int skb_find_text (struct sk_buff *skb,unsigned int from,unsigned int to,struct ts_config *config) { +unsigned int patlen = config->ops->get_pattern_len (config);struct ts_state state;unsigned int ret;
@@ -4278,7 +4279,7 @@ unsigned int skb_find_text(struct sk_buff *skb, unsigned int from,skb_prepare_seq_read (skb, from, to,TS_SKB_CB (&state)); ret =textsearch_find (config, &state); -return (ret <= to - from ? ret :UINT_MAX ); +return (ret + patlen <= to - from ? ret :UINT_MAX ); }EXPORT_SYMBOL (skb_find_text);
tools/testing/selftests/netfilter/Makefile +1 -1
@@ -7,7 +7,7 @@ TEST_PROGS := nft_trans_stress.sh nft_fib.sh nft_nat.sh bridge_brouter.sh \ nft_queue.sh nft_meta.sh nf_nat_edemux.sh \ ipip-conntrack-mtu.sh conntrack_tcp_unreplied.sh \ conntrack_vrf.sh nft_synproxy.sh rpath.sh nft_audit.sh \ - conntrack_sctp_collision.sh + conntrack_sctp_collision.sh xt_string.sh HOSTPKG_CONFIG := pkg-config
tools/testing/selftests/netfilter/xt_string.sh new file +128 -0
128 lines not on this page · raw message
Signature · 1 line
2.41.0
Quoted 10 lines · Phil Sutter
Assume that caller's 'to' offset really represents an upper boundary for the pattern search, so patterns extending past this offset are to be rejected.
The old behaviour also was kind of inconsistent when it comes to fragmentation (or otherwise non-linear skbs): If the pattern started in between 'to' and 'from' offsets but extended to the next fragment, it was not found if 'to' offset was still within the current fragment.
Test the new behaviour in a kselftest using iptables' string match.
Quoted 5 lines · Florian Westphal
Quoted 4 lines · Phil Sutter
Assume that caller's 'to' offset really represents an upper boundary for the pattern search, so patterns extending past this offset are to be rejected.
Quoted 8 lines
Quoted 6 lines
The old behaviour also was kind of inconsistent when it comes to fragmentation (or otherwise non-linear skbs): If the pattern started in between 'to' and 'from' offsets but extended to the next fragment, it was not found if 'to' offset was still within the current fragment.
Test the new behaviour in a kselftest using iptables' string match.
Reviewed-by Florian Westphal <[email protected]>
This patch was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Quoted 10 lines · On Tue, 17 Oct 2023 11:39:06 +0200 you wrote:
Assume that caller's 'to' offset really represents an upper boundary for the pattern search, so patterns extending past this offset are to be rejected.
The old behaviour also was kind of inconsistent when it comes to fragmentation (or otherwise non-linear skbs): If the pattern started in between 'to' and 'from' offsets but extended to the next fragment, it was not found if 'to' offset was still within the current fragment.
[...]
Here is the summary with links:
- [net-next,v2] net: skb_find_text: Ignore patterns extending past 'to'
https://git.kernel.org/netdev/net-next/c/c4eee56e14fe
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html