Skip to contentSkip to conversation

Netfilter updates for net-next

PATCH Applied Pablo Neira Ayuso 2 participants 9 messages Dec 15, 2021 – Dec 16, 2021

Subsystems (5)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

cover Netfilter updates for net-next

Hi,

The following patchset contains Netfilter updates for net-next, mostly rather small housekeeping patches:

1) Remove unused variable in IPVS, from GuoYong Zheng.

2) Use memset_after in conntrack, from Kees Cook.

3) Remove leftover function in nfnetlink_queue, from Florian Westphal.

4) Remove redundant test on bool in conntrack, from Bernard Zhao.

5) egress support for nft_fwd, from Lukas Wunner.

6) Make pppoe work for br_netfilter, from Florian Westphal.

7) Remove unused variable in conntrack resize routine, from luo penghao.

Please, pull these changes from:

git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git

Thanks.

----------------------------------------------------------------

The following changes since commit 196073f9c44be0b4758ead11e51bc2875f98df29:

net: ixp4xx_hss: drop kfree for memory allocated with devm_kzalloc (2021-11-30 12:40:22 +0000)

are available in the Git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git HEAD

for you to fetch changes up to 284ca7647c67683b32f4f8c0dec6cc38cb2cb9f8:

netfilter: conntrack: Remove useless assignment statements (2021-12-16 00:17:40 +0100)

----------------------------------------------------------------
Bernard Zhao (1):
netfilter: ctnetlink: remove useless type conversion to bool

Florian Westphal (2):
netfilter: nf_queue: remove leftover synchronize_rcu
netfilter: bridge: add support for pppoe filtering

GuoYong Zheng (1):
ipvs: remove unused variable for ip_vs_new_dest

Kees Cook (1):
netfilter: conntrack: Use memset_startat() to zero struct nf_conn

Pablo Neira Ayuso (1):
netfilter: nft_fwd_netdev: Support egress hook

luo penghao (1):
netfilter: conntrack: Remove useless assignment statements

 net/bridge/br_netfilter_hooks.c      | 7 +++----
 net/netfilter/ipvs/ip_vs_ctl.c       | 7 ++-----
 net/netfilter/nf_conntrack_core.c    | 5 +----
 net/netfilter/nf_conntrack_netlink.c | 2 +-
 net/netfilter/nfnetlink_queue.c      | 6 ------
 net/netfilter/nft_fwd_netdev.c       | 7 +++++--
 6 files changed, 12 insertions(+), 22 deletions(-)
author maintainer
#1 lore raw

PATCH 1/7 ipvs: remove unused variable for ip_vs_new_dest

From: GuoYong Zheng <[email protected]>

The dest variable is not used after ip_vs_new_dest anymore in ip_vs_add_dest, do not need pass it to ip_vs_new_dest, remove it.

---
 net/netfilter/ipvs/ip_vs_ctl.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
net/netfilter/ipvs/ip_vs_ctl.c +2 -5
index 39c523bd775c..7f645328b47f 100644
@@ -960,8 +960,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
  *	Create a destination for the given service
  */
 static int
-ip_vs_new_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest,
-	       struct ip_vs_dest **dest_p)
+ip_vs_new_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
 {
 	struct ip_vs_dest *dest;
 	unsigned int atype, i;
@@ -1021,8 +1020,6 @@ ip_vs_new_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest,
 	spin_lock_init(&dest->stats.lock);
 	__ip_vs_update_dest(svc, dest, udest, 1);
 
-	*dest_p = dest;
-
 	LeaveFunction(2);
 	return 0;
 
@@ -1096,7 +1093,7 @@ ip_vs_add_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
 		/*
 		 * Allocate and initialize the dest structure
 		 */
-		ret = ip_vs_new_dest(svc, udest, &dest);
+		ret = ip_vs_new_dest(svc, udest);
 	}
 	LeaveFunction(2);
 
Signature · 1 line
2.30.2
#2 lore raw

Re: [PATCH nf-next 1/7] ipvs: remove unused variable for ip_vs_new_dest

This series was applied to netdev/net-next.git (master) by Pablo Neira Ayuso <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (master) by Pablo Neira Ayuso <[email protected]>:

Quoted 11 lines · On Thu, 16 Dec 2021 00:49:05 +0100 you wrote:

From: GuoYong Zheng <[email protected]>

The dest variable is not used after ip_vs_new_dest anymore in ip_vs_add_dest, do not need pass it to ip_vs_new_dest, remove it.

[...]

Here is the summary with links:
- [nf-next,1/7] ipvs: remove unused variable for ip_vs_new_dest

    https://git.kernel.org/netdev/net-next/c/fc5e0352ccb5
  - [nf-next,2/7] netfilter: conntrack: Use memset_startat() to zero struct nf_conn
    https://git.kernel.org/netdev/net-next/c/4be1dbb75c3d
  - [nf-next,3/7] netfilter: nf_queue: remove leftover synchronize_rcu
    https://git.kernel.org/netdev/net-next/c/c5fc837bf934
  - [nf-next,4/7] netfilter: ctnetlink: remove useless type conversion to bool
    https://git.kernel.org/netdev/net-next/c/632cb151ca53
  - [nf-next,5/7] netfilter: nft_fwd_netdev: Support egress hook
    https://git.kernel.org/netdev/net-next/c/f87b9464d152
  - [nf-next,6/7] netfilter: bridge: add support for pppoe filtering
    https://git.kernel.org/netdev/net-next/c/28b78ecffea8
  - [nf-next,7/7] netfilter: conntrack: Remove useless assignment statements
    https://git.kernel.org/netdev/net-next/c/284ca7647c67

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
author maintainer
#3 lore raw

PATCH 2/7 netfilter: conntrack: Use memset_startat() to zero struct nf_conn

In reply to Pablo Neira Ayuso

From: Kees Cook <[email protected]>

In preparation for FORTIFY_SOURCE performing compile-time and run-time field bounds checking for memset(), avoid intentionally writing across neighboring fields.

Use memset_startat() to avoid confusing memset() about writing beyond the target struct member.

---
 net/netfilter/nf_conntrack_core.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
net/netfilter/nf_conntrack_core.c +1 -3
index 054ee9d25efe..aa657db18318 100644
@@ -1562,9 +1562,7 @@ __nf_conntrack_alloc(struct net *net,
 	ct->status = 0;
 	ct->timeout = 0;
 	write_pnet(&ct->ct_net, net);
-	memset(&ct->__nfct_init_offset, 0,
-	       offsetof(struct nf_conn, proto) -
-	       offsetof(struct nf_conn, __nfct_init_offset));
+	memset_after(ct, 0, __nfct_init_offset);
 
 	nf_ct_zone_add(ct, zone);
 
Signature · 1 line
2.30.2
author maintainer
#4 lore raw

PATCH 3/7 netfilter: nf_queue: remove leftover synchronize_rcu

In reply to Pablo Neira Ayuso

From: Florian Westphal <[email protected]>

Its no longer needed after commit 870299707436 ("netfilter: nf_queue: move hookfn registration out of struct net").

---
 net/netfilter/nfnetlink_queue.c | 6 ------
 1 file changed, 6 deletions(-)
net/netfilter/nfnetlink_queue.c +0 -6
index 4acc4b8e9fe5..b61165e97252 100644
@@ -1527,15 +1527,9 @@ static void __net_exit nfnl_queue_net_exit(struct net *net)
 		WARN_ON_ONCE(!hlist_empty(&q->instance_table[i]));
 }
 
-static void nfnl_queue_net_exit_batch(struct list_head *net_exit_list)
-{
-	synchronize_rcu();
-}
-
 static struct pernet_operations nfnl_queue_net_ops = {
 	.init		= nfnl_queue_net_init,
 	.exit		= nfnl_queue_net_exit,
-	.exit_batch	= nfnl_queue_net_exit_batch,
 	.id		= &nfnl_queue_net_id,
 	.size		= sizeof(struct nfnl_queue_net),
 };
Signature · 1 line
2.30.2
author maintainer
#5 lore raw

PATCH 4/7 netfilter: ctnetlink: remove useless type conversion to bool

In reply to Pablo Neira Ayuso

From: Bernard Zhao <[email protected]>

dying is bool, the type conversion to true/false value is not needed.

---
 net/netfilter/nf_conntrack_netlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_conntrack_netlink.c +1 -1
index 849fa7f4353c..f9f5cb46c43d 100644
@@ -1746,7 +1746,7 @@ ctnetlink_dump_list(struct sk_buff *skb, struct netlink_callback *cb, bool dying
 			res = ctnetlink_fill_info(skb, NETLINK_CB(cb->skb).portid,
 						  cb->nlh->nlmsg_seq,
 						  NFNL_MSG_TYPE(cb->nlh->nlmsg_type),
-						  ct, dying ? true : false, 0);
+						  ct, dying, 0);
 			if (res < 0) {
 				if (!atomic_inc_not_zero(&ct->ct_general.use))
 					continue;
Signature · 1 line
2.30.2
author maintainer
#6 lore raw

PATCH 5/7 netfilter: nft_fwd_netdev: Support egress hook

In reply to Pablo Neira Ayuso

Allow packet redirection to another interface upon egress.

[lukas: set skb_iif, add commit message, original patch from Pablo. ]
---
 net/netfilter/nft_fwd_netdev.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
net/netfilter/nft_fwd_netdev.c +5 -2
index cd59afde5b2f..fa9301ca6033 100644
@@ -27,9 +27,11 @@ static void nft_fwd_netdev_eval(const struct nft_expr *expr,
 {
 	struct nft_fwd_netdev *priv = nft_expr_priv(expr);
 	int oif = regs->data[priv->sreg_dev];
+	struct sk_buff *skb = pkt->skb;
 
 	/* This is used by ifb only. */
-	skb_set_redirected(pkt->skb, true);
+	skb->skb_iif = skb->dev->ifindex;
+	skb_set_redirected(skb, nft_hook(pkt) == NF_NETDEV_INGRESS);
 
 	nf_fwd_netdev_egress(pkt, oif);
 	regs->verdict.code = NF_STOLEN;
@@ -198,7 +200,8 @@ static int nft_fwd_validate(const struct nft_ctx *ctx,
 			    const struct nft_expr *expr,
 			    const struct nft_data **data)
 {
-	return nft_chain_validate_hooks(ctx->chain, (1 << NF_NETDEV_INGRESS));
+	return nft_chain_validate_hooks(ctx->chain, (1 << NF_NETDEV_INGRESS) |
+						    (1 << NF_NETDEV_EGRESS));
 }
 
 static struct nft_expr_type nft_fwd_netdev_type;
Signature · 1 line
2.30.2
author maintainer
#7 lore raw

PATCH 6/7 netfilter: bridge: add support for pppoe filtering

In reply to Pablo Neira Ayuso

From: Florian Westphal <[email protected]>

This makes 'bridge-nf-filter-pppoe-tagged' sysctl work for bridged traffic.

Looking at the original commit it doesn't appear this ever worked:

static unsigned int br_nf_post_routing(unsigned int hook, struct sk_buff **pskb,
[..]

        if (skb->protocol == htons(ETH_P_8021Q)) {
                skb_pull(skb, VLAN_HLEN);
                skb->network_header += VLAN_HLEN;
+       } else if (skb->protocol == htons(ETH_P_PPP_SES)) {
+               skb_pull(skb, PPPOE_SES_HLEN);
+               skb->network_header += PPPOE_SES_HLEN;
        }
 [..]
	NF_HOOK(... POST_ROUTING, ...)

... but the adjusted offsets are never restored.

The alternative would be to rip this code out for good, but otoh we'd have to keep this anyway for the vlan handling (which works because vlan tag info is in the skb, not the packet
payload).

Reported-and-tested-by Amish Chana <[email protected]>
Fixes 516299d2f5b6f97 ("[NETFILTER]: bridge-nf: filter bridged IPv4/IPv6 encapsulated in pppoe traffic")
---
 net/bridge/br_netfilter_hooks.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
net/bridge/br_netfilter_hooks.c +3 -4
index b5af68c105a8..4fd882686b04 100644
@@ -743,6 +743,9 @@ static int br_nf_dev_queue_xmit(struct net *net, struct sock *sk, struct sk_buff
 	if (nf_bridge->frag_max_size && nf_bridge->frag_max_size < mtu)
 		mtu = nf_bridge->frag_max_size;
 
+	nf_bridge_update_protocol(skb);
+	nf_bridge_push_encap_header(skb);
+
 	if (skb_is_gso(skb) || skb->len + mtu_reserved <= mtu) {
 		nf_bridge_info_free(skb);
 		return br_dev_queue_push_xmit(net, sk, skb);
@@ -760,8 +763,6 @@ static int br_nf_dev_queue_xmit(struct net *net, struct sock *sk, struct sk_buff
 
 		IPCB(skb)->frag_max_size = nf_bridge->frag_max_size;
 
-		nf_bridge_update_protocol(skb);
-
 		data = this_cpu_ptr(&brnf_frag_data_storage);
 
 		if (skb_vlan_tag_present(skb)) {
@@ -789,8 +790,6 @@ static int br_nf_dev_queue_xmit(struct net *net, struct sock *sk, struct sk_buff
 
 		IP6CB(skb)->frag_max_size = nf_bridge->frag_max_size;
 
-		nf_bridge_update_protocol(skb);
-
 		data = this_cpu_ptr(&brnf_frag_data_storage);
 		data->encap_size = nf_bridge_encap_header_len(skb);
 		data->size = ETH_HLEN + data->encap_size;
Signature · 1 line
2.30.2
author maintainer
#8 lore raw

PATCH 7/7 netfilter: conntrack: Remove useless assignment statements

In reply to Pablo Neira Ayuso

From: luo penghao <[email protected]>

The old_size assignment here will not be used anymore

The clang_analyzer complains as follows:

Value stored to 'old_size' is never read

---
 net/netfilter/nf_conntrack_core.c | 1 -
 1 file changed, 1 deletion(-)
net/netfilter/nf_conntrack_core.c +0 -1
index aa657db18318..b622ef143415 100644
@@ -2588,7 +2588,6 @@ int nf_conntrack_hash_resize(unsigned int hashsize)
 			hlist_nulls_add_head_rcu(&h->hnnode, &hash[bucket]);
 		}
 	}
-	old_size = nf_conntrack_htable_size;
 	old_hash = nf_conntrack_hash;
 
 	nf_conntrack_hash = hash;
Signature · 1 line
2.30.2