Netfilter fixes for net
Subsystems (3)
Pablo Neira Ayuso
maintainercover Netfilter fixes for net
Hi,
The following patchset contains Netfilter fixes for net:
1) Allow conntrack entries with l3num == NFPROTO_IPV4 or == NFPROTO_IPV6 only via ctnetlink, from Will McVicker.
2) Batch notifications to userspace to improve netlink socket receive utilization.
3) Restore mark based dump filtering via ctnetlink, from Martin Willi.
4) nf_conncount_init() fails with -EPROTO with CONFIG_IPV6, from Eelco Chaudron.
5) Containers fail to match on meta skuid and skgid, use socket user_ns to retrieve meta skuid and skgid.
Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
Thank you.
----------------------------------------------------------------
The following changes since commit 19162fd4063a3211843b997a454b505edb81d5ce:
hv_netvsc: Fix hibernation for mlx5 VF driver (2020-09-07 21:04:36 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git HEAD
for you to fetch changes up to 0c92411bb81de9bc516d6924f50289d8d5f880e5:
netfilter: nft_meta: use socket user_ns to retrieve skuid and skgid (2020-09-08 13:04:56 +0200)
----------------------------------------------------------------
Eelco Chaudron (1):
netfilter: conntrack: nf_conncount_init is failing with IPv6 disabled
Martin Willi (1):
netfilter: ctnetlink: fix mark based dump filtering regression
Pablo Neira Ayuso (2):
netfilter: nf_tables: coalesce multiple notifications into one skbuff
netfilter: nft_meta: use socket user_ns to retrieve skuid and skgid
Will McVicker (1):
netfilter: ctnetlink: add a range check for l3/l4 protonum
include/net/netns/nftables.h | 1 + net/netfilter/nf_conntrack_netlink.c | 22 +++--------- net/netfilter/nf_conntrack_proto.c | 2 ++ net/netfilter/nf_tables_api.c | 70 +++++++++++++++++++++++++++++------- net/netfilter/nft_meta.c | 4 +-- 5 files changed, 67 insertions(+), 32 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 1/5 netfilter: ctnetlink: add a range check for l3/l4 protonum
From: Will McVicker <[email protected]>
The indexes to the nf_nat_l[34]protos arrays come from userspace. So check the tuple's family, e.g. l3num, when creating the conntrack in order to prevent an OOB memory access during setup. Here is an example kernel panic on 4.14.180 when userspace passes in an index greater than NFPROTO_NUMPROTO.
Internal error: Oops - BUG: 0 [#1] PREEMPT SMP Modules linked in:... Process poc (pid: 5614, stack limit = 0x00000000a3933121) CPU: 4 PID: 5614 Comm: poc Tainted: G S W O 4.14.180-g051355490483 Hardware name: Qualcomm Technologies, Inc. SM8150 V2 PM8150 Google Inc. MSM task: 000000002a3dfffe task.stack: 00000000a3933121 pc : __cfi_check_fail+0x1c/0x24 lr : __cfi_check_fail+0x1c/0x24 ... Call trace: __cfi_check_fail+0x1c/0x24 name_to_dev_t+0x0/0x468 nfnetlink_parse_nat_setup+0x234/0x258 ctnetlink_parse_nat_setup+0x4c/0x228 ctnetlink_new_conntrack+0x590/0xc40 nfnetlink_rcv_msg+0x31c/0x4d4 netlink_rcv_skb+0x100/0x184 nfnetlink_rcv+0xf4/0x180 netlink_unicast+0x360/0x770 netlink_sendmsg+0x5a0/0x6a4 ___sys_sendmsg+0x314/0x46c SyS_sendmsg+0xb4/0x108 el0_svc_naked+0x34/0x38
This crash is not happening since 5.4+, however, ctnetlink still allows for creating entries with unsupported layer 3 protocol number.
--- net/netfilter/nf_conntrack_netlink.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/netfilter/nf_conntrack_netlink.c +2 -1
@@ -1404,7 +1404,8 @@ ctnetlink_parse_tuple_filter(const struct nlattr * const cda[],if (err <0 )return err; - +if (l3num !=NFPROTO_IPV4 && l3num !=NFPROTO_IPV6 ) +return -EOPNOTSUPP ; tuple->src.l3num = l3num; if (flags & CTA_FILTER_FLAG(CTA_IP_DST) ||
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 2/5 netfilter: nf_tables: coalesce multiple notifications into one skbuff
In reply to Pablo Neira AyusoOn x86_64, each notification results in one skbuff allocation which consumes at least 768 bytes due to the skbuff overhead.
This patch coalesces several notifications into one single skbuff, so each notification consumes at least ~211 bytes, that ~3.5 times less memory consumption. As a result, this is reducing the chances to exhaust the netlink socket receive buffer.
Rule of thumb is that each notification batch only contains netlink messages whose report flag is the same, nfnetlink_send() requires this to do appropriate delivery to userspace, either via unicast (echo mode) or multicast (monitor mode).
The skbuff control buffer is used to annotate the report flag for later handling at the new coalescing routine.
The batch skbuff notification size is NLMSG_GOODSIZE, using a larger skbuff would allow for more socket receiver buffer savings (to amortize the cost of the skbuff even more), however, going over that size might break userspace applications, so let's be conservative and stick to NLMSG_GOODSIZE.
--- include/net/netns/nftables.h | 1 + net/netfilter/nf_tables_api.c | 70 ++++++++++++++++++++++++++++------- 2 files changed, 58 insertions(+), 13 deletions(-)
include/net/netns/nftables.h +1 -0
@@ -8,6 +8,7 @@ struct netns_nftables {struct list_head tables;struct list_head commit_list;struct list_head module_list; +struct list_head notify_list;struct mutex commit_mutex;unsigned int base_seq;u8 gencursor;
net/netfilter/nf_tables_api.c +57 -13
142 lines not on this page · raw message
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 3/5 netfilter: ctnetlink: fix mark based dump filtering regression
In reply to Pablo Neira AyusoFrom: Martin Willi <[email protected]>
conntrack mark based dump filtering may falsely skip entries if a mask is given: If the mask-based check does not filter out the entry, the else-if check is always true and compares the mark without considering the mask. The if/else-if logic seems wrong.
Given that the mask during filter setup is implicitly set to 0xffffffff if not specified explicitly, the mark filtering flags seem to just complicate things. Restore the previously used approach by always matching against a zero mask is no filter mark is given.
--- net/netfilter/nf_conntrack_netlink.c | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-)
net/netfilter/nf_conntrack_netlink.c +3 -16
@@ -851,7 +851,6 @@ static int ctnetlink_done(struct netlink_callback *cb) }struct ctnetlink_filter { -u_int32_t cta_flags;u8 family;u_int32_t orig_flags;
@@ -906,10 +905,6 @@ static int ctnetlink_parse_tuple_filter(const struct nlattr * const cda[],struct nf_conntrack_zone *zone, u_int32_t flags); -/* applied on filters */ -#define CTA_FILTER_F_CTA_MARK (1 << 0) -#define CTA_FILTER_F_CTA_MARK_MASK (1 << 1) -static struct ctnetlink_filter *ctnetlink_alloc_filter (const struct nlattr *const cda[],u8 family) {
@@ -930,14 +925,10 @@ ctnetlink_alloc_filter(const struct nlattr * const cda[], u8 family)#ifdef CONFIG_NF_CONNTRACK_MARK if (cda[CTA_MARK ]) { filter->mark.val =ntohl (nla_get_be32 (cda[CTA_MARK ])); - filter->cta_flags |=CTA_FILTER_FLAG (CTA_MARK ); - -if (cda[CTA_MARK_MASK ]) { +if (cda[CTA_MARK_MASK ]) filter->mark.mask =ntohl (nla_get_be32 (cda[CTA_MARK_MASK ])); - filter->cta_flags |=CTA_FILTER_FLAG (CTA_MARK_MASK ); - }else { +else filter->mark.mask =0xffffffff ; - } }else if (cda[CTA_MARK_MASK ]) { err = -EINVAL ; goto err_filter;
@@ -1117,11 +1108,7 @@ static int ctnetlink_filter_match(struct nf_conn *ct, void *data) }#ifdef CONFIG_NF_CONNTRACK_MARK -if ((filter->cta_flags &CTA_FILTER_FLAG (CTA_MARK_MASK )) && - (ct->mark & filter->mark.mask) != filter->mark.val) - goto ignore_entry; -else if ((filter->cta_flags &CTA_FILTER_FLAG (CTA_MARK )) && - ct->mark != filter->mark.val) +if ((ct->mark & filter->mark.mask) != filter->mark.val) goto ignore_entry;#endif
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 4/5 netfilter: conntrack: nf_conncount_init is failing with IPv6 disabled
In reply to Pablo Neira AyusoFrom: Eelco Chaudron <[email protected]>
The openvswitch module fails initialization when used in a kernel without IPv6 enabled. nf_conncount_init() fails because the ct code unconditionally tries to initialize the netns IPv6 related bit, regardless of the build option. The change below ignores the IPv6 part if not enabled.
Note that the corresponding _put() function already has this IPv6 configuration check.
--- net/netfilter/nf_conntrack_proto.c | 2 ++ 1 file changed, 2 insertions(+)
net/netfilter/nf_conntrack_proto.c +2 -0
@@ -565,6 +565,7 @@ static int nf_ct_netns_inet_get(struct net *net)int err; err =nf_ct_netns_do_get (net,NFPROTO_IPV4 ); +#if IS_ENABLED (CONFIG_IPV6 )if (err <0 ) goto err1; err =nf_ct_netns_do_get (net,NFPROTO_IPV6 );
@@ -575,6 +576,7 @@ static int nf_ct_netns_inet_get(struct net *net) err2:nf_ct_netns_put (net,NFPROTO_IPV4 ); err1: +#endif return err; }
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 5/5 netfilter: nft_meta: use socket user_ns to retrieve skuid and skgid
In reply to Pablo Neira Ayuso... instead of using init_user_ns.
--- net/netfilter/nft_meta.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nft_meta.c +2 -2
@@ -147,11 +147,11 @@ nft_meta_get_eval_skugid(enum nft_meta_keys key,switch (key) {case NFT_META_SKUID : - *dest =from_kuid_munged (&init_user_ns, + *dest =from_kuid_munged (sock_net (sk)->user_ns, sock->file->f_cred->fsuid);break ;case NFT_META_SKGID : - *dest =from_kgid_munged (&init_user_ns, + *dest =from_kgid_munged (sock_net (sk)->user_ns, sock->file->f_cred->fsgid);break ;default :
Signature · 1 line
2.20.1
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Tue, 8 Sep 2020 17:09:42 +0200
Quoted 13 lines
The following patchset contains Netfilter fixes for net:
1) Allow conntrack entries with l3num ==
NFPROTO_IPV4or ==NFPROTO_IPV6only via ctnetlink, from Will McVicker.2) Batch notifications to userspace to improve netlink socket receive utilization.
3) Restore mark based dump filtering via ctnetlink, from Martin Willi.
4)
nf_conncount_init()fails with-EPROTOwithCONFIG_IPV6, from Eelco Chaudron.
Quoted 6 lines
5) Containers fail to match on meta skuid and skgid, use socket
user_nsto retrieve meta skuid and skgid.Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
Pulled, thanks Pablo.