netfilter updates for net
Subsystems (3)
Florian Westphal
maintainercover netfilter updates for net
Three late fixes for netfilter:
1) If nf_queue user requests packet truncation below size of l3 header, we corrupt the skb, then crash. Reject such requests.
2) add cond_resched() calls when doing cycle detection in the nf_tables graph. This avoids softlockup warning with certain rulesets.
3) Reject rulesets that use nftables 'queue' expression in family/chain combinations other than those that are supported. Currently the ruleset will load, but when userspace attempts to reinject you get WARN splat + packet drops.
The following changes since commit 9b134b1694ec8926926ba6b7b80884ea829245a0:
bridge: Do not send empty IFLA_AF_SPEC attribute (2022-07-26 15:35:53 +0200)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git
for you to fetch changes up to 47f4f510ad586032b85c89a0773fbb011d412425:
netfilter: nft_queue: only allow supported familes and hooks (2022-07-26 21:12:42 +0200)
----------------------------------------------------------------
Florian Westphal (3):
netfilter: nf_queue: do not allow packet truncation below transport header offset
netfilter: nf_tables: add rescheduling points during loop detection walks
netfilter: nft_queue: only allow supported familes and hooks
net/netfilter/nf_tables_api.c | 6 ++++++ net/netfilter/nfnetlink_queue.c | 7 ++++++- net/netfilter/nft_queue.c | 27 +++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-)
Signature · 1 line
2.35.1
Florian Westphal
maintainerPATCH 1/3 netfilter: nf_queue: do not allow packet truncation below transport header offset
Domingo Dirutigliano and Nicola Guerrera report kernel panic when sending nf_queue verdict with 1-byte nfta_payload attribute.
The IP/IPv6 stack pulls the IP(v6) header from the packet after the input hook.
If user truncates the packet below the header size, this skb_pull() will result in a malformed skb (skb->len < 0).
--- net/netfilter/nfnetlink_queue.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/netfilter/nfnetlink_queue.c +6 -1
@@ -843,11 +843,16 @@ nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum) }static int -nfqnl_mangle (void *data,int data_len,struct nf_queue_entry *e,int diff) +nfqnl_mangle (void *data,unsigned int data_len,struct nf_queue_entry *e,int diff) {struct sk_buff *nskb;if (diff <0 ) { +unsigned int min_len =skb_transport_offset (e->skb); + +if (data_len < min_len) +return -EINVAL ; +if (pskb_trim (e->skb, data_len))return -ENOMEM ; }else if (diff >0 ) {
Signature · 1 line
2.35.1
Re: [PATCH net 1/3] netfilter: nf_queue: do not allow packet truncation below transport header offset
This series was applied to netdev/net.git (master) by Florian Westphal <[email protected]>:
Hello:
This series was applied to netdev/net.git (master) by Florian Westphal <[email protected]>:
Quoted 10 lines · On Tue, 26 Jul 2022 21:20:54 +0200 you wrote:
Domingo Dirutigliano and Nicola Guerrera report kernel panic when sending
nf_queueverdict with 1-bytenfta_payloadattribute.The IP/IPv6 stack pulls the IP(v6) header from the packet after the input hook.
If user truncates the packet below the header size, this
skb_pull()will result in a malformed skb (skb->len< 0).[...]
Here is the summary with links:
- [net,1/3] netfilter: nf_queue: do not allow packet truncation below transport header offset
https://git.kernel.org/netdev/net/c/99a63d36cb3e - [net,2/3] netfilter: nf_tables: add rescheduling points during loop detection walks https://git.kernel.org/netdev/net/c/81ea01066741 - [net,3/3] netfilter: nft_queue: only allow supported familes and hooks https://git.kernel.org/netdev/net/c/47f4f510ad58
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Florian Westphal
maintainerPATCH 2/3 netfilter: nf_tables: add rescheduling points during loop detection walks
In reply to Florian WestphalAdd explicit rescheduling points during ruleset walk.
Switching to a faster algorithm is possible but this is a much smaller change, suitable for nf tree.
--- net/netfilter/nf_tables_api.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/netfilter/nf_tables_api.c +6 -0
@@ -3340,6 +3340,8 @@ int nft_chain_validate(const struct nft_ctx *ctx, const struct nft_chain *chain)if (err <0 )return err; } + +cond_resched (); }return 0 ;
@@ -9367,9 +9369,13 @@ static int nf_tables_check_loops(const struct nft_ctx *ctx,break ; } } + +cond_resched (); }list_for_each_entry (set, &ctx->table->sets, list) { +cond_resched (); +if (!nft_is_active_next (ctx->net, set))continue ; if (!(set->flags & NFT_SET_MAP) ||
Signature · 1 line
2.35.1
Florian Westphal
maintainerPATCH 3/3 netfilter: nft_queue: only allow supported familes and hooks
In reply to Florian WestphalTrying to use 'queue' statement in ingress (for example) triggers a splat on reinject:
WARNING: CPU: 3 PID: 1345 at net/netfilter/nf_queue.c:291
... because nf_reinject cannot find the ruleset head.
The netdev family doesn't support async resume at the moment anyway, so disallow loading such rulesets with a more appropriate error message.
v2: add 'validate' callback and also check hook points, v1 did allow ingress use in 'table inet', but that doesn't work either. (Pablo)
--- net/netfilter/nft_queue.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
net/netfilter/nft_queue.c +27 -0
@@ -68,6 +68,31 @@ static void nft_queue_sreg_eval(const struct nft_expr *expr, regs->verdict.code = ret; } +static int nft_queue_validate (const struct nft_ctx *ctx, +const struct nft_expr *expr, +const struct nft_data **data) +{ +static const unsigned int supported_hooks = ((1 <<NF_INET_PRE_ROUTING ) | + (1 <<NF_INET_LOCAL_IN ) | + (1 <<NF_INET_FORWARD ) | + (1 <<NF_INET_LOCAL_OUT ) | + (1 <<NF_INET_POST_ROUTING )); + +switch (ctx->family) { +case NFPROTO_IPV4 : +case NFPROTO_IPV6 : +case NFPROTO_INET : +case NFPROTO_BRIDGE : +break ; +case NFPROTO_NETDEV :/* lacks okfn */ + fallthrough; +default : +return -EOPNOTSUPP ; + } + +return nft_chain_validate_hooks (ctx->chain, supported_hooks); +} +static const struct nla_policy nft_queue_policy[NFTA_QUEUE_MAX +1 ] = { [NFTA_QUEUE_NUM ] = { .type =NLA_U16 }, [NFTA_QUEUE_TOTAL ] = { .type =NLA_U16 },
@@ -164,6 +189,7 @@ static const struct nft_expr_ops nft_queue_ops = { .eval = nft_queue_eval, .init = nft_queue_init, .dump = nft_queue_dump, + .validate = nft_queue_validate, .reduce = NFT_REDUCE_READONLY, };
@@ -173,6 +199,7 @@ static const struct nft_expr_ops nft_queue_sreg_ops = { .eval = nft_queue_sreg_eval, .init = nft_queue_sreg_init, .dump = nft_queue_sreg_dump, + .validate = nft_queue_validate, .reduce = NFT_REDUCE_READONLY, };
Signature · 1 line
2.35.1