* [PATCH net 0/3] netfilter updates for net
@ 2022-07-26 19:20 Florian Westphal
2022-07-26 19:20 ` [PATCH net 1/3] netfilter: nf_queue: do not allow packet truncation below transport header offset Florian Westphal
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Florian Westphal @ 2022-07-26 19:20 UTC (permalink / raw)
To: netdev
Cc: Paolo Abeni, Jakub Kicinski, David S. Miller, Eric Dumazet,
Florian Westphal
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(-)
--
2.35.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net 1/3] netfilter: nf_queue: do not allow packet truncation below transport header offset
2022-07-26 19:20 [PATCH net 0/3] netfilter updates for net Florian Westphal
@ 2022-07-26 19:20 ` Florian Westphal
2022-07-27 3:10 ` patchwork-bot+netdevbpf
2022-07-26 19:20 ` [PATCH net 2/3] netfilter: nf_tables: add rescheduling points during loop detection walks Florian Westphal
2022-07-26 19:20 ` [PATCH net 3/3] netfilter: nft_queue: only allow supported familes and hooks Florian Westphal
2 siblings, 1 reply; 5+ messages in thread
From: Florian Westphal @ 2022-07-26 19:20 UTC (permalink / raw)
To: netdev
Cc: Paolo Abeni, Jakub Kicinski, David S. Miller, Eric Dumazet,
Florian Westphal, Domingo Dirutigliano, Pablo Neira Ayuso
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).
Fixes: 7af4cc3fa158 ("[NETFILTER]: Add "nfnetlink_queue" netfilter queue handler over nfnetlink")
Reported-by: Domingo Dirutigliano <pwnzer0tt1@proton.me>
Signed-off-by: Florian Westphal <fw@strlen.de>
Reviewed-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/nfnetlink_queue.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c
index a364f8e5e698..87a9009d5234 100644
--- a/net/netfilter/nfnetlink_queue.c
+++ b/net/netfilter/nfnetlink_queue.c
@@ -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) {
--
2.35.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net 2/3] netfilter: nf_tables: add rescheduling points during loop detection walks
2022-07-26 19:20 [PATCH net 0/3] netfilter updates for net Florian Westphal
2022-07-26 19:20 ` [PATCH net 1/3] netfilter: nf_queue: do not allow packet truncation below transport header offset Florian Westphal
@ 2022-07-26 19:20 ` Florian Westphal
2022-07-26 19:20 ` [PATCH net 3/3] netfilter: nft_queue: only allow supported familes and hooks Florian Westphal
2 siblings, 0 replies; 5+ messages in thread
From: Florian Westphal @ 2022-07-26 19:20 UTC (permalink / raw)
To: netdev
Cc: Paolo Abeni, Jakub Kicinski, David S. Miller, Eric Dumazet,
Florian Westphal, Pablo Neira Ayuso
Add explicit rescheduling points during ruleset walk.
Switching to a faster algorithm is possible but this is a much
smaller change, suitable for nf tree.
Link: https://bugzilla.netfilter.org/show_bug.cgi?id=1460
Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/nf_tables_api.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 646d5fd53604..9f976b11d896 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -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) ||
--
2.35.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net 3/3] netfilter: nft_queue: only allow supported familes and hooks
2022-07-26 19:20 [PATCH net 0/3] netfilter updates for net Florian Westphal
2022-07-26 19:20 ` [PATCH net 1/3] netfilter: nf_queue: do not allow packet truncation below transport header offset Florian Westphal
2022-07-26 19:20 ` [PATCH net 2/3] netfilter: nf_tables: add rescheduling points during loop detection walks Florian Westphal
@ 2022-07-26 19:20 ` Florian Westphal
2 siblings, 0 replies; 5+ messages in thread
From: Florian Westphal @ 2022-07-26 19:20 UTC (permalink / raw)
To: netdev
Cc: Paolo Abeni, Jakub Kicinski, David S. Miller, Eric Dumazet,
Florian Westphal, Pablo Neira Ayuso
Trying 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)
Signed-off-by: Florian Westphal <fw@strlen.de>
Reviewed-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/nft_queue.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/net/netfilter/nft_queue.c b/net/netfilter/nft_queue.c
index 15e4b7640dc0..da29e92c03e2 100644
--- a/net/netfilter/nft_queue.c
+++ b/net/netfilter/nft_queue.c
@@ -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,
};
--
2.35.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net 1/3] netfilter: nf_queue: do not allow packet truncation below transport header offset
2022-07-26 19:20 ` [PATCH net 1/3] netfilter: nf_queue: do not allow packet truncation below transport header offset Florian Westphal
@ 2022-07-27 3:10 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-07-27 3:10 UTC (permalink / raw)
To: Florian Westphal; +Cc: netdev, pabeni, kuba, davem, edumazet, pwnzer0tt1, pablo
Hello:
This series was applied to netdev/net.git (master)
by Florian Westphal <fw@strlen.de>:
On Tue, 26 Jul 2022 21:20:54 +0200 you wrote:
> 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).
>
> [...]
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!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-07-27 3:10 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-26 19:20 [PATCH net 0/3] netfilter updates for net Florian Westphal
2022-07-26 19:20 ` [PATCH net 1/3] netfilter: nf_queue: do not allow packet truncation below transport header offset Florian Westphal
2022-07-27 3:10 ` patchwork-bot+netdevbpf
2022-07-26 19:20 ` [PATCH net 2/3] netfilter: nf_tables: add rescheduling points during loop detection walks Florian Westphal
2022-07-26 19:20 ` [PATCH net 3/3] netfilter: nft_queue: only allow supported familes and hooks Florian Westphal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).