Netfilter fixes for net
Subsystems (4)
Pablo Neira Ayuso
maintainercover Netfilter fixes for net
Hi,
The following patchset contains Netfilter fixes for net:
Patches #1 and #2 add missing rcu read side lock when iterating over expression and object type list which could race with module removal.
Patch #3 prevents promisc packet from visiting the bridge/input hook
to amend a recent fix to address conntrack confirmation race in br_netfilter and nf_conntrack_bridge.
Patch #4 adds and uses iterate decorator type to fetch the current
pipapo set backend datastructure view when netlink dumps the set elements.
Patch #5 fixes removal of duplicate elements in the pipapo set backend.
Patch #6 flowtable validates pppoe header before accessing it.
Patch #7 fixes flowtable datapath for pppoe packets, otherwise lookup
fails and pppoe packets follow classic path.
Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git nf-24-04-11
Thanks.
----------------------------------------------------------------
The following changes since commit 19fa4f2a85d777a8052e869c1b892a2f7556569d:
r8169: fix LED-related deadlock on module removal (2024-04-10 10:44:29 +0100)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git tags/nf-24-04-11
for you to fetch changes up to 6db5dc7b351b9569940cd1cf445e237c42cd6d27:
netfilter: flowtable: incorrect pppoe tuple (2024-04-11 12:14:10 +0200)
----------------------------------------------------------------
netfilter pull request 24-04-11
----------------------------------------------------------------
Florian Westphal (1):
netfilter: nft_set_pipapo: do not free live element
Pablo Neira Ayuso (4):
netfilter: br_netfilter: skip conntrack input hook for promisc packets
netfilter: nft_set_pipapo: walk over current view on netlink dump
netfilter: flowtable: validate pppoe header
netfilter: flowtable: incorrect pppoe tuple
Ziyang Xuan (2):
netfilter: nf_tables: Fix potential data-race in __nft_expr_type_get()
netfilter: nf_tables: Fix potential data-race in __nft_obj_type_get()
include/net/netfilter/nf_flow_table.h | 12 +++++++++++- include/net/netfilter/nf_tables.h | 14 ++++++++++++++ net/bridge/br_input.c | 15 +++++++++++---- net/bridge/br_netfilter_hooks.c | 6 ++++++ net/bridge/br_private.h | 1 + net/bridge/netfilter/nf_conntrack_bridge.c | 14 ++++++++++---- net/netfilter/nf_flow_table_inet.c | 3 ++- net/netfilter/nf_flow_table_ip.c | 10 ++++++---- net/netfilter/nf_tables_api.c | 22 ++++++++++++++++++---- net/netfilter/nft_set_pipapo.c | 19 ++++++++++++------- 10 files changed, 91 insertions(+), 25 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 1/7 netfilter: nf_tables: Fix potential data-race in __nft_expr_type_get()
From: Ziyang Xuan <[email protected]>
nft_unregister_expr() can concurrent with __nft_expr_type_get(), and there is not any protection when iterate over nf_tables_expressions list in __nft_expr_type_get(). Therefore, there is potential data-race of nf_tables_expressions list entry.
Use list_for_each_entry_rcu() to iterate over nf_tables_expressions list in __nft_expr_type_get(), and use rcu_read_lock() in the caller nft_expr_type_get() to protect the entire type query process.
--- net/netfilter/nf_tables_api.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
net/netfilter/nf_tables_api.c +6 -2
@@ -3060,7 +3060,7 @@ static const struct nft_expr_type *__nft_expr_type_get(u8 family, {const struct nft_expr_type *type, *candidate =NULL ; -list_for_each_entry (type, &nf_tables_expressions, list) { +list_for_each_entry_rcu (type, &nf_tables_expressions, list) {if (!nla_strcmp (nla, type->name)) {if (!type->family && !candidate) candidate = type;
@@ -3092,9 +3092,13 @@ static const struct nft_expr_type *nft_expr_type_get(struct net *net,if (nla ==NULL )return ERR_PTR (-EINVAL ); +rcu_read_lock (); type =__nft_expr_type_get (family, nla); -if (type !=NULL &&try_module_get (type->owner)) +if (type !=NULL &&try_module_get (type->owner)) { +rcu_read_unlock ();return type; + } +rcu_read_unlock ();lockdep_nfnl_nft_mutex_not_held ();#ifdef CONFIG_MODULES
Signature · 1 line
2.30.2
Re: [PATCH net 1/7] netfilter: nf_tables: Fix potential data-race in __nft_expr_type_get()
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, 11 Apr 2024 13:28:54 +0200 you wrote:
From: Ziyang Xuan <[email protected]>
nft_unregister_expr()can concurrent with__nft_expr_type_get(), and there is not any protection when iterate overnf_tables_expressionslist in__nft_expr_type_get(). Therefore, there is potential data-race ofnf_tables_expressionslist entry.[...]
Here is the summary with links:
- [net,1/7] netfilter: nf_tables: Fix potential data-race in __nft_expr_type_get()
https://git.kernel.org/netdev/net/c/f969eb84ce48 - [net,2/7] netfilter: nf_tables: Fix potential data-race in __nft_obj_type_get() https://git.kernel.org/netdev/net/c/d78d867dcea6 - [net,3/7] netfilter: br_netfilter: skip conntrack input hook for promisc packets https://git.kernel.org/netdev/net/c/751de2012eaf - [net,4/7] netfilter: nft_set_pipapo: walk over current view on netlink dump https://git.kernel.org/netdev/net/c/29b359cf6d95 - [net,5/7] netfilter: nft_set_pipapo: do not free live element https://git.kernel.org/netdev/net/c/3cfc9ec039af - [net,6/7] netfilter: flowtable: validate pppoe header https://git.kernel.org/netdev/net/c/87b3593bed18 - [net,7/7] netfilter: flowtable: incorrect pppoe tuple https://git.kernel.org/netdev/net/c/6db5dc7b351b
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 2/7 netfilter: nf_tables: Fix potential data-race in __nft_obj_type_get()
In reply to Pablo Neira AyusoFrom: Ziyang Xuan <[email protected]>
nft_unregister_obj() can concurrent with __nft_obj_type_get(), and there is not any protection when iterate over nf_tables_objects list in __nft_obj_type_get(). Therefore, there is potential data-race of nf_tables_objects list entry.
Use list_for_each_entry_rcu() to iterate over nf_tables_objects list in __nft_obj_type_get(), and use rcu_read_lock() in the caller nft_obj_type_get() to protect the entire type query process.
--- net/netfilter/nf_tables_api.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
net/netfilter/nf_tables_api.c +6 -2
@@ -7611,7 +7611,7 @@ static const struct nft_object_type *__nft_obj_type_get(u32 objtype, u8 family) {const struct nft_object_type *type; -list_for_each_entry (type, &nf_tables_objects, list) { +list_for_each_entry_rcu (type, &nf_tables_objects, list) {if (type->family !=NFPROTO_UNSPEC && type->family != family)continue ;
@@ -7627,9 +7627,13 @@ nft_obj_type_get(struct net *net, u32 objtype, u8 family) {const struct nft_object_type *type; +rcu_read_lock (); type =__nft_obj_type_get (objtype, family); -if (type !=NULL &&try_module_get (type->owner)) +if (type !=NULL &&try_module_get (type->owner)) { +rcu_read_unlock ();return type; + } +rcu_read_unlock ();lockdep_nfnl_nft_mutex_not_held ();#ifdef CONFIG_MODULES
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 3/7 netfilter: br_netfilter: skip conntrack input hook for promisc packets
In reply to Pablo Neira AyusoFor historical reasons, when bridge device is in promisc mode, packets that are directed to the taps follow bridge input hook path. This patch adds a workaround to reset conntrack for these packets.
Jianbo Liu reports warning splats in their test infrastructure where cloned packets reach the br_netfilter input hook to confirm the conntrack object.
Scratch one bit from BR_INPUT_SKB_CB to annotate that this packet has reached the input hook because it is passed up to the bridge device to reach the taps.
[ 57.571874] WARNING: CPU: 1 PID: 0 at net/bridge/br_netfilter_hooks.c:616 br_nf_local_in+0x157/0x180 [br_netfilter] [ 57.572749] Modules linked in: xt_MASQUERADE nf_conntrack_netlink nfnetlink iptable_nat xt_addrtype xt_conntrack nf_nat br_netfilter rpcsec_gss_krb5 auth_rpcgss oid_registry overlay rpcrdma rdma_ucm ib_iser libiscsi scsi_transport_isc si ib_umad rdma_cm ib_ipoib iw_cm ib_cm mlx5_ib ib_uverbs ib_core mlx5ctl mlx5_core [ 57.575158] CPU: 1 PID: 0 Comm: swapper/1 Not tainted 6.8.0+ #19 [ 57.575700] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.13.0-0-gf21b5a4aeb02-prebuilt.qemu.org 04/01/2014 [ 57.576662] RIP: 0010:br_nf_local_in+0x157/0x180 [br_netfilter] [ 57.577195] Code: fe ff ff 41 bd 04 00 00 00 be 04 00 00 00 e9 4a ff ff ff be 04 00 00 00 48 89 ef e8 f3 a9 3c e1 66 83 ad b4 00 00 00 04 eb 91 <0f> 0b e9 f1 fe ff ff 0f 0b e9 df fe ff ff 48 89 df e8 b3 53 47 e1 [ 57.578722] RSP: 0018:ffff88885f845a08 EFLAGS: 00010202 [ 57.579207] RAX: 0000000000000002 RBX: ffff88812dfe8000 RCX: 0000000000000000 [ 57.579830] RDX: ffff88885f845a60 RSI: ffff8881022dc300 RDI: 0000000000000000 [ 57.580454] RBP: ffff88885f845a60 R08: 0000000000000001 R09: 0000000000000003 [ 57.581076] R10: 00000000ffff1300 R11: 0000000000000002 R12: 0000000000000000 [ 57.581695] R13: ffff8881047ffe00 R14: ffff888108dbee00 R15: ffff88814519b800 [ 57.582313] FS: 0000000000000000(0000) GS:ffff88885f840000(0000) knlGS:0000000000000000 [ 57.583040] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 57.583564] CR2: 000000c4206aa000 CR3: 0000000103847001 CR4: 0000000000370eb0 [ 57.584194] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 57.584820] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [ 57.585440] Call Trace: [ 57.585721] <IRQ> [ 57.585976] ? __warn+0x7d/0x130 [ 57.586323] ? br_nf_local_in+0x157/0x180 [br_netfilter] [ 57.586811] ? report_bug+0xf1/0x1c0 [ 57.587177] ? handle_bug+0x3f/0x70 [ 57.587539] ? exc_invalid_op+0x13/0x60 [ 57.587929] ? asm_exc_invalid_op+0x16/0x20 [ 57.588336] ? br_nf_local_in+0x157/0x180 [br_netfilter] [ 57.588825] nf_hook_slow+0x3d/0xd0 [ 57.589188] ? br_handle_vlan+0x4b/0x110 [ 57.589579] br_pass_frame_up+0xfc/0x150 [ 57.589970] ? br_port_flags_change+0x40/0x40 [ 57.590396] br_handle_frame_finish+0x346/0x5e0 [ 57.590837] ? ipt_do_table+0x32e/0x430 [ 57.591221] ? br_handle_local_finish+0x20/0x20 [ 57.591656] br_nf_hook_thresh+0x4b/0xf0 [br_netfilter] [ 57.592286] ? br_handle_local_finish+0x20/0x20 [ 57.592802] br_nf_pre_routing_finish+0x178/0x480 [br_netfilter] [ 57.593348] ? br_handle_local_finish+0x20/0x20 [ 57.593782] ? nf_nat_ipv4_pre_routing+0x25/0x60 [nf_nat] [ 57.594279] br_nf_pre_routing+0x24c/0x550 [br_netfilter] [ 57.594780] ? br_nf_hook_thresh+0xf0/0xf0 [br_netfilter] [ 57.595280] br_handle_frame+0x1f3/0x3d0 [ 57.595676] ? br_handle_local_finish+0x20/0x20 [ 57.596118] ? br_handle_frame_finish+0x5e0/0x5e0 [ 57.596566] __netif_receive_skb_core+0x25b/0xfc0 [ 57.597017] ? __napi_build_skb+0x37/0x40 [ 57.597418] __netif_receive_skb_list_core+0xfb/0x220
--- net/bridge/br_input.c | 15 +++++++++++---- net/bridge/br_netfilter_hooks.c | 6 ++++++ net/bridge/br_private.h | 1 + net/bridge/netfilter/nf_conntrack_bridge.c | 14 ++++++++++---- 4 files changed, 28 insertions(+), 8 deletions(-)
net/bridge/br_input.c +11 -4
@@ -30,7 +30,7 @@ br_netif_receive_skb(struct net *net, struct sock *sk, struct sk_buff *skb)return netif_receive_skb (skb); } -static int br_pass_frame_up (struct sk_buff *skb) +static int br_pass_frame_up (struct sk_buff *skb,bool promisc) {struct net_device *indev, *brdev =BR_INPUT_SKB_CB (skb)->brdev;struct net_bridge *br =netdev_priv (brdev);
@@ -65,6 +65,8 @@ static int br_pass_frame_up(struct sk_buff *skb)br_multicast_count (br,NULL , skb,br_multicast_igmp_type (skb),BR_MCAST_DIR_TX ); +BR_INPUT_SKB_CB (skb)->promisc = promisc; +return NF_HOOK (NFPROTO_BRIDGE ,NF_BR_LOCAL_IN ,dev_net (indev),NULL , skb, indev,NULL , br_netif_receive_skb);
@@ -82,6 +84,7 @@ int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skbstruct net_bridge_mcast *brmctx;struct net_bridge_vlan *vlan;struct net_bridge *br; +bool promisc;u16 vid =0 ;u8 state;
@@ -137,7 +140,9 @@ int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skbif (p->flags &BR_LEARNING )br_fdb_update (br, p,eth_hdr (skb)->h_source, vid,0 ); - local_rcv = !!(br->dev->flags &IFF_PROMISC ); + promisc = !!(br->dev->flags &IFF_PROMISC ); + local_rcv = promisc; +if (is_multicast_ether_addr (eth_hdr (skb)->h_dest)) {/* by definition the broadcast is also a multicast address */ if (is_broadcast_ether_addr (eth_hdr (skb)->h_dest)) {
@@ -200,7 +205,7 @@ int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skbunsigned long now = jiffies;if (test_bit (BR_FDB_LOCAL , &dst->flags)) -return br_pass_frame_up (skb); +return br_pass_frame_up (skb, false);if (now != dst->used) dst->used = now;
@@ -213,7 +218,7 @@ int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb }if (local_rcv) -return br_pass_frame_up (skb); +return br_pass_frame_up (skb, promisc); out:return 0 ;
@@ -386,6 +391,8 @@ static rx_handler_result_t br_handle_frame(struct sk_buff **pskb) goto forward; } +BR_INPUT_SKB_CB (skb)->promisc = false; +/* The else clause should be hit when nf_hook(): * - returns < 0 (drop/error) * - returns = 0 (stolen/nf_queue)
net/bridge/br_netfilter_hooks.c +6 -0
@@ -600,11 +600,17 @@ static unsigned int br_nf_local_in(void *priv,struct sk_buff *skb, const struct nf_hook_state *state) { + bool promisc = BR_INPUT_SKB_CB(skb)->promisc;struct nf_conntrack *nfct =skb_nfct (skb);const struct nf_ct_hook *ct_hook;struct nf_conn *ct;int ret; +if (promisc) { +nf_reset_ct (skb); +return NF_ACCEPT ; + } +if (!nfct || skb->pkt_type ==PACKET_HOST )return NF_ACCEPT ;
net/bridge/br_private.h +1 -0
@@ -589,6 +589,7 @@ struct br_input_skb_cb {#endif u8 proxyarp_replied:1; u8 src_port_isolated:1; + u8 promisc:1;#ifdef CONFIG_BRIDGE_VLAN_FILTERING u8 vlan_filtered:1;#endif
net/bridge/netfilter/nf_conntrack_bridge.c +10 -4
@@ -294,18 +294,24 @@ static unsigned int nf_ct_bridge_pre(void *priv, struct sk_buff *skb,static unsigned int nf_ct_bridge_in (void *priv,struct sk_buff *skb,const struct nf_hook_state *state) { -enum ip_conntrack_info ctinfo; +bool promisc =BR_INPUT_SKB_CB (skb)->promisc; +struct nf_conntrack *nfct =skb_nfct (skb);struct nf_conn *ct; -if (skb->pkt_type ==PACKET_HOST ) +if (promisc) { +nf_reset_ct (skb); +return NF_ACCEPT ; + } + +if (!nfct || skb->pkt_type ==PACKET_HOST )return NF_ACCEPT ;/* nf_conntrack_confirm() cannot handle concurrent clones, * this happens for broad/multicast frames with e.g. macvlan on top * of the bridge device. */ - ct =nf_ct_get (skb, &ctinfo); -if (!ct ||nf_ct_is_confirmed (ct) ||nf_ct_is_template (ct)) + ct = container_of(nfct, struct nf_conn, ct_general); +if (nf_ct_is_confirmed (ct) ||nf_ct_is_template (ct))return NF_ACCEPT ;/* let inet prerouting call conntrack again */
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 4/7 netfilter: nft_set_pipapo: walk over current view on netlink dump
In reply to Pablo Neira AyusoThe generation mask can be updated while netlink dump is in progress. The pipapo set backend walk iterator cannot rely on it to infer what view of the datastructure is to be used. Add notation to specify if user wants to read/update the set.
Based on patch from Florian Westphal.
--- include/net/netfilter/nf_tables.h | 14 ++++++++++++++ net/netfilter/nf_tables_api.c | 6 ++++++ net/netfilter/nft_set_pipapo.c | 5 +++-- 3 files changed, 23 insertions(+), 2 deletions(-)
include/net/netfilter/nf_tables.h +14 -0
@@ -307,9 +307,23 @@ static inline void *nft_elem_priv_cast(const struct nft_elem_priv *priv)return (void *)priv; } + +/** +* enum nft_iter_type - nftables set iterator type +* +* @NFT_ITER_READ: read-only iteration over set elements +* @NFT_ITER_UPDATE: iteration under mutex to update set element state +*/ +enum nft_iter_type { +NFT_ITER_UNSPEC , +NFT_ITER_READ , +NFT_ITER_UPDATE , +}; +struct nft_set ;struct nft_set_iter {u8 genmask; +enum nft_iter_type type:8 ;unsigned int count;unsigned int skip;int err;
net/netfilter/nf_tables_api.c +6 -0
@@ -626,6 +626,7 @@ static void nft_map_deactivate(const struct nft_ctx *ctx, struct nft_set *set) {struct nft_set_iter iter = { .genmask =nft_genmask_next (ctx->net), + .type =NFT_ITER_UPDATE , .fn = nft_mapelem_deactivate, };
@@ -5445,6 +5446,7 @@ int nf_tables_bind_set(const struct nft_ctx *ctx, struct nft_set *set, } iter.genmask =nft_genmask_next (ctx->net); + iter.type =NFT_ITER_UPDATE ; iter.skip =0 ; iter.count =0 ; iter.err =0 ;
@@ -5518,6 +5520,7 @@ static void nft_map_activate(const struct nft_ctx *ctx, struct nft_set *set) {struct nft_set_iter iter = { .genmask =nft_genmask_next (ctx->net), + .type =NFT_ITER_UPDATE , .fn = nft_mapelem_activate, };
@@ -5892,6 +5895,7 @@ static int nf_tables_dump_set(struct sk_buff *skb, struct netlink_callback *cb) args.skb = skb; args.reset = dump_ctx->reset; args.iter.genmask =nft_genmask_cur (net); + args.iter.type =NFT_ITER_READ ; args.iter.skip = cb->args[0 ]; args.iter.count =0 ; args.iter.err =0 ;
@@ -7376,6 +7380,7 @@ static int nft_set_flush(struct nft_ctx *ctx, struct nft_set *set, u8 genmask) {struct nft_set_iter iter = { .genmask = genmask, + .type =NFT_ITER_UPDATE , .fn = nft_setelem_flush, };
@@ -10879,6 +10884,7 @@ static int nf_tables_check_loops(const struct nft_ctx *ctx,continue ; iter.genmask =nft_genmask_next (ctx->net); + iter.type =NFT_ITER_UPDATE ; iter.skip =0 ; iter.count =0 ; iter.err =0 ;
net/netfilter/nft_set_pipapo.c +3 -2
@@ -2115,13 +2115,14 @@ static void nft_pipapo_walk(const struct nft_ctx *ctx, struct nft_set *set, struct nft_set_iter *iter) {struct nft_pipapo *priv =nft_set_priv (set); -struct net *net =read_pnet (&set->net);const struct nft_pipapo_match *m;const struct nft_pipapo_field *f;unsigned int i, r; +WARN_ON_ONCE (iter->type ==NFT_ITER_UNSPEC ); +rcu_read_lock (); -if (iter->genmask ==nft_genmask_cur (net)) +if (iter->type ==NFT_ITER_READ ) m =rcu_dereference (priv->match);else m = priv->clone;
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 5/7 netfilter: nft_set_pipapo: do not free live element
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Pablo reports a crash with large batches of elements with a back-to-back add/remove pattern. Quoting Pablo:
add_elem("00000000") timeout 100 ms
...
add_elem("0000000X") timeout 100 ms
del_elem("0000000X") <---------------- delete one that was just added
...
add_elem("00005000") timeout 100 ms
1) nft_pipapo_remove() removes element 0000000X
Then, KASAN shows a splat.
Looking at the remove function there is a chance that we will drop a rule that maps to a non-deactivated element.
Removal happens in two steps, first we do a lookup for key k and return the to-be-removed element and mark it as inactive in the next generation. Then, in a second step, the element gets removed from the set/map.
The _remove function does not work correctly if we have more than one element that share the same key.
This can happen if we insert an element into a set when the set already holds an element with same key, but the element mapping to the existing key has timed out or is not active in the next generation.
In such case its possible that removal will unmap the wrong element. If this happens, we will leak the non-deactivated element, it becomes unreachable.
The element that got deactivated (and will be freed later) will remain reachable in the set data structure, this can result in a crash when such an element is retrieved during lookup (stale pointer).
Add a check that the fully matching key does in fact map to the element that we have marked as inactive in the deactivation step.
If not, we need to continue searching.
Add a bug/warn trap at the end of the function as well, the remove function must not ever be called with an invisible/unreachable/non-existent element.
v2: avoid uneeded temporary variable (Stefano)
--- net/netfilter/nft_set_pipapo.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
net/netfilter/nft_set_pipapo.c +9 -5
@@ -2077,6 +2077,8 @@ static void nft_pipapo_remove(const struct net *net, const struct nft_set *set, rules_fx = rules_f0;nft_pipapo_for_each_field (f, i, m) { +bool last = i == m->field_count -1 ; +if (!pipapo_match_field (f, start, rules_fx, match_start, match_end))break ;
@@ -2089,16 +2091,18 @@ static void nft_pipapo_remove(const struct net *net, const struct nft_set *set, match_start +=NFT_PIPAPO_GROUPS_PADDED_SIZE (f); match_end +=NFT_PIPAPO_GROUPS_PADDED_SIZE (f); - } -if (i == m->field_count) { - priv->dirty = true; -pipapo_drop (m, rulemap); -return ; +if (last && f->mt[rulemap[i].to].e == e) { + priv->dirty = true; +pipapo_drop (m, rulemap); +return ; + } } first_rule += rules_f0; } + +WARN_ON_ONCE (1 );/* elem_priv not found */ }/**
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 6/7 netfilter: flowtable: validate pppoe header
In reply to Pablo Neira AyusoEnsure there is sufficient room to access the protocol field of the PPPoe header. Validate it once before the flowtable lookup, then use a helper function to access protocol field.
--- include/net/netfilter/nf_flow_table.h | 12 +++++++++++- net/netfilter/nf_flow_table_inet.c | 3 ++- net/netfilter/nf_flow_table_ip.c | 8 +++++--- 3 files changed, 18 insertions(+), 5 deletions(-)
include/net/netfilter/nf_flow_table.h +11 -1
@@ -336,7 +336,7 @@ int nf_flow_rule_route_ipv6(struct net *net, struct flow_offload *flow,int nf_flow_table_offload_init (void );void nf_flow_table_offload_exit (void ); -static inline __be16 nf_flow_pppoe_proto (const struct sk_buff *skb) +static inline __be16 __nf_flow_pppoe_proto (const struct sk_buff *skb) {__be16 proto;
@@ -352,6 +352,16 @@ static inline __be16 nf_flow_pppoe_proto(const struct sk_buff *skb)return 0 ; } +static inline bool nf_flow_pppoe_proto (struct sk_buff *skb,__be16 *inner_proto) +{ +if (!pskb_may_pull (skb,PPPOE_SES_HLEN )) +return false; + + *inner_proto =__nf_flow_pppoe_proto (skb); + +return true; +} +#define NF_FLOW_TABLE_STAT_INC (net, count) __this_cpu_inc((net)->ft.stat->count)#define NF_FLOW_TABLE_STAT_DEC (net, count) __this_cpu_dec((net)->ft.stat->count)#define NF_FLOW_TABLE_STAT_INC_ATOMIC (net, count) \
net/netfilter/nf_flow_table_inet.c +2 -1
@@ -21,7 +21,8 @@ nf_flow_offload_inet_hook(void *priv, struct sk_buff *skb, proto = veth->h_vlan_encapsulated_proto;break ;case htons (ETH_P_PPP_SES ): - proto =nf_flow_pppoe_proto (skb); +if (!nf_flow_pppoe_proto (skb, &proto)) +return NF_ACCEPT ;break ;default : proto = skb->protocol;
net/netfilter/nf_flow_table_ip.c +5 -3
@@ -273,10 +273,11 @@ static unsigned int nf_flow_xmit_xfrm(struct sk_buff *skb,return NF_STOLEN ; } -static bool nf_flow_skb_encap_protocol (const struct sk_buff *skb,__be16 proto, +static bool nf_flow_skb_encap_protocol (struct sk_buff *skb,__be16 proto,u32 *offset) {struct vlan_ethhdr *veth; +__be16 inner_proto;switch (skb->protocol) {case htons (ETH_P_8021Q ):
@@ -287,7 +288,8 @@ static bool nf_flow_skb_encap_protocol(const struct sk_buff *skb, __be16 proto, }break ;case htons (ETH_P_PPP_SES ): -if (nf_flow_pppoe_proto (skb) == proto) { +if (nf_flow_pppoe_proto (skb, &inner_proto) && + inner_proto == proto) { *offset +=PPPOE_SES_HLEN ;return true; }
@@ -316,7 +318,7 @@ static void nf_flow_encap_pop(struct sk_buff *skb,skb_reset_network_header (skb);break ;case htons (ETH_P_PPP_SES ): - skb->protocol =nf_flow_pppoe_proto (skb); + skb->protocol =__nf_flow_pppoe_proto (skb);skb_pull (skb,PPPOE_SES_HLEN );skb_reset_network_header (skb);break ;
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 7/7 netfilter: flowtable: incorrect pppoe tuple
In reply to Pablo Neira Ayusopppoe traffic reaching ingress path does not match the flowtable entry because the pppoe header is expected to be at the network header offset. This bug causes a mismatch in the flow table lookup, so pppoe packets enter the classical forwarding path.
--- net/netfilter/nf_flow_table_ip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_flow_table_ip.c +1 -1
@@ -157,7 +157,7 @@ static void nf_flow_tuple_encap(struct sk_buff *skb, tuple->encap[i].proto = skb->protocol;break ;case htons (ETH_P_PPP_SES ): - phdr = (struct pppoe_hdr *)skb_mac_header (skb); + phdr = (struct pppoe_hdr *)skb_network_header (skb); tuple->encap[i].id =ntohs (phdr->sid); tuple->encap[i].proto = skb->protocol;break ;
Signature · 1 line
2.30.2
Paolo Abeni
maintainerQuoted 59 lines · Pablo Neira Ayuso
Hi,
The following patchset contains Netfilter fixes for net:
Patches #1 and #2 add missing rcu read side lock when iterating over expression and object type list which could race with module removal.
Patch #3 prevents promisc packet from visiting the bridge/input hook
to amend a recent fix to address conntrack confirmation race inbr_netfilterandnf_conntrack_bridge.Patch #4 adds and uses iterate decorator type to fetch the current
pipapo set backend datastructure view when netlink dumps the set elements.Patch #5 fixes removal of duplicate elements in the pipapo set backend.
Patch #6 flowtable validates pppoe header before accessing it.
Patch #7 fixes flowtable datapath for pppoe packets, otherwise lookup
fails and pppoe packets follow classic path.Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.gitnf-24-04-11Thanks.
----------------------------------------------------------------
The following changes since commit
19fa4f2a85d777a8052e869c1b892a2f7556569d:r8169: fix LED-related deadlock on module removal (2024-04-10 10:44:29 +0100)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.gittags/nf-24-04-11for you to fetch changes up to
6db5dc7b351b9569940cd1cf445e237c42cd6d27:netfilter: flowtable: incorrect pppoe tuple (2024-04-11 12:14:10 +0200)
----------------------------------------------------------------
netfilter pull request 24-04-11----------------------------------------------------------------
Florian Westphal (1):
netfilter:nft_set_pipapo: do not free live elementPablo Neira Ayuso (4):
netfilter:br_netfilter: skip conntrack input hook for promisc packets
netfilter:nft_set_pipapo: walk over current view on netlink dump
netfilter: flowtable: validate pppoe header
netfilter: flowtable: incorrect pppoe tupleZiyang Xuan (2):
netfilter:nf_tables: Fix potential data-race in__nft_expr_type_get()
netfilter:nf_tables: Fix potential data-race in__nft_obj_type_get()
Quoted 11 lines
include/net/netfilter/nf_flow_table.h | 12 +++++++++++- include/net/netfilter/nf_tables.h | 14 ++++++++++++++ net/bridge/br_input.c | 15 +++++++++++---- net/bridge/br_netfilter_hooks.c | 6 ++++++ net/bridge/br_private.h | 1 + net/bridge/netfilter/nf_conntrack_bridge.c | 14 ++++++++++---- net/netfilter/nf_flow_table_inet.c | 3 ++- net/netfilter/nf_flow_table_ip.c | 10 ++++++---- net/netfilter/nf_tables_api.c | 22 ++++++++++++++++++---- net/netfilter/nft_set_pipapo.c | 19 ++++++++++++------- 10 files changed, 91 insertions(+), 25 deletions(-)
Whoops, I'm finishing testing right now todays PR, I hope it's not a big issue if this lands later?
Thanks,
Paolo
Pablo Neira Ayuso
maintainerQuoted 72 lines · Paolo Abeni
Quoted 59 lines · Pablo Neira Ayuso
Hi,
The following patchset contains Netfilter fixes for net:
Patches #1 and #2 add missing rcu read side lock when iterating over expression and object type list which could race with module removal.
Patch #3 prevents promisc packet from visiting the bridge/input hook
to amend a recent fix to address conntrack confirmation race inbr_netfilterandnf_conntrack_bridge.Patch #4 adds and uses iterate decorator type to fetch the current
pipapo set backend datastructure view when netlink dumps the set elements.Patch #5 fixes removal of duplicate elements in the pipapo set backend.
Patch #6 flowtable validates pppoe header before accessing it.
Patch #7 fixes flowtable datapath for pppoe packets, otherwise lookup
fails and pppoe packets follow classic path.Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.gitnf-24-04-11Thanks.
----------------------------------------------------------------
The following changes since commit
19fa4f2a85d777a8052e869c1b892a2f7556569d:r8169: fix LED-related deadlock on module removal (2024-04-10 10:44:29 +0100)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.gittags/nf-24-04-11for you to fetch changes up to
6db5dc7b351b9569940cd1cf445e237c42cd6d27:netfilter: flowtable: incorrect pppoe tuple (2024-04-11 12:14:10 +0200)
----------------------------------------------------------------
netfilter pull request 24-04-11----------------------------------------------------------------
Florian Westphal (1):
netfilter:nft_set_pipapo: do not free live elementPablo Neira Ayuso (4):
netfilter:br_netfilter: skip conntrack input hook for promisc packets
netfilter:nft_set_pipapo: walk over current view on netlink dump
netfilter: flowtable: validate pppoe header
netfilter: flowtable: incorrect pppoe tupleZiyang Xuan (2):
netfilter:nf_tables: Fix potential data-race in__nft_expr_type_get()
netfilter:nf_tables: Fix potential data-race in__nft_obj_type_get()Quoted 11 lines
include/net/netfilter/nf_flow_table.h | 12 +++++++++++- include/net/netfilter/nf_tables.h | 14 ++++++++++++++ net/bridge/br_input.c | 15 +++++++++++---- net/bridge/br_netfilter_hooks.c | 6 ++++++ net/bridge/br_private.h | 1 + net/bridge/netfilter/nf_conntrack_bridge.c | 14 ++++++++++---- net/netfilter/nf_flow_table_inet.c | 3 ++- net/netfilter/nf_flow_table_ip.c | 10 ++++++---- net/netfilter/nf_tables_api.c | 22 ++++++++++++++++++---- net/netfilter/nft_set_pipapo.c | 19 ++++++++++++------- 10 files changed, 91 insertions(+), 25 deletions(-)
Quoted 2 lines
Whoops, I'm finishing testing right now todays PR, I hope it's not a big issue if this lands later?
Apologies, I am working at full steam here, I could not deliver any sooner.
Paolo Abeni
maintainerQuoted 73 lines · Pablo Neira Ayuso
Quoted 72 lines · Paolo Abeni
Quoted 70 lines · Pablo Neira Ayuso
Hi,
The following patchset contains Netfilter fixes for net:
Patches #1 and #2 add missing rcu read side lock when iterating over expression and object type list which could race with module removal.
Patch #3 prevents promisc packet from visiting the bridge/input hook
to amend a recent fix to address conntrack confirmation race inbr_netfilterandnf_conntrack_bridge.Patch #4 adds and uses iterate decorator type to fetch the current
pipapo set backend datastructure view when netlink dumps the set elements.Patch #5 fixes removal of duplicate elements in the pipapo set backend.
Patch #6 flowtable validates pppoe header before accessing it.
Patch #7 fixes flowtable datapath for pppoe packets, otherwise lookup
fails and pppoe packets follow classic path.Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.gitnf-24-04-11Thanks.
----------------------------------------------------------------
The following changes since commit
19fa4f2a85d777a8052e869c1b892a2f7556569d:r8169: fix LED-related deadlock on module removal (2024-04-10 10:44:29 +0100)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.gittags/nf-24-04-11for you to fetch changes up to
6db5dc7b351b9569940cd1cf445e237c42cd6d27:netfilter: flowtable: incorrect pppoe tuple (2024-04-11 12:14:10 +0200)
----------------------------------------------------------------
netfilter pull request 24-04-11----------------------------------------------------------------
Florian Westphal (1):
netfilter:nft_set_pipapo: do not free live elementPablo Neira Ayuso (4):
netfilter:br_netfilter: skip conntrack input hook for promisc packets
netfilter:nft_set_pipapo: walk over current view on netlink dump
netfilter: flowtable: validate pppoe header
netfilter: flowtable: incorrect pppoe tupleZiyang Xuan (2):
netfilter:nf_tables: Fix potential data-race in__nft_expr_type_get()
netfilter:nf_tables: Fix potential data-race in__nft_obj_type_get()include/net/netfilter/nf_flow_table.h | 12 +++++++++++- include/net/netfilter/nf_tables.h | 14 ++++++++++++++ net/bridge/br_input.c | 15 +++++++++++---- net/bridge/br_netfilter_hooks.c | 6 ++++++ net/bridge/br_private.h | 1 + net/bridge/netfilter/nf_conntrack_bridge.c | 14 ++++++++++---- net/netfilter/nf_flow_table_inet.c | 3 ++- net/netfilter/nf_flow_table_ip.c | 10 ++++++---- net/netfilter/nf_tables_api.c | 22 ++++++++++++++++++---- net/netfilter/nft_set_pipapo.c | 19 ++++++++++++------- 10 files changed, 91 insertions(+), 25 deletions(-)
Quoted 4 lines
Quoted 2 lines
Whoops, I'm finishing testing right now todays PR, I hope it's not a big issue if this lands later?
Apologies, I am working at full steam here, I could not deliver any sooner.
I'm sorry, I was likely unclear, the above was just a question (not a complain): do you have strong preference for these fixes to land into today's PR? (the answer is unclear to me)
Thanks!
Paolo
Pablo Neira Ayuso
maintainerQuoted 74 lines · Paolo Abeni
Quoted 73 lines · Pablo Neira Ayuso
Quoted 72 lines · Paolo Abeni
Quoted 70 lines · Pablo Neira Ayuso
Hi,
The following patchset contains Netfilter fixes for net:
Patches #1 and #2 add missing rcu read side lock when iterating over expression and object type list which could race with module removal.
Patch #3 prevents promisc packet from visiting the bridge/input hook
to amend a recent fix to address conntrack confirmation race inbr_netfilterandnf_conntrack_bridge.Patch #4 adds and uses iterate decorator type to fetch the current
pipapo set backend datastructure view when netlink dumps the set elements.Patch #5 fixes removal of duplicate elements in the pipapo set backend.
Patch #6 flowtable validates pppoe header before accessing it.
Patch #7 fixes flowtable datapath for pppoe packets, otherwise lookup
fails and pppoe packets follow classic path.Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.gitnf-24-04-11Thanks.
----------------------------------------------------------------
The following changes since commit
19fa4f2a85d777a8052e869c1b892a2f7556569d:r8169: fix LED-related deadlock on module removal (2024-04-10 10:44:29 +0100)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.gittags/nf-24-04-11for you to fetch changes up to
6db5dc7b351b9569940cd1cf445e237c42cd6d27:netfilter: flowtable: incorrect pppoe tuple (2024-04-11 12:14:10 +0200)
----------------------------------------------------------------
netfilter pull request 24-04-11----------------------------------------------------------------
Florian Westphal (1):
netfilter:nft_set_pipapo: do not free live elementPablo Neira Ayuso (4):
netfilter:br_netfilter: skip conntrack input hook for promisc packets
netfilter:nft_set_pipapo: walk over current view on netlink dump
netfilter: flowtable: validate pppoe header
netfilter: flowtable: incorrect pppoe tupleZiyang Xuan (2):
netfilter:nf_tables: Fix potential data-race in__nft_expr_type_get()
netfilter:nf_tables: Fix potential data-race in__nft_obj_type_get()include/net/netfilter/nf_flow_table.h | 12 +++++++++++- include/net/netfilter/nf_tables.h | 14 ++++++++++++++ net/bridge/br_input.c | 15 +++++++++++---- net/bridge/br_netfilter_hooks.c | 6 ++++++ net/bridge/br_private.h | 1 + net/bridge/netfilter/nf_conntrack_bridge.c | 14 ++++++++++---- net/netfilter/nf_flow_table_inet.c | 3 ++- net/netfilter/nf_flow_table_ip.c | 10 ++++++---- net/netfilter/nf_tables_api.c | 22 ++++++++++++++++++---- net/netfilter/nft_set_pipapo.c | 19 ++++++++++++------- 10 files changed, 91 insertions(+), 25 deletions(-)
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Whoops, I'm finishing testing right now todays PR, I hope it's not a big issue if this lands later?
Apologies, I am working at full steam here, I could not deliver any sooner.
I'm sorry, I was likely unclear, the above was just a question (not a complain): do you have strong preference for these fixes to land into today's PR? (the answer is unclear to me)
No problem Paolo, I can miss this flight, it is OK.