Netfilter fixes for net
Subsystems (5)
Pablo Neira Ayuso
maintainerv2 cover Netfilter fixes for net
Hi,
The following batch contains Netfilter fixes for net. Slightly larger than usual because this batch includes several patches to tighten the nf_tables control plane to reject inconsistent configuration:
1) Restrict NFTA_SET_POLICY to NFT_SET_POL_PERFORMANCE and NFT_SET_POL_MEMORY.
2) Bail out if a nf_tables expression registers more than 16 netlink attributes which is what struct nft_expr_info allows.
3) Bail out if NFT_EXPR_STATEFUL provides no .clone interface, remove existing fallback to memcpy() when cloning which might accidentally duplicate memory reference to the same object.
4) Fix br_netfilter interaction with neighbour layer. This requires three preparation patches:
- Use nf_bridge_get_physinif() in nfnetlink_log
- Use nf_bridge_info_exists() to check in br_netfilter context is available in nf_queue.
- Pass net to nf_bridge_get_physindev()
And finally, the fix which replaces physindev with physinif in nf_bridge_info.
Patches from Pavel Tikhomirov.
5) Catch-all deactivation happens in the transaction, hence this oneliner to check for the next generation. This bug uncovered after the removal of the _BUSY bit, which happened in set elements back in summer 2023.
6) Ensure set (total) key length size and concat field length description is consistent, otherwise bail out.
7) Skip set element with the _DEAD flag on from the netlink dump path. A tests occasionally shows that dump is mismatching because GC might lose race to get rid of this element while a netlink dump is in progress.
8) Reject NFT_SET_CONCAT for field_count < 1.
9) Use IP6_INC_STATS in ipvs to fix preemption BUG splat, patch from Fedor Pchelkin.
Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git nf-24-01-18
Thanks.
----------------------------------------------------------------
This is v2 without Jozsef's ipset patch.
----------------------------------------------------------------
The following changes since commit ea937f77208323d35ffe2f8d8fc81b00118bfcda:
net: netdevsim: don't try to destroy PHC on VFs (2024-01-17 10:56:44 +0000)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git tags/nf-24-01-18
for you to fetch changes up to d6938c1c76c64f42363d0d1f051e1b4641c2ad40:
ipvs: avoid stat macros calls from preemptible context (2024-01-17 12:02:51 +0100)
----------------------------------------------------------------
netfilter pull request 24-01-18
----------------------------------------------------------------
Fedor Pchelkin (1):
ipvs: avoid stat macros calls from preemptible context
Pablo Neira Ayuso (8):
netfilter: nf_tables: reject invalid set policy
netfilter: nf_tables: validate .maxattr at expression registration
netfilter: nf_tables: bail out if stateful expression provides no .clone
netfilter: nft_limit: do not ignore unsupported flags
netfilter: nf_tables: check if catch-all set element is active in next generation
netfilter: nf_tables: do not allow mismatch field size and set key length
netfilter: nf_tables: skip dead set elements in netlink dump
netfilter: nf_tables: reject NFT_SET_CONCAT with not field length description
Pavel Tikhomirov (4):
netfilter: nfnetlink_log: use proper helper for fetching physinif
netfilter: nf_queue: remove excess nf_bridge variable
netfilter: propagate net to nf_bridge_get_physindev
netfilter: bridge: replace physindev with physinif in nf_bridge_info
include/linux/netfilter_bridge.h | 6 ++-- include/linux/skbuff.h | 2 +- net/bridge/br_netfilter_hooks.c | 42 ++++++++++++++++++++++------ net/bridge/br_netfilter_ipv6.c | 14 +++++++--- net/ipv4/netfilter/nf_reject_ipv4.c | 9 ++++-- net/ipv6/netfilter/nf_reject_ipv6.c | 11 ++++++-- net/netfilter/ipset/ip_set_hash_netiface.c | 8 +++--- net/netfilter/ipvs/ip_vs_xmit.c | 4 +-- net/netfilter/nf_log_syslog.c | 13 +++++---- net/netfilter/nf_queue.c | 6 ++-- net/netfilter/nf_tables_api.c | 44 +++++++++++++++++++++--------- net/netfilter/nfnetlink_log.c | 8 +++--- net/netfilter/nft_limit.c | 19 ++++++++----- net/netfilter/xt_physdev.c | 2 +- 14 files changed, 125 insertions(+), 63 deletions(-)
Pablo Neira Ayuso
maintainerPATCH v2 1/13 netfilter: nf_tables: reject invalid set policy
Report -EINVAL in case userspace provides a unsupported set backend policy.
--- net/netfilter/nf_tables_api.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +9 -1
@@ -5048,8 +5048,16 @@ static int nf_tables_newset(struct sk_buff *skb, const struct nfnl_info *info, } desc.policy =NFT_SET_POL_PERFORMANCE ; -if (nla[NFTA_SET_POLICY ] !=NULL ) +if (nla[NFTA_SET_POLICY ] !=NULL ) { desc.policy =ntohl (nla_get_be32 (nla[NFTA_SET_POLICY ])); +switch (desc.policy) { +case NFT_SET_POL_PERFORMANCE : +case NFT_SET_POL_MEMORY : +break ; +default : +return -EOPNOTSUPP ; + } + }if (nla[NFTA_SET_DESC ] !=NULL ) { err =nf_tables_set_desc_parse (&desc, nla[NFTA_SET_DESC ]);
Signature · 1 line
2.30.2
Re: [PATCH net 01/13] netfilter: nf_tables: reject invalid set policy
This series was applied to netdev/net.git (main) by Pablo Neira Ayuso <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Pablo Neira Ayuso <[email protected]>:
Quoted 8 lines · On Thu, 18 Jan 2024 17:17:14 +0100 you wrote:
Report
-EINVALin case userspace provides a unsupported set backend policy.Fixes c50b960ccc59 ("netfilter: nf_tables: implement proper set selection")Signed-off-by Pablo Neira Ayuso <[email protected]>--- net/netfilter/nf_tables_api.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
Here is the summary with links:
- [net,01/13] netfilter: nf_tables: reject invalid set policy
https://git.kernel.org/netdev/net/c/0617c3de9b40 - [net,02/13] netfilter: nf_tables: validate .maxattr at expression registration https://git.kernel.org/netdev/net/c/65b3bd600e15 - [net,03/13] netfilter: nf_tables: bail out if stateful expression provides no .clone https://git.kernel.org/netdev/net/c/3c13725f43dc - [net,04/13] netfilter: nft_limit: do not ignore unsupported flags https://git.kernel.org/netdev/net/c/91a139cee120 - [net,05/13] netfilter: nfnetlink_log: use proper helper for fetching physinif https://git.kernel.org/netdev/net/c/c3f9fd54cd87 - [net,06/13] netfilter: nf_queue: remove excess nf_bridge variable https://git.kernel.org/netdev/net/c/aeaa44075f8e - [net,07/13] netfilter: propagate net to nf_bridge_get_physindev https://git.kernel.org/netdev/net/c/a54e72197037 - [net,08/13] netfilter: bridge: replace physindev with physinif in nf_bridge_info https://git.kernel.org/netdev/net/c/9874808878d9 - [net,09/13] netfilter: nf_tables: check if catch-all set element is active in next generation https://git.kernel.org/netdev/net/c/b1db244ffd04 - [net,10/13] netfilter: nf_tables: do not allow mismatch field size and set key length https://git.kernel.org/netdev/net/c/3ce67e3793f4 - [net,11/13] netfilter: nf_tables: skip dead set elements in netlink dump https://git.kernel.org/netdev/net/c/6b1ca88e4bb6 - [net,12/13] netfilter: nf_tables: reject NFT_SET_CONCAT with not field length description https://git.kernel.org/netdev/net/c/113661e07460 - [net,13/13] ipvs: avoid stat macros calls from preemptible context https://git.kernel.org/netdev/net/c/d6938c1c76c6
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Pablo Neira Ayuso
maintainerPATCH v2 2/13 netfilter: nf_tables: validate .maxattr at expression registration
In reply to Pablo Neira Ayusostruct nft_expr_info allows to store up to NFT_EXPR_MAXATTR (16) attributes when parsing netlink attributes.
Rise a warning in case there is ever a nft expression whose .maxattr goes beyond this number of expressions, in such case, struct nft_expr_info needs to be updated.
--- net/netfilter/nf_tables_api.c | 3 +++ 1 file changed, 3 insertions(+)
net/netfilter/nf_tables_api.c +3 -0
@@ -2977,6 +2977,9 @@ static int nf_tables_delchain(struct sk_buff *skb, const struct nfnl_info *info,*/ int nft_register_expr (struct nft_expr_type *type) { +if (WARN_ON_ONCE (type->maxattr >NFT_EXPR_MAXATTR )) +return -ENOMEM ; +nfnl_lock (NFNL_SUBSYS_NFTABLES );if (type->family ==NFPROTO_UNSPEC )list_add_tail_rcu (&type->list, &nf_tables_expressions);
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH v2 3/13 netfilter: nf_tables: bail out if stateful expression provides no .clone
In reply to Pablo Neira AyusoAll existing NFT_EXPR_STATEFUL provide a .clone interface, remove fallback to copy content of stateful expression since this is never exercised and bail out if .clone interface is not defined.
--- net/netfilter/nf_tables_api.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
net/netfilter/nf_tables_api.c +7 -8
@@ -3274,14 +3274,13 @@ int nft_expr_clone(struct nft_expr *dst, struct nft_expr *src) {int err; -if (src->ops->clone) { - dst->ops = src->ops; - err = src->ops->clone (dst, src); -if (err <0 ) -return err; - }else { -memcpy (dst, src, src->ops->size); - } +if (WARN_ON_ONCE (!src->ops->clone)) +return -EINVAL ; + + dst->ops = src->ops; + err = src->ops->clone (dst, src); +if (err <0 ) +return err;__module_get (src->ops->type->owner);
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH v2 4/13 netfilter: nft_limit: do not ignore unsupported flags
In reply to Pablo Neira AyusoBail out if userspace provides unsupported flags, otherwise future extensions to the limit expression will be silently ignored by the kernel.
--- net/netfilter/nft_limit.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
net/netfilter/nft_limit.c +12 -7
@@ -58,6 +58,7 @@ static inline bool nft_limit_eval(struct nft_limit_priv *priv, u64 cost)static int nft_limit_init (struct nft_limit_priv *priv,const struct nlattr *const tb[],bool pkts) { +bool invert = false;u64 unit, tokens; if (tb[NFTA_LIMIT_RATE] == NULL ||
@@ -90,19 +91,23 @@ static int nft_limit_init(struct nft_limit_priv *priv, priv->rate); } +if (tb[NFTA_LIMIT_FLAGS ]) { +u32 flags =ntohl (nla_get_be32 (tb[NFTA_LIMIT_FLAGS ])); + +if (flags & ~NFT_LIMIT_F_INV ) +return -EOPNOTSUPP ; + +if (flags &NFT_LIMIT_F_INV ) + invert = true; + } + priv->limit =kmalloc (sizeof (*priv->limit),GFP_KERNEL_ACCOUNT );if (!priv->limit)return -ENOMEM ; priv->limit->tokens = tokens; priv->tokens_max = priv->limit->tokens; - -if (tb[NFTA_LIMIT_FLAGS ]) { -u32 flags =ntohl (nla_get_be32 (tb[NFTA_LIMIT_FLAGS ])); - -if (flags &NFT_LIMIT_F_INV ) - priv->invert = true; - } + priv->invert = invert; priv->limit->last =ktime_get_ns ();spin_lock_init (&priv->limit->lock);
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH v2 5/13 netfilter: nfnetlink_log: use proper helper for fetching physinif
In reply to Pablo Neira AyusoFrom: Pavel Tikhomirov <[email protected]>
We don't use physindev in __build_packet_message except for getting physinif from it. So let's switch to nf_bridge_get_physinif to get what we want directly.
--- net/netfilter/nfnetlink_log.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/netfilter/nfnetlink_log.c +4 -4
@@ -508,7 +508,7 @@ __build_packet_message(struct nfnl_log_net *log, htonl(br_port_get_rcu(indev)->br->dev->ifindex))) goto nla_put_failure; }else { -struct net_device *physindev; +int physinif;/* Case 2: indev is bridge group, we need to look for * physical device (when called from ipv4) */
@@ -516,10 +516,10 @@ __build_packet_message(struct nfnl_log_net *log, htonl(indev->ifindex))) goto nla_put_failure; - physindev =nf_bridge_get_physindev (skb); -if (physindev && + physinif =nf_bridge_get_physinif (skb); +if (physinif &&nla_put_be32 (inst->skb,NFULA_IFINDEX_PHYSINDEV , -htonl (physindev->ifindex))) +htonl (physinif))) goto nla_put_failure; }#endif
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH v2 6/13 netfilter: nf_queue: remove excess nf_bridge variable
In reply to Pablo Neira AyusoFrom: Pavel Tikhomirov <[email protected]>
We don't really need nf_bridge variable here. And nf_bridge_info_exists is better replacement for nf_bridge_info_get in case we are only checking for existence.
--- net/netfilter/nf_queue.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
net/netfilter/nf_queue.c +1 -3
@@ -82,10 +82,8 @@ static void __nf_queue_entry_init_physdevs(struct nf_queue_entry *entry) {#if IS_ENABLED (CONFIG_BRIDGE_NETFILTER )const struct sk_buff *skb = entry->skb; -struct nf_bridge_info *nf_bridge; - nf_bridge =nf_bridge_info_get (skb); -if (nf_bridge) { +if (nf_bridge_info_exists (skb)) { entry->physin =nf_bridge_get_physindev (skb); entry->physout =nf_bridge_get_physoutdev (skb); }else {
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH v2 7/13 netfilter: propagate net to nf_bridge_get_physindev
In reply to Pablo Neira AyusoFrom: Pavel Tikhomirov <[email protected]>
This is a preparation patch for replacing physindev with physinif on nf_bridge_info structure. We will use dev_get_by_index_rcu to resolve device, when needed, and it requires net to be available.
--- include/linux/netfilter_bridge.h | 2 +- net/ipv4/netfilter/nf_reject_ipv4.c | 2 +- net/ipv6/netfilter/nf_reject_ipv6.c | 2 +- net/netfilter/ipset/ip_set_hash_netiface.c | 8 ++++---- net/netfilter/nf_log_syslog.c | 13 +++++++------ net/netfilter/nf_queue.c | 2 +- net/netfilter/xt_physdev.c | 2 +- 7 files changed, 16 insertions(+), 15 deletions(-)
include/linux/netfilter_bridge.h +1 -1
@@ -56,7 +56,7 @@ static inline int nf_bridge_get_physoutif(const struct sk_buff *skb) }static inline struct net_device * -nf_bridge_get_physindev (const struct sk_buff *skb) +nf_bridge_get_physindev (const struct sk_buff *skb,struct net *net) {const struct nf_bridge_info *nf_bridge =nf_bridge_info_get (skb);
net/ipv4/netfilter/nf_reject_ipv4.c +1 -1
@@ -289,7 +289,7 @@ void nf_send_reset(struct net *net, struct sock *sk, struct sk_buff *oldskb,* build the eth header using the original destination's MAC as the * source, and send the RST packet directly. */ - br_indev =nf_bridge_get_physindev (oldskb); + br_indev =nf_bridge_get_physindev (oldskb, net);if (br_indev) {struct ethhdr *oeth =eth_hdr (oldskb);
net/ipv6/netfilter/nf_reject_ipv6.c +1 -1
@@ -354,7 +354,7 @@ void nf_send_reset6(struct net *net, struct sock *sk, struct sk_buff *oldskb,* build the eth header using the original destination's MAC as the * source, and send the RST packet directly. */ - br_indev =nf_bridge_get_physindev (oldskb); + br_indev =nf_bridge_get_physindev (oldskb, net);if (br_indev) {struct ethhdr *oeth =eth_hdr (oldskb);
net/netfilter/ipset/ip_set_hash_netiface.c +4 -4
@@ -138,9 +138,9 @@ hash_netiface4_data_next(struct hash_netiface4_elem *next,#include "ip_set_hash_gen.h" #if IS_ENABLED (CONFIG_BRIDGE_NETFILTER ) -static const char *get_physindev_name (const struct sk_buff *skb) +static const char *get_physindev_name (const struct sk_buff *skb,struct net *net) { -struct net_device *dev =nf_bridge_get_physindev (skb); +struct net_device *dev =nf_bridge_get_physindev (skb, net);return dev ? dev->name :NULL ; }
@@ -177,7 +177,7 @@ hash_netiface4_kadt(struct ip_set *set, const struct sk_buff *skb,if (opt->cmdflags &IPSET_FLAG_PHYSDEV ) {#if IS_ENABLED (CONFIG_BRIDGE_NETFILTER ) -const char *eiface =SRCDIR ?get_physindev_name (skb) : +const char *eiface =SRCDIR ?get_physindev_name (skb,xt_net (par)) :get_physoutdev_name (skb);if (!eiface)
@@ -395,7 +395,7 @@ hash_netiface6_kadt(struct ip_set *set, const struct sk_buff *skb,if (opt->cmdflags &IPSET_FLAG_PHYSDEV ) {#if IS_ENABLED (CONFIG_BRIDGE_NETFILTER ) -const char *eiface =SRCDIR ?get_physindev_name (skb) : +const char *eiface =SRCDIR ?get_physindev_name (skb,xt_net (par)) :get_physoutdev_name (skb);if (!eiface)
net/netfilter/nf_log_syslog.c +7 -6
@@ -111,7 +111,8 @@ nf_log_dump_packet_common(struct nf_log_buf *m, u8 pf, unsigned int hooknum, const struct sk_buff *skb, const struct net_device *in, const struct net_device *out, - const struct nf_loginfo *loginfo, const char *prefix) + const struct nf_loginfo *loginfo, const char *prefix, + struct net *net) { const struct net_device *physoutdev __maybe_unused;const struct net_device *physindev__maybe_unused ;
@@ -121,7 +122,7 @@ nf_log_dump_packet_common(struct nf_log_buf *m, u8 pf, in ? in->name :"" , out ? out->name : "");#if IS_ENABLED (CONFIG_BRIDGE_NETFILTER ) - physindev =nf_bridge_get_physindev (skb); + physindev =nf_bridge_get_physindev (skb, net);if (physindev && in != physindev)nf_log_buf_add (m,"PHYSIN=%s " , physindev->name); physoutdev =nf_bridge_get_physoutdev (skb);
@@ -148,7 +149,7 @@ static void nf_log_arp_packet(struct net *net, u_int8_t pf, loginfo = &default_loginfo;nf_log_dump_packet_common (m, pf, hooknum, skb, in, out, loginfo, - prefix); + prefix, net);dump_arp_packet (m, loginfo, skb,skb_network_offset (skb));nf_log_buf_close (m);
@@ -845,7 +846,7 @@ static void nf_log_ip_packet(struct net *net, u_int8_t pf, loginfo = &default_loginfo;nf_log_dump_packet_common (m, pf, hooknum, skb, in, - out, loginfo, prefix); + out, loginfo, prefix, net);if (in)dump_mac_header (m, loginfo, skb);
@@ -880,7 +881,7 @@ static void nf_log_ip6_packet(struct net *net, u_int8_t pf, loginfo = &default_loginfo;nf_log_dump_packet_common (m, pf, hooknum, skb, in, out, - loginfo, prefix); + loginfo, prefix, net);if (in)dump_mac_header (m, loginfo, skb);
@@ -916,7 +917,7 @@ static void nf_log_unknown_packet(struct net *net, u_int8_t pf, loginfo = &default_loginfo;nf_log_dump_packet_common (m, pf, hooknum, skb, in, out, loginfo, - prefix); + prefix, net);dump_mac_header (m, loginfo, skb);
net/netfilter/nf_queue.c +1 -1
@@ -84,7 +84,7 @@ static void __nf_queue_entry_init_physdevs(struct nf_queue_entry *entry)const struct sk_buff *skb = entry->skb;if (nf_bridge_info_exists (skb)) { - entry->physin =nf_bridge_get_physindev (skb); + entry->physin =nf_bridge_get_physindev (skb, entry->state.net); entry->physout =nf_bridge_get_physoutdev (skb); }else { entry->physin =NULL ;
net/netfilter/xt_physdev.c +1 -1
@@ -59,7 +59,7 @@ physdev_mt(const struct sk_buff *skb, struct xt_action_param *par) (!!outdev ^ !(info->invert & XT_PHYSDEV_OP_BRIDGED)))return false; - physdev =nf_bridge_get_physindev (skb); + physdev =nf_bridge_get_physindev (skb,xt_net (par)); indev = physdev ? physdev->name :NULL ; if ((info->bitmask & XT_PHYSDEV_OP_ISIN &&
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH v2 8/13 netfilter: bridge: replace physindev with physinif in nf_bridge_info
In reply to Pablo Neira AyusoFrom: Pavel Tikhomirov <[email protected]>
An skb can be added to a neigh->arp_queue while waiting for an arp reply. Where original skb's skb->dev can be different to neigh's neigh->dev. For instance in case of bridging dnated skb from one veth to another, the skb would be added to a neigh->arp_queue of the bridge.
As skb->dev can be reset back to nf_bridge->physindev and used, and as there is no explicit mechanism that prevents this physindev from been freed under us (for instance neigh_flush_dev doesn't cleanup skbs from different device's neigh queue) we can crash on e.g. this stack:
arp_process
neigh_update
skb = __skb_dequeue(&neigh->arp_queue)
neigh_resolve_output(..., skb)
...
br_nf_dev_xmit
br_nf_pre_routing_finish_bridge_slow
skb->dev = nf_bridge->physindev
br_handle_frame_finishLet's use plain ifindex instead of net_device link. To peek into the original net_device we will use dev_get_by_index_rcu(). Thus either we get device and are safe to use it or we don't get it and drop skb.
--- include/linux/netfilter_bridge.h | 4 +-- include/linux/skbuff.h | 2 +- net/bridge/br_netfilter_hooks.c | 42 +++++++++++++++++++++++------ net/bridge/br_netfilter_ipv6.c | 14 +++++++--- net/ipv4/netfilter/nf_reject_ipv4.c | 9 ++++--- net/ipv6/netfilter/nf_reject_ipv6.c | 11 +++++--- 6 files changed, 61 insertions(+), 21 deletions(-)
include/linux/netfilter_bridge.h +2 -2
@@ -42,7 +42,7 @@ static inline int nf_bridge_get_physinif(const struct sk_buff *skb)if (!nf_bridge)return 0 ; -return nf_bridge->physindev ? nf_bridge->physindev->ifindex :0 ; +return nf_bridge->physinif; }static inline int nf_bridge_get_physoutif (const struct sk_buff *skb)
@@ -60,7 +60,7 @@ nf_bridge_get_physindev(const struct sk_buff *skb, struct net *net) {const struct nf_bridge_info *nf_bridge =nf_bridge_info_get (skb); -return nf_bridge ? nf_bridge->physindev :NULL ; +return nf_bridge ?dev_get_by_index_rcu (net, nf_bridge->physinif) :NULL ; } static inline struct net_device *
include/linux/skbuff.h +1 -1
@@ -295,7 +295,7 @@ struct nf_bridge_info { u8 bridged_dnat:1; u8 sabotage_in_done:1;__u16 frag_max_size; -struct net_device *physindev; +int physinif;/* always valid & non-NULL from FORWARD on, for physdev match */ struct net_device *physoutdev;
net/bridge/br_netfilter_hooks.c +34 -8
102 lines not on this page · raw message
net/bridge/br_netfilter_ipv6.c +10 -4
@@ -102,9 +102,15 @@ static int br_nf_pre_routing_finish_ipv6(struct net *net, struct sock *sk, struc {struct nf_bridge_info *nf_bridge =nf_bridge_info_get (skb);struct rtable *rt; -struct net_device *dev = skb->dev; +struct net_device *dev = skb->dev, *br_indev;const struct nf_ipv6_ops *v6ops =nf_get_ipv6_ops (); + br_indev =nf_bridge_get_physindev (skb, net); +if (!br_indev) { +kfree_skb (skb); +return 0 ; + } + nf_bridge->frag_max_size =IP6CB (skb)->frag_max_size;if (nf_bridge->pkt_otherhost) {
@@ -122,7 +128,7 @@ static int br_nf_pre_routing_finish_ipv6(struct net *net, struct sock *sk, struc }if (skb_dst (skb)->dev == dev) { - skb->dev = nf_bridge->physindev; + skb->dev = br_indev;nf_bridge_update_protocol (skb);nf_bridge_push_encap_header (skb); br_nf_hook_thresh(NF_BR_PRE_ROUTING,
@@ -133,7 +139,7 @@ static int br_nf_pre_routing_finish_ipv6(struct net *net, struct sock *sk, strucether_addr_copy (eth_hdr (skb)->h_dest, dev->dev_addr); skb->pkt_type =PACKET_HOST ; }else { - rt =bridge_parent_rtable (nf_bridge->physindev); + rt =bridge_parent_rtable (br_indev);if (!rt) {kfree_skb (skb);return 0 ;
@@ -142,7 +148,7 @@ static int br_nf_pre_routing_finish_ipv6(struct net *net, struct sock *sk, strucskb_dst_set_noref (skb, &rt->dst); } - skb->dev = nf_bridge->physindev; + skb->dev = br_indev;nf_bridge_update_protocol (skb);nf_bridge_push_encap_header (skb); br_nf_hook_thresh(NF_BR_PRE_ROUTING, net, sk, skb,
net/ipv4/netfilter/nf_reject_ipv4.c +6 -3
@@ -239,7 +239,6 @@ static int nf_reject_fill_skb_dst(struct sk_buff *skb_in)void nf_send_reset (struct net *net,struct sock *sk,struct sk_buff *oldskb,int hook) { -struct net_device *br_indev__maybe_unused ;struct sk_buff *nskb;struct iphdr *niph;const struct tcphdr *oth;
@@ -289,9 +288,13 @@ void nf_send_reset(struct net *net, struct sock *sk, struct sk_buff *oldskb,* build the eth header using the original destination's MAC as the * source, and send the RST packet directly. */ - br_indev =nf_bridge_get_physindev (oldskb, net); -if (br_indev) { +if (nf_bridge_info_exists (oldskb)) {struct ethhdr *oeth =eth_hdr (oldskb); +struct net_device *br_indev; + + br_indev =nf_bridge_get_physindev (oldskb, net); +if (!br_indev) + goto free_nskb; nskb->dev = br_indev; niph->tot_len =htons (nskb->len);
net/ipv6/netfilter/nf_reject_ipv6.c +8 -3
@@ -278,7 +278,6 @@ static int nf_reject6_fill_skb_dst(struct sk_buff *skb_in)void nf_send_reset6 (struct net *net,struct sock *sk,struct sk_buff *oldskb,int hook) { -struct net_device *br_indev__maybe_unused ;struct sk_buff *nskb;struct tcphdr _otcph;const struct tcphdr *otcph;
@@ -354,9 +353,15 @@ void nf_send_reset6(struct net *net, struct sock *sk, struct sk_buff *oldskb,* build the eth header using the original destination's MAC as the * source, and send the RST packet directly. */ - br_indev =nf_bridge_get_physindev (oldskb, net); -if (br_indev) { +if (nf_bridge_info_exists (oldskb)) {struct ethhdr *oeth =eth_hdr (oldskb); +struct net_device *br_indev; + + br_indev =nf_bridge_get_physindev (oldskb, net); +if (!br_indev) { +kfree_skb (nskb); +return ; + } nskb->dev = br_indev; nskb->protocol =htons (ETH_P_IPV6 );
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH v2 9/13 netfilter: nf_tables: check if catch-all set element is active in next generation
In reply to Pablo Neira AyusoWhen deactivating the catch-all set element, check the state in the next generation that represents this transaction.
This bug uncovered after the recent removal of the element busy mark a2dd0233cbc4 ("netfilter: nf_tables: remove busy mark and gc batch API").
--- net/netfilter/nf_tables_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +1 -1
@@ -6578,7 +6578,7 @@ static int nft_setelem_catchall_deactivate(const struct net *net,list_for_each_entry (catchall, &set->catchall_list, list) { ext =nft_set_elem_ext (set, catchall->elem); -if (!nft_is_active (net, ext)) +if (!nft_is_active_next (net, ext))continue ;kfree (elem->priv);
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH v2 10/13 netfilter: nf_tables: do not allow mismatch field size and set key length
In reply to Pablo Neira AyusoThe set description provides the size of each field in the set whose sum should not mismatch the set key length, bail out otherwise.
I did not manage to crash nft_set_pipapo with mismatch fields and set key length so far, but this is UB which must be disallowed.
--- net/netfilter/nf_tables_api.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +5 -1
@@ -4813,8 +4813,8 @@ static int nft_set_desc_concat_parse(const struct nlattr *attr,static int nft_set_desc_concat (struct nft_set_desc *desc,const struct nlattr *nla) { +u32 num_regs =0 , key_num_regs =0 ;struct nlattr *attr; -u32 num_regs =0 ;int rem, err, i;nla_for_each_nested (attr, nla, rem) {
@@ -4829,6 +4829,10 @@ static int nft_set_desc_concat(struct nft_set_desc *desc,for (i =0 ; i < desc->field_count; i++) num_regs +=DIV_ROUND_UP (desc->field_len[i],sizeof (u32)); + key_num_regs =DIV_ROUND_UP (desc->klen,sizeof (u32)); +if (key_num_regs != num_regs) +return -EINVAL ; +if (num_regs >NFT_REG32_COUNT )return -E2BIG ;
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH v2 11/13 netfilter: nf_tables: skip dead set elements in netlink dump
In reply to Pablo Neira AyusoDelete from packet path relies on the garbage collector to purge elements with NFT_SET_ELEM_DEAD_BIT on.
Skip these dead elements from nf_tables_dump_setelem() path, I very rarely see tests/shell/testcases/maps/typeof_maps_add_delete reports [DUMP FAILED] showing a mismatch in the expected output with an element that should not be there.
If the netlink dump happens before GC worker run, it might show dead elements in the ruleset listing.
nft_rhash_get() already skips dead elements in nft_rhash_cmp(), therefore, it already does not show the element when getting a single element via netlink control plane.
--- net/netfilter/nf_tables_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +1 -1
@@ -5718,7 +5718,7 @@ static int nf_tables_dump_setelem(const struct nft_ctx *ctx,const struct nft_set_ext *ext =nft_set_elem_ext (set, elem_priv);struct nft_set_dump_args *args; -if (nft_set_elem_expired (ext)) +if (nft_set_elem_expired (ext) ||nft_set_elem_is_dead (ext))return 0 ; args = container_of(iter, struct nft_set_dump_args, iter);
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH v2 12/13 netfilter: nf_tables: reject NFT_SET_CONCAT with not field length description
In reply to Pablo Neira AyusoIt is still possible to set on the NFT_SET_CONCAT flag by specifying a set size and no field description, report EINVAL in such case.
--- net/netfilter/nf_tables_api.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +5 -1
@@ -5070,8 +5070,12 @@ static int nf_tables_newset(struct sk_buff *skb, const struct nfnl_info *info,if (err <0 )return err; -if (desc.field_count >1 && !(flags &NFT_SET_CONCAT )) +if (desc.field_count >1 ) { +if (!(flags &NFT_SET_CONCAT )) +return -EINVAL ; + }else if (flags &NFT_SET_CONCAT ) {return -EINVAL ; + } }else if (flags &NFT_SET_CONCAT ) {return -EINVAL ; }
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH v2 13/13 ipvs: avoid stat macros calls from preemptible context
In reply to Pablo Neira AyusoFrom: Fedor Pchelkin <[email protected]>
Inside decrement_ttl() upon discovering that the packet ttl has exceeded, __IP_INC_STATS and __IP6_INC_STATS macros can be called from preemptible context having the following backtrace:
check_preemption_disabled: 48 callbacks suppressed
BUG: using __this_cpu_add() in preemptible [00000000] code: curl/1177 caller is decrement_ttl+0x217/0x830 CPU: 5 PID: 1177 Comm: curl Not tainted 6.7.0+ #34 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0xbd/0xe0 check_preemption_disabled+0xd1/0xe0 decrement_ttl+0x217/0x830 __ip_vs_get_out_rt+0x4e0/0x1ef0 ip_vs_nat_xmit+0x205/0xcd0 ip_vs_in_hook+0x9b1/0x26a0 nf_hook_slow+0xc2/0x210 nf_hook+0x1fb/0x770 __ip_local_out+0x33b/0x640 ip_local_out+0x2a/0x490 __ip_queue_xmit+0x990/0x1d10 __tcp_transmit_skb+0x288b/0x3d10 tcp_connect+0x3466/0x5180 tcp_v4_connect+0x1535/0x1bb0 __inet_stream_connect+0x40d/0x1040 inet_stream_connect+0x57/0xa0 __sys_connect_file+0x162/0x1a0 __sys_connect+0x137/0x160 __x64_sys_connect+0x72/0xb0 do_syscall_64+0x6f/0x140 entry_SYSCALL_64_after_hwframe+0x6e/0x76 RIP: 0033:0x7fe6dbbc34e0
Use the corresponding preemption-aware variants: IP_INC_STATS and IP6_INC_STATS.
Found by Linux Verification Center (linuxtesting.org).
--- net/netfilter/ipvs/ip_vs_xmit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/ipvs/ip_vs_xmit.c +2 -2
@@ -271,7 +271,7 @@ static inline bool decrement_ttl(struct netns_ipvs *ipvs, skb->dev = dst->dev;icmpv6_send (skb,ICMPV6_TIME_EXCEED ,ICMPV6_EXC_HOPLIMIT ,0 ); -__IP6_INC_STATS (net, idev,IPSTATS_MIB_INHDRERRORS ); +IP6_INC_STATS (net, idev,IPSTATS_MIB_INHDRERRORS );return false; }
@@ -286,7 +286,7 @@ static inline bool decrement_ttl(struct netns_ipvs *ipvs, {if (ip_hdr (skb)->ttl <=1 ) {/* Tell the sender its packet died... */ -__IP_INC_STATS (net,IPSTATS_MIB_INHDRERRORS ); +IP_INC_STATS (net,IPSTATS_MIB_INHDRERRORS );icmp_send (skb,ICMP_TIME_EXCEEDED ,ICMP_EXC_TTL ,0 );return false; }
Signature · 1 line
2.30.2