netfilter: disable payload mangling in userns
Subsystems (3)
PATCH 1/1 netfilter: disable payload mangling in userns
From: Florian Westphal <[email protected]>
Several parts of network stack rely on iph->ihl validation done by network stack before PRE_ROUTING.
Disable this feature for user namespaces for now.
This could be relaxed later. Example:
- allow userns only for ingress hook.
- allow userns write if base is transport header
- allow userns write if base is linklayer and offset below network header offset
- allow userns write for ipv4 if offset+len match saddr/daddr
- allow userns write for ipv6 if offset+len match saddr/daddr ... etc.
tcp option handling might be safe even for LOCAL_IN, as LOCAL_IN gets invoked before tcp stack, but this turns it off too. optstrip remains enabled, see no problem with that one.
I don't think these are the only means to alter packets, but these appear to be relatively prominent.
Another option would be to restrict this generally, however, this is harder to do for nfqueue. For nftables we know where the modification happens and can even reject a subset from netlink path directly. But for nfqueue, we'd need to 'revalidate' at least ip/ipv6 header for ipv4/ipv6 families. Bridge path might be okay with arbitray header modifications.
---
Tested on net.git tip: unprivileged userns nft @nh,*,* set rules hit -EPERM at rule install.
net/netfilter/nfnetlink_queue.c | 3 +++ net/netfilter/nft_exthdr.c | 3 +++ net/netfilter/nft_payload.c | 3 +++ 3 files changed, 9 insertions(+)
net/netfilter/nfnetlink_queue.c +3 -0
@@ -1141,6 +1141,9 @@ nfqnl_mangle(void *data, unsigned int data_len, struct nf_queue_entry *e, int di {struct sk_buff *nskb; +if (e->state.net->user_ns != &init_user_ns) +return -EPERM ; +if (diff <0 ) {unsigned int min_len =skb_transport_offset (e->skb);
net/netfilter/nft_exthdr.c +3 -0
@@ -551,6 +551,9 @@ static int nft_exthdr_tcp_set_init(const struct nft_ctx *ctx,u32 offset, len, flags =0 , op =NFT_EXTHDR_OP_IPV6 ;int err; +if (ctx->net->user_ns != &init_user_ns) +return -EPERM ; + if (!tb[NFTA_EXTHDR_SREG] || !tb[NFTA_EXTHDR_TYPE] || !tb[NFTA_EXTHDR_OFFSET] ||
net/netfilter/nft_payload.c +3 -0
@@ -917,6 +917,9 @@ static int nft_payload_set_init(const struct nft_ctx *ctx,struct nft_payload_set *priv =nft_expr_priv (expr);int err; +if (ctx->net->user_ns != &init_user_ns) +return -EPERM ; + priv->base =ntohl (nla_get_be32 (tb[NFTA_PAYLOAD_BASE ])); priv->len =ntohl (nla_get_be32 (tb[NFTA_PAYLOAD_LEN ]));
Signature · 1 line
2.47.3