Netfilter/IPVS updates for net-next
Subsystems (6)
Pablo Neira Ayuso
maintainercover Netfilter/IPVS updates for net-next
Hi,
The following patchset contains Netfilter/IPVS updates for net-next:
1) Simplify nf_ct_get_tuple(), from Jackie Liu.
2) Add format to request_module() call, from Bill Wendling.
3) Add /proc/net/stats/nf_flowtable to monitor in-flight pending hardware offload objects to be processed, from Vlad Buslov.
4) Missing rcu annotation and accessors in the netfilter tree, from Florian Westphal.
5) Merge h323 conntrack helper nat hooks into single object, also from Florian.
6) A batch of update to fix sparse warnings treewide, from Florian Westphal.
7) Move nft_cmp_fast_mask() where it used, from Florian.
8) Missing const in nf_nat_initialized(), from James Yonan.
9) Use bitmap API for Maglev IPVS scheduler, from Christophe Jaillet.
10) Use refcount_inc instead of _inc_not_zero in flowtable, from Florian Westphal.
11) Remove pr_debug in xt_TPROXY, from Nathan Cancellor.
Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next.git
Thanks.
----------------------------------------------------------------
The following changes since commit edb2c3476db9898a63fb5d0011ecaa43ebf46c9b:
fddi/skfp: fix repeated words in comments (2022-07-11 14:12:54 +0100)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next.git HEAD
for you to fetch changes up to aa8c7cdbae58b695ed79a0129b6b8c887b25969f:
netfilter: xt_TPROXY: remove pr_debug invocations (2022-07-21 00:56:00 +0200)
----------------------------------------------------------------
Bill Wendling (1):
netfilter: conntrack: use correct format characters
Christophe JAILLET (1):
netfilter: ipvs: Use the bitmap API to allocate bitmaps
Florian Westphal (10):
netfilter: nf_conntrack: add missing __rcu annotations
netfilter: nf_conntrack: use rcu accessors where needed
netfilter: h323: merge nat hook pointers into one
netfilter: nfnetlink: add missing __be16 cast
netfilter: x_tables: use correct integer types
netfilter: nf_tables: use the correct get/put helpers
netfilter: nf_tables: add and use BE register load-store helpers
netfilter: nf_tables: use correct integer types
netfilter: nf_tables: move nft_cmp_fast_mask to where its used
netfilter: flowtable: prefer refcount_inc
Jackie Liu (1):
netfilter: conntrack: use fallthrough to cleanup
James Yonan (1):
netfilter: nf_nat: in nf_nat_initialized(), use const struct nf_conn *
Justin Stitt (1):
netfilter: xt_TPROXY: remove pr_debug invocations
Vlad Buslov (2):
net/sched: act_ct: set 'net' pointer when creating new nf_flow_table
netfilter: nf_flow_table: count pending offload workqueue tasks
Zhang Jiaming (1):
netfilter: nft_set_bitmap: Fix spelling mistake
include/linux/netfilter/nf_conntrack_h323.h | 109 +++++------ include/linux/netfilter/nf_conntrack_sip.h | 2 +- include/net/net_namespace.h | 6 + include/net/netfilter/nf_conntrack_timeout.h | 2 +- include/net/netfilter/nf_flow_table.h | 21 +++ include/net/netfilter/nf_nat.h | 2 +- include/net/netfilter/nf_tables.h | 15 ++ include/net/netfilter/nf_tables_core.h | 10 -- include/net/netns/flow_table.h | 14 ++ net/bridge/netfilter/nft_meta_bridge.c | 2 +- net/ipv4/netfilter/nf_nat_h323.c | 42 ++--- net/netfilter/Kconfig | 9 + net/netfilter/Makefile | 1 + net/netfilter/ipvs/ip_vs_mh.c | 5 +- net/netfilter/nf_conntrack_broadcast.c | 6 +- net/netfilter/nf_conntrack_core.c | 8 +- net/netfilter/nf_conntrack_h323_main.c | 260 ++++++++++----------------- net/netfilter/nf_conntrack_helper.c | 4 +- net/netfilter/nf_conntrack_netlink.c | 9 +- net/netfilter/nf_conntrack_pptp.c | 2 +- net/netfilter/nf_conntrack_sip.c | 9 +- net/netfilter/nf_conntrack_timeout.c | 18 +- net/netfilter/nf_flow_table_core.c | 73 +++++++- net/netfilter/nf_flow_table_offload.c | 17 +- net/netfilter/nf_flow_table_procfs.c | 80 +++++++++ net/netfilter/nfnetlink.c | 2 +- net/netfilter/nfnetlink_cthelper.c | 10 +- net/netfilter/nft_byteorder.c | 3 +- net/netfilter/nft_cmp.c | 18 +- net/netfilter/nft_ct.c | 4 +- net/netfilter/nft_exthdr.c | 10 +- net/netfilter/nft_osf.c | 2 +- net/netfilter/nft_set_bitmap.c | 4 +- net/netfilter/nft_socket.c | 8 +- net/netfilter/nft_tproxy.c | 6 +- net/netfilter/nft_tunnel.c | 3 +- net/netfilter/nft_xfrm.c | 8 +- net/netfilter/xt_CT.c | 23 ++- net/netfilter/xt_DSCP.c | 8 +- net/netfilter/xt_TCPMSS.c | 4 +- net/netfilter/xt_TPROXY.c | 25 +-- net/netfilter/xt_connlimit.c | 6 +- net/sched/act_ct.c | 5 +- 43 files changed, 518 insertions(+), 357 deletions(-) create mode 100644 include/net/netns/flow_table.h create mode 100644 net/netfilter/nf_flow_table_procfs.c
Pablo Neira Ayuso
maintainerPATCH 1/18 netfilter: conntrack: use fallthrough to cleanup
From: Jackie Liu <[email protected]>
These cases all use the same function. we can simplify the code through fallthrough.
$ size net/netfilter/nf_conntrack_core.o
text data bss dec hex filename before 81601 81430 768 163799 27fd7 net/netfilter/nf_conntrack_core.o after 80361 81430 768 162559 27aff net/netfilter/nf_conntrack_core.o
Arch: aarch64
Gcc : gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
--- net/netfilter/nf_conntrack_core.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
net/netfilter/nf_conntrack_core.c +3 -5
@@ -329,20 +329,18 @@ nf_ct_get_tuple(const struct sk_buff *skb,return gre_pkt_to_tuple (skb, dataoff, net, tuple);#endif case IPPROTO_TCP : -case IPPROTO_UDP :/* fallthrough */ -return nf_ct_get_tuple_ports (skb, dataoff, tuple); +case IPPROTO_UDP :#ifdef CONFIG_NF_CT_PROTO_UDPLITE case IPPROTO_UDPLITE : -return nf_ct_get_tuple_ports (skb, dataoff, tuple);#endif #ifdef CONFIG_NF_CT_PROTO_SCTP case IPPROTO_SCTP : -return nf_ct_get_tuple_ports (skb, dataoff, tuple);#endif #ifdef CONFIG_NF_CT_PROTO_DCCP case IPPROTO_DCCP : -return nf_ct_get_tuple_ports (skb, dataoff, tuple);#endif +/* fallthrough */ +return nf_ct_get_tuple_ports (skb, dataoff, tuple);default :break ; }
Signature · 1 line
2.30.2
Re: [PATCH nf-next 01/18] netfilter: conntrack: use fallthrough to cleanup
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 8 lines · On Thu, 21 Jul 2022 01:07:37 +0200 you wrote:
From: Jackie Liu <[email protected]>
These cases all use the same function. we can simplify the code through fallthrough.
$ size net/netfilter/nf_conntrack_core.o[...]
Here is the summary with links:
- [nf-next,01/18] netfilter: conntrack: use fallthrough to cleanup
https://git.kernel.org/netdev/net-next/c/6be791561212 - [nf-next,02/18] netfilter: conntrack: use correct format characters https://git.kernel.org/netdev/net-next/c/b8acd43148c0 - [nf-next,03/18] net/sched: act_ct: set 'net' pointer when creating new nf_flow_table https://git.kernel.org/netdev/net-next/c/fc54d9065f90 - [nf-next,04/18] netfilter: nf_flow_table: count pending offload workqueue tasks https://git.kernel.org/netdev/net-next/c/b038177636f8 - [nf-next,05/18] netfilter: nf_conntrack: add missing __rcu annotations https://git.kernel.org/netdev/net-next/c/6976890e8998 - [nf-next,06/18] netfilter: nf_conntrack: use rcu accessors where needed https://git.kernel.org/netdev/net-next/c/e14575fa7529 - [nf-next,07/18] netfilter: h323: merge nat hook pointers into one https://git.kernel.org/netdev/net-next/c/d3f2d0a292c2 - [nf-next,08/18] netfilter: nft_set_bitmap: Fix spelling mistake https://git.kernel.org/netdev/net-next/c/f72547473fcd - [nf-next,09/18] netfilter: nfnetlink: add missing __be16 cast https://git.kernel.org/netdev/net-next/c/ec6f2ff0a398 - [nf-next,10/18] netfilter: x_tables: use correct integer types https://git.kernel.org/netdev/net-next/c/168141f7e0b4 - [nf-next,11/18] netfilter: nf_tables: use the correct get/put helpers https://git.kernel.org/netdev/net-next/c/d86473bf2ff3 - [nf-next,12/18] netfilter: nf_tables: add and use BE register load-store helpers https://git.kernel.org/netdev/net-next/c/7278b3c1e4eb - [nf-next,13/18] netfilter: nf_tables: use correct integer types https://git.kernel.org/netdev/net-next/c/ffb3d9a30cc6 - [nf-next,14/18] netfilter: nf_tables: move nft_cmp_fast_mask to where its used https://git.kernel.org/netdev/net-next/c/6b77205374fd - [nf-next,15/18] netfilter: nf_nat: in nf_nat_initialized(), use const struct nf_conn * https://git.kernel.org/netdev/net-next/c/9d2f00fb0a0c - [nf-next,16/18] netfilter: ipvs: Use the bitmap API to allocate bitmaps https://git.kernel.org/netdev/net-next/c/5787db7c9053 - [nf-next,17/18] netfilter: flowtable: prefer refcount_inc https://git.kernel.org/netdev/net-next/c/f02e7dc4cff8
- [nf-next,18/18] netfilter: xt_TPROXY: remove pr_debug invocations (no matching commit)
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/18 netfilter: conntrack: use correct format characters
In reply to Pablo Neira AyusoFrom: Bill Wendling <[email protected]>
When compiling with -Wformat, clang emits the following warnings:
net/netfilter/nf_conntrack_helper.c:168:18: error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]
request_module(mod_name);
^~~~~~~~Use a string literal for the format string.
--- net/netfilter/nf_conntrack_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_conntrack_helper.c +1 -1
@@ -165,7 +165,7 @@ nf_nat_helper_try_module_get(const char *name, u16 l3num, u8 protonum)if (!nat) {snprintf (mod_name,sizeof (mod_name),"%s" , h->nat_mod_name);rcu_read_unlock (); -request_module (mod_name); +request_module ("%s" , mod_name);rcu_read_lock (); nat =nf_conntrack_nat_helper_find (mod_name);
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 3/18 net/sched: act_ct: set 'net' pointer when creating new nf_flow_table
In reply to Pablo Neira AyusoFrom: Vlad Buslov <[email protected]>
Following patches in series use the pointer to access flow table offload debug variables.
--- net/sched/act_ct.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
net/sched/act_ct.c +3 -2
@@ -277,7 +277,7 @@ static struct nf_flowtable_type flowtable_ct = { .owner = THIS_MODULE, }; -static int tcf_ct_flow_table_get (struct tcf_ct_params *params) +static int tcf_ct_flow_table_get (struct net *net,struct tcf_ct_params *params) {struct tcf_ct_flow_table *ct_ft;int err = -ENOMEM ;
@@ -303,6 +303,7 @@ static int tcf_ct_flow_table_get(struct tcf_ct_params *params) err =nf_flow_table_init (&ct_ft->nf_ft);if (err) goto err_init; +write_pnet (&ct_ft->nf_ft.net, net);__module_get (THIS_MODULE ); out_unlock:
@@ -1391,7 +1392,7 @@ static int tcf_ct_init(struct net *net, struct nlattr *nla,if (err) goto cleanup; - err =tcf_ct_flow_table_get (params); + err =tcf_ct_flow_table_get (net, params);if (err) goto cleanup;
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 4/18 netfilter: nf_flow_table: count pending offload workqueue tasks
In reply to Pablo Neira AyusoFrom: Vlad Buslov <[email protected]>
To improve hardware offload debuggability count pending 'add', 'del' and 'stats' flow_table offload workqueue tasks. Counters are incremented before scheduling new task and decremented when workqueue handler finishes executing. These counters allow user to diagnose congestion on hardware offload workqueues that can happen when either CPU is starved and workqueue jobs are executed at lower rate than new ones are added or when hardware/driver can't keep up with the rate.
Implement the described counters as percpu counters inside new struct netns_ft which is stored inside struct net. Expose them via new procfs file '/proc/net/stats/nf_flowtable' that is similar to existing 'nf_conntrack' file.
--- include/net/net_namespace.h | 6 ++ include/net/netfilter/nf_flow_table.h | 21 +++++++ include/net/netns/flow_table.h | 14 +++++ net/netfilter/Kconfig | 9 +++ net/netfilter/Makefile | 1 + net/netfilter/nf_flow_table_core.c | 62 ++++++++++++++++++++- net/netfilter/nf_flow_table_offload.c | 17 +++++- net/netfilter/nf_flow_table_procfs.c | 80 +++++++++++++++++++++++++++ 8 files changed, 206 insertions(+), 4 deletions(-) create mode 100644 include/net/netns/flow_table.h create mode 100644 net/netfilter/nf_flow_table_procfs.c
include/net/net_namespace.h +6 -0
@@ -26,6 +26,9 @@#if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE )#include <net/netns/conntrack.h> #endif +#if IS_ENABLED (CONFIG_NF_FLOW_TABLE ) +#include <net/netns/flow_table.h> +#endif #include <net/netns/nftables.h> #include <net/netns/xfrm.h> #include <net/netns/mpls.h>
@@ -142,6 +145,9 @@ struct net {#if defined(CONFIG_NF_TABLES ) || defined(CONFIG_NF_TABLES_MODULE )struct netns_nftables nft;#endif +#if IS_ENABLED (CONFIG_NF_FLOW_TABLE ) +struct netns_ft ft; +#endif #endif #ifdef CONFIG_WEXT_CORE struct sk_buff_head wext_nlevents;
include/net/netfilter/nf_flow_table.h +21 -0
@@ -335,4 +335,25 @@ static inline __be16 nf_flow_pppoe_proto(const struct sk_buff *skb) return 0; } +#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) \ + this_cpu_inc((net)->ft.stat->count) +#define NF_FLOW_TABLE_STAT_DEC_ATOMIC (net, count) \ + this_cpu_dec((net)->ft.stat->count) + +#ifdef CONFIG_NF_FLOW_TABLE_PROCFS +int nf_flow_table_init_proc (struct net *net); +void nf_flow_table_fini_proc (struct net *net); +#else +static inline int nf_flow_table_init_proc (struct net *net) +{ +return 0 ; +} + +static inline void nf_flow_table_fini_proc (struct net *net) +{ +} +#endif /* CONFIG_NF_FLOW_TABLE_PROCFS */ +#endif /* _NF_FLOW_TABLE_H */
include/net/netns/flow_table.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __NETNS_FLOW_TABLE_H +#define __NETNS_FLOW_TABLE_H + +struct nf_flow_table_stat { +unsigned int count_wq_add; +unsigned int count_wq_del; +unsigned int count_wq_stats; +}; + +struct netns_ft { +struct nf_flow_table_stat __percpu *stat; +}; +#endif
net/netfilter/Kconfig +9 -0
@@ -734,6 +734,15 @@ config NF_FLOW_TABLE To compile it as a module, choose M here. +config NF_FLOW_TABLE_PROCFS + bool "Supply flow table statistics in procfs" + default y + depends on PROC_FS + depends on SYSCTL + help + This option enables for the flow table offload statistics + to be shown in procfs under net/netfilter/nf_flowtable. + config NETFILTER_XTABLES tristate "Netfilter Xtables support (required for ip_tables)" default m if NETFILTER_ADVANCED=n
net/netfilter/Makefile +1 -0
@@ -128,6 +128,7 @@ obj-$(CONFIG_NFT_FWD_NETDEV) += nft_fwd_netdev.o obj-$(CONFIG_NF_FLOW_TABLE) += nf_flow_table.o nf_flow_table-objs := nf_flow_table_core.o nf_flow_table_ip.o \ nf_flow_table_offload.o +nf_flow_table-$(CONFIG_NF_FLOW_TABLE_PROCFS) += nf_flow_table_procfs.o obj-$(CONFIG_NF_FLOW_TABLE_INET) += nf_flow_table_inet.o
net/netfilter/nf_flow_table_core.c +61 -1
75 lines not on this page · raw message
net/netfilter/nf_flow_table_offload.c +14 -3
@@ -967,17 +967,22 @@ static void flow_offload_work_stats(struct flow_offload_work *offload)static void flow_offload_work_handler (struct work_struct *work) {struct flow_offload_work *offload; +struct net *net; offload = container_of(work, struct flow_offload_work, work); + net =read_pnet (&offload->flowtable->net);switch (offload->cmd) {case FLOW_CLS_REPLACE :flow_offload_work_add (offload); +NF_FLOW_TABLE_STAT_DEC_ATOMIC (net, count_wq_add);break ;case FLOW_CLS_DESTROY :flow_offload_work_del (offload); +NF_FLOW_TABLE_STAT_DEC_ATOMIC (net, count_wq_del);break ;case FLOW_CLS_STATS :flow_offload_work_stats (offload); +NF_FLOW_TABLE_STAT_DEC_ATOMIC (net, count_wq_stats);break ;default :WARN_ON_ONCE (1 );
@@ -989,12 +994,18 @@ static void flow_offload_work_handler(struct work_struct *work)static void flow_offload_queue_work (struct flow_offload_work *offload) { -if (offload->cmd ==FLOW_CLS_REPLACE ) +struct net *net =read_pnet (&offload->flowtable->net); + +if (offload->cmd ==FLOW_CLS_REPLACE ) { +NF_FLOW_TABLE_STAT_INC (net, count_wq_add);queue_work (nf_flow_offload_add_wq, &offload->work); -else if (offload->cmd ==FLOW_CLS_DESTROY ) + }else if (offload->cmd ==FLOW_CLS_DESTROY ) { +NF_FLOW_TABLE_STAT_INC (net, count_wq_del);queue_work (nf_flow_offload_del_wq, &offload->work); -else + }else { +NF_FLOW_TABLE_STAT_INC (net, count_wq_stats);queue_work (nf_flow_offload_stats_wq, &offload->work); + } } static struct flow_offload_work *
net/netfilter/nf_flow_table_procfs.c new file +80 -0
80 lines not on this page · raw message
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 5/18 netfilter: nf_conntrack: add missing __rcu annotations
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Access to the hook pointers use correct helpers but the pointers lack the needed __rcu annotation.
--- include/linux/netfilter/nf_conntrack_sip.h | 2 +- include/net/netfilter/nf_conntrack_timeout.h | 2 +- net/netfilter/nf_conntrack_pptp.c | 2 +- net/netfilter/nf_conntrack_sip.c | 2 +- net/netfilter/nf_conntrack_timeout.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-)
include/linux/netfilter/nf_conntrack_sip.h +1 -1
@@ -164,7 +164,7 @@ struct nf_nat_sip_hooks {unsigned int medialen, union nf_inet_addr *rtp_addr); }; -extern const struct nf_nat_sip_hooks *nf_nat_sip_hooks; +extern const struct nf_nat_sip_hooks __rcu *nf_nat_sip_hooks; int ct_sip_parse_request(const struct nf_conn *ct, const char *dptr, unsigned int datalen, unsigned int *matchoff,
include/net/netfilter/nf_conntrack_timeout.h +1 -1
@@ -105,7 +105,7 @@ struct nf_ct_timeout_hooks {void (*timeout_put)(struct nf_ct_timeout *timeout); }; -extern const struct nf_ct_timeout_hooks *nf_ct_timeout_hook; +extern const struct nf_ct_timeout_hooks __rcu *nf_ct_timeout_hook;#endif #endif /* _NF_CONNTRACK_TIMEOUT_H */
net/netfilter/nf_conntrack_pptp.c +1 -1
@@ -45,7 +45,7 @@ MODULE_ALIAS_NFCT_HELPER("pptp");static DEFINE_SPINLOCK (nf_pptp_lock); -const struct nf_nat_pptp_hook *nf_nat_pptp_hook; +const struct nf_nat_pptp_hook __rcu *nf_nat_pptp_hook;EXPORT_SYMBOL_GPL (nf_nat_pptp_hook);#if defined(DEBUG ) || defined(CONFIG_DYNAMIC_DEBUG )
net/netfilter/nf_conntrack_sip.c +1 -1
@@ -60,7 +60,7 @@ module_param(sip_external_media, int, 0600);MODULE_PARM_DESC (sip_external_media,"Expect Media streams between external " "endpoints (default 0)" ); -const struct nf_nat_sip_hooks *nf_nat_sip_hooks; +const struct nf_nat_sip_hooks __rcu *nf_nat_sip_hooks;EXPORT_SYMBOL_GPL (nf_nat_sip_hooks); static int string_len(const struct nf_conn *ct, const char *dptr,
net/netfilter/nf_conntrack_timeout.c +1 -1
@@ -22,7 +22,7 @@#include <net/netfilter/nf_conntrack_l4proto.h> #include <net/netfilter/nf_conntrack_timeout.h> -const struct nf_ct_timeout_hooks *nf_ct_timeout_hook__read_mostly ; +const struct nf_ct_timeout_hooks __rcu *nf_ct_timeout_hook__read_mostly ;EXPORT_SYMBOL_GPL (nf_ct_timeout_hook);static int untimeout (struct nf_conn *ct,void *timeout)
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 6/18 netfilter: nf_conntrack: use rcu accessors where needed
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Sparse complains about direct access to the 'helper' and timeout members. Both have __rcu annotation, so use the accessors.
xt_CT is fine, accesses occur before the structure is visible to other cpus. Switch to rcu accessors there as well to reduce noise.
--- net/netfilter/nf_conntrack_broadcast.c | 6 +++++- net/netfilter/nf_conntrack_helper.c | 2 +- net/netfilter/nf_conntrack_netlink.c | 9 +++++++-- net/netfilter/nf_conntrack_sip.c | 7 ++++++- net/netfilter/nf_conntrack_timeout.c | 16 +++++++++++++--- net/netfilter/nfnetlink_cthelper.c | 10 +++++++--- net/netfilter/xt_CT.c | 23 ++++++++++++++++++----- 7 files changed, 57 insertions(+), 16 deletions(-)
net/netfilter/nf_conntrack_broadcast.c +5 -1
@@ -20,6 +20,7 @@ int nf_conntrack_broadcast_help(struct sk_buff *skb, enum ip_conntrack_info ctinfo, unsigned int timeout) { +const struct nf_conntrack_helper *helper;struct nf_conntrack_expect *exp;struct iphdr *iph =ip_hdr (skb);struct rtable *rt =skb_rtable (skb);
@@ -58,7 +59,10 @@ int nf_conntrack_broadcast_help(struct sk_buff *skb, goto out; exp->tuple = ct->tuplehash[IP_CT_DIR_REPLY ].tuple; - exp->tuple.src.u.udp.port = help->helper->tuple.src.u.udp.port; + + helper =rcu_dereference (help->helper); +if (helper) + exp->tuple.src.u.udp.port = helper->tuple.src.u.udp.port; exp->mask.src.u3.ip = mask; exp->mask.src.u.udp.port =htons (0xFFFF );
net/netfilter/nf_conntrack_helper.c +1 -1
@@ -249,7 +249,7 @@ int __nf_ct_try_assign_helper(struct nf_conn *ct, struct nf_conn *tmpl,if (tmpl !=NULL ) { help =nfct_help (tmpl);if (help !=NULL ) { - helper = help->helper; + helper =rcu_dereference (help->helper);set_bit (IPS_HELPER_BIT , &ct->status); } }
net/netfilter/nf_conntrack_netlink.c +7 -2
@@ -2004,7 +2004,7 @@ static int ctnetlink_change_helper(struct nf_conn *ct, }if (help) { -if (help->helper == helper) { +if (rcu_access_pointer (help->helper) == helper) {/* update private helper data if allowed. */ if (helper->from_nlattr) helper->from_nlattr (helpinfo, ct);
@@ -3412,12 +3412,17 @@ static int ctnetlink_get_expect(struct sk_buff *skb,static bool expect_iter_name (struct nf_conntrack_expect *exp,void *data) { +struct nf_conntrack_helper *helper;const struct nf_conn_help *m_help;const char *name = data; m_help =nfct_help (exp->master); -return strcmp (m_help->helper->name, name) ==0 ; + helper =rcu_dereference (m_help->helper); +if (!helper) +return false; + +return strcmp (helper->name, name) ==0 ; }static bool expect_iter_all (struct nf_conntrack_expect *exp,void *data)
net/netfilter/nf_conntrack_sip.c +6 -1
@@ -1229,6 +1229,7 @@ static int process_register_request(struct sk_buff *skb, unsigned int protoff,struct nf_conntrack_expect *exp;union nf_inet_addr *saddr, daddr;const struct nf_nat_sip_hooks *hooks; +struct nf_conntrack_helper *helper;__be16 port;u8 proto;unsigned int expires =0 ;
@@ -1289,10 +1290,14 @@ static int process_register_request(struct sk_buff *skb, unsigned int protoff,if (sip_direct_signalling) saddr = &ct->tuplehash[!dir].tuple.src.u3; + helper =rcu_dereference (nfct_help (ct)->helper); +if (!helper) +return NF_DROP ; +nf_ct_expect_init (exp,SIP_EXPECT_SIGNALLING ,nf_ct_l3num (ct), saddr, &daddr, proto,NULL , &port); exp->timeout.expires = sip_timeout *HZ ; - exp->helper =nfct_help (ct)->helper; + exp->helper = helper; exp->flags =NF_CT_EXPECT_PERMANENT |NF_CT_EXPECT_INACTIVE ; hooks =rcu_dereference (nf_nat_sip_hooks);
net/netfilter/nf_conntrack_timeout.c +13 -3
@@ -29,8 +29,14 @@ static int untimeout(struct nf_conn *ct, void *timeout) {struct nf_conn_timeout *timeout_ext =nf_ct_timeout_find (ct); -if (timeout_ext && (!timeout || timeout_ext->timeout == timeout)) -RCU_INIT_POINTER (timeout_ext->timeout,NULL ); +if (timeout_ext) { +const struct nf_ct_timeout *t; + + t =rcu_access_pointer (timeout_ext->timeout); + +if (!timeout || t == timeout) +RCU_INIT_POINTER (timeout_ext->timeout,NULL ); + }/* We are not intended to delete this conntrack. */ return 0 ;
@@ -127,7 +133,11 @@ void nf_ct_destroy_timeout(struct nf_conn *ct)if (h) { timeout_ext =nf_ct_timeout_find (ct);if (timeout_ext) { - h->timeout_put (timeout_ext->timeout); +struct nf_ct_timeout *t; + + t =rcu_dereference (timeout_ext->timeout); +if (t) + h->timeout_put (t);RCU_INIT_POINTER (timeout_ext->timeout,NULL ); } }
net/netfilter/nfnetlink_cthelper.c +7 -3
@@ -96,11 +96,13 @@ static int nfnl_cthelper_from_nlattr(struct nlattr *attr, struct nf_conn *ct) { struct nf_conn_help *help = nfct_help(ct); +const struct nf_conntrack_helper *helper;if (attr ==NULL )return -EINVAL ; -if (help->helper->data_len ==0 ) + helper =rcu_dereference (help->helper); +if (!helper || helper->data_len ==0 )return -EINVAL ;nla_memcpy (help->data, attr,sizeof (help->data));
@@ -111,9 +113,11 @@ static int nfnl_cthelper_to_nlattr(struct sk_buff *skb, const struct nf_conn *ct) { const struct nf_conn_help *help = nfct_help(ct); +const struct nf_conntrack_helper *helper; -if (help->helper->data_len && -nla_put (skb,CTA_HELP_INFO , help->helper->data_len, &help->data)) + helper =rcu_dereference (help->helper); +if (helper && helper->data_len && +nla_put (skb,CTA_HELP_INFO , helper->data_len, &help->data)) goto nla_put_failure;return 0 ;
net/netfilter/xt_CT.c +18 -5
@@ -96,7 +96,7 @@ xt_ct_set_helper(struct nf_conn *ct, const char *helper_name,return -ENOMEM ; } - help->helper = helper; +rcu_assign_pointer (help->helper, helper);return 0 ; }
@@ -136,6 +136,21 @@ static u16 xt_ct_flags_to_dir(const struct xt_ct_target_info_v1 *info) } } +static void xt_ct_put_helper (struct nf_conn_help *help) +{ +struct nf_conntrack_helper *helper; + +if (!help) +return ; + +/* not yet exposed to other cpus, or ruleset +* already detached (post-replacement). +*/ + helper =rcu_dereference_raw (help->helper); +if (helper) +nf_conntrack_helper_put (helper); +} +static int xt_ct_tg_check (const struct xt_tgchk_param *par,struct xt_ct_target_info_v1 *info) {
@@ -207,8 +222,7 @@ static int xt_ct_tg_check(const struct xt_tgchk_param *par, err4: help =nfct_help (ct); -if (help) -nf_conntrack_helper_put (help->helper); +xt_ct_put_helper (help); err3:nf_ct_tmpl_free (ct); err2:
@@ -270,8 +284,7 @@ static void xt_ct_tg_destroy(const struct xt_tgdtor_param *par,if (ct) { help =nfct_help (ct); -if (help) -nf_conntrack_helper_put (help->helper); +xt_ct_put_helper (help);nf_ct_netns_put (par->net, par->family);
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 7/18 netfilter: h323: merge nat hook pointers into one
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
sparse complains about incorrect rcu usage.
Code uses the correct rcu access primitives, but the function pointers lack rcu annotations.
Collapse all of them into a single structure, then annotate the pointer.
--- include/linux/netfilter/nf_conntrack_h323.h | 109 ++++---- net/ipv4/netfilter/nf_nat_h323.c | 42 ++-- net/netfilter/nf_conntrack_h323_main.c | 260 ++++++++------------ 3 files changed, 169 insertions(+), 242 deletions(-)
include/linux/netfilter/nf_conntrack_h323.h +56 -53
@@ -38,60 +38,63 @@ void nf_conntrack_h245_expect(struct nf_conn *new, struct nf_conntrack_expect *this);void nf_conntrack_q931_expect (struct nf_conn *new,struct nf_conntrack_expect *this); -extern int (*set_h245_addr_hook) (struct sk_buff *skb,unsigned int protoff, -unsigned char **data,int dataoff, -H245_TransportAddress *taddr, -union nf_inet_addr *addr, -__be16 port); -extern int (*set_h225_addr_hook) (struct sk_buff *skb,unsigned int protoff, -unsigned char **data,int dataoff, -TransportAddress *taddr, -union nf_inet_addr *addr, -__be16 port); -extern int (*set_sig_addr_hook) (struct sk_buff *skb, -struct nf_conn *ct, -enum ip_conntrack_info ctinfo, -unsigned int protoff,unsigned char **data, -TransportAddress *taddr,int count); -extern int (*set_ras_addr_hook) (struct sk_buff *skb, -struct nf_conn *ct, -enum ip_conntrack_info ctinfo, -unsigned int protoff,unsigned char **data, -TransportAddress *taddr,int count); -extern int (*nat_rtp_rtcp_hook) (struct sk_buff *skb, -struct nf_conn *ct, -enum ip_conntrack_info ctinfo, -unsigned int protoff,unsigned char **data, -int dataoff, -H245_TransportAddress *taddr, -__be16 port,__be16 rtp_port, -struct nf_conntrack_expect *rtp_exp, -struct nf_conntrack_expect *rtcp_exp); -extern int (*nat_t120_hook) (struct sk_buff *skb,struct nf_conn *ct, -enum ip_conntrack_info ctinfo, -unsigned int protoff, + +struct nfct_h323_nat_hooks { +int (*set_h245_addr)(struct sk_buff *skb,unsigned int protoff,unsigned char **data,int dataoff, -H245_TransportAddress *taddr,__be16 port, -struct nf_conntrack_expect *exp); -extern int (*nat_h245_hook) (struct sk_buff *skb,struct nf_conn *ct, -enum ip_conntrack_info ctinfo, -unsigned int protoff, +H245_TransportAddress *taddr, +union nf_inet_addr *addr,__be16 port); +int (*set_h225_addr)(struct sk_buff *skb,unsigned int protoff,unsigned char **data,int dataoff, -TransportAddress *taddr,__be16 port, -struct nf_conntrack_expect *exp); -extern int (*nat_callforwarding_hook) (struct sk_buff *skb, -struct nf_conn *ct, -enum ip_conntrack_info ctinfo, -unsigned int protoff, -unsigned char **data,int dataoff, -TransportAddress *taddr, -__be16 port, -struct nf_conntrack_expect *exp); -extern int (*nat_q931_hook) (struct sk_buff *skb,struct nf_conn *ct, -enum ip_conntrack_info ctinfo, -unsigned int protoff, -unsigned char **data,TransportAddress *taddr, -int idx,__be16 port, -struct nf_conntrack_expect *exp); +TransportAddress *taddr, +union nf_inet_addr *addr,__be16 port); +int (*set_sig_addr)(struct sk_buff *skb, +struct nf_conn *ct, +enum ip_conntrack_info ctinfo, +unsigned int protoff,unsigned char **data, +TransportAddress *taddr,int count); +int (*set_ras_addr)(struct sk_buff *skb, +struct nf_conn *ct, +enum ip_conntrack_info ctinfo, +unsigned int protoff,unsigned char **data, +TransportAddress *taddr,int count); +int (*nat_rtp_rtcp)(struct sk_buff *skb, +struct nf_conn *ct, +enum ip_conntrack_info ctinfo, +unsigned int protoff, +unsigned char **data,int dataoff, +H245_TransportAddress *taddr, +__be16 port,__be16 rtp_port, +struct nf_conntrack_expect *rtp_exp, +struct nf_conntrack_expect *rtcp_exp); +int (*nat_t120)(struct sk_buff *skb, +struct nf_conn *ct, +enum ip_conntrack_info ctinfo, +unsigned int protoff, +unsigned char **data,int dataoff, +H245_TransportAddress *taddr,__be16 port, +struct nf_conntrack_expect *exp); +int (*nat_h245)(struct sk_buff *skb, +struct nf_conn *ct, +enum ip_conntrack_info ctinfo, +unsigned int protoff, +unsigned char **data,int dataoff, +TransportAddress *taddr,__be16 port, +struct nf_conntrack_expect *exp); +int (*nat_callforwarding)(struct sk_buff *skb, +struct nf_conn *ct, +enum ip_conntrack_info ctinfo, +unsigned int protoff, +unsigned char **data,int dataoff, +TransportAddress *taddr,__be16 port, +struct nf_conntrack_expect *exp); +int (*nat_q931)(struct sk_buff *skb, +struct nf_conn *ct, +enum ip_conntrack_info ctinfo, +unsigned int protoff, +unsigned char **data,TransportAddress *taddr,int idx, +__be16 port,struct nf_conntrack_expect *exp); +}; +extern const struct nfct_h323_nat_hooks __rcu *nfct_h323_nat_hook;#endif
net/ipv4/netfilter/nf_nat_h323.c +14 -28
57 lines not on this page · raw message
net/netfilter/nf_conntrack_h323_main.c +99 -161
540 lines not on this page · raw message
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 8/18 netfilter: nft_set_bitmap: Fix spelling mistake
In reply to Pablo Neira AyusoFrom: Zhang Jiaming <[email protected]>
Change 'succesful' to 'successful'.
Change 'transation' to 'transaction'.
--- net/netfilter/nft_set_bitmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nft_set_bitmap.c +2 -2
@@ -21,7 +21,7 @@ struct nft_bitmap_elem {* the element state in the current and the future generation. * * An element can be in three states. The generation cursor is represented using -* the ^ character, note that this cursor shifts on every succesful transaction. +* the ^ character, note that this cursor shifts on every successful transaction. * If no transaction is going on, we observe all elements are in the following * state: *
@@ -39,7 +39,7 @@ struct nft_bitmap_elem {* 10 = this element is active in the current generation and it becomes inactive * ^ in the next one. This happens when the element is deactivated but commit * path has not yet been executed yet, so removal is still pending. On -* transation abortion, the next generation bit is reset to go back to +* transaction abortion, the next generation bit is reset to go back to * restore its previous state. */ struct nft_bitmap {
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 9/18 netfilter: nfnetlink: add missing __be16 cast
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Sparse flags this as suspicious, because this compares integer with a be16 with no conversion.
Its a compat check for old userspace that sends host byte order, so force a be16 cast here.
--- net/netfilter/nfnetlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nfnetlink.c +1 -1
@@ -626,7 +626,7 @@ static void nfnetlink_rcv_skb_batch(struct sk_buff *skb, struct nlmsghdr *nlh) nfgenmsg =nlmsg_data (nlh);skb_pull (skb, msglen);/* Work around old nft using host byte order */ -if (nfgenmsg->res_id ==NFNL_SUBSYS_NFTABLES ) +if (nfgenmsg->res_id == (__force __be16 )NFNL_SUBSYS_NFTABLES ) res_id =NFNL_SUBSYS_NFTABLES ;else res_id =ntohs (nfgenmsg->res_id);
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 10/18 netfilter: x_tables: use correct integer types
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Sparse complains because __be32 and u32 are mixed without conversions. Use the correct types, no code changes.
Furthermore, xt_DSCP generates a bit truncation warning:
"cast truncates bits from constant value (ffffff03 becomes 3)"
The truncation is fine (and wanted). Add a private definition and use that instead.
objdiff shows no changes.
--- net/netfilter/xt_DSCP.c | 8 ++++---- net/netfilter/xt_TCPMSS.c | 4 ++-- net/netfilter/xt_connlimit.c | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-)
net/netfilter/xt_DSCP.c +4 -4
@@ -24,6 +24,8 @@ MODULE_ALIAS("ip6t_DSCP");MODULE_ALIAS ("ipt_TOS" );MODULE_ALIAS ("ip6t_TOS" ); +#define XT_DSCP_ECN_MASK 3u +static unsigned int dscp_tg (struct sk_buff *skb,const struct xt_action_param *par) {
@@ -34,8 +36,7 @@ dscp_tg(struct sk_buff *skb, const struct xt_action_param *par)if (skb_ensure_writable (skb,sizeof (struct iphdr )))return NF_DROP ; -ipv4_change_dsfield (ip_hdr (skb), - (__force __u8)(~XT_DSCP_MASK ), +ipv4_change_dsfield (ip_hdr (skb),XT_DSCP_ECN_MASK , dinfo->dscp <<XT_DSCP_SHIFT ); }
@@ -52,8 +53,7 @@ dscp_tg6(struct sk_buff *skb, const struct xt_action_param *par)if (skb_ensure_writable (skb,sizeof (struct ipv6hdr )))return NF_DROP ; -ipv6_change_dsfield (ipv6_hdr (skb), - (__force __u8)(~XT_DSCP_MASK ), +ipv6_change_dsfield (ipv6_hdr (skb),XT_DSCP_ECN_MASK , dinfo->dscp <<XT_DSCP_SHIFT ); }return XT_CONTINUE ;
net/netfilter/xt_TCPMSS.c +2 -2
@@ -239,8 +239,8 @@ tcpmss_tg6(struct sk_buff *skb, const struct xt_action_param *par) oldlen = ipv6h->payload_len; newlen =htons (ntohs (oldlen) + ret);if (skb->ip_summed ==CHECKSUM_COMPLETE ) - skb->csum =csum_add (csum_sub (skb->csum, oldlen), - newlen); + skb->csum =csum_add (csum_sub (skb->csum, (__force __wsum )oldlen), + (__force __wsum )newlen); ipv6h->payload_len = newlen; }return XT_CONTINUE ;
net/netfilter/xt_connlimit.c +3 -3
@@ -62,10 +62,10 @@ connlimit_mt(const struct sk_buff *skb, struct xt_action_param *par) key[4 ] = zone->id; }else {const struct iphdr *iph =ip_hdr (skb); - key[0 ] = (info->flags &XT_CONNLIMIT_DADDR ) ? - iph->daddr : iph->saddr; - key[0 ] &= info->mask.ip; + key[0 ] = (info->flags &XT_CONNLIMIT_DADDR ) ? + (__force __u32 )iph->daddr : (__force __u32 )iph->saddr; + key[0 ] &= (__force __u32 )info->mask.ip; key[1 ] = zone->id; }
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 11/18 netfilter: nf_tables: use the correct get/put helpers
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Switch to be16/32 and u16/32 respectively. No code changes here, the functions do the same thing, this is just for sparse checkers' sake.
objdiff shows no changes.
--- net/netfilter/nft_byteorder.c | 3 ++- net/netfilter/nft_osf.c | 2 +- net/netfilter/nft_socket.c | 8 ++++---- net/netfilter/nft_xfrm.c | 8 ++++---- 4 files changed, 11 insertions(+), 10 deletions(-)
net/netfilter/nft_byteorder.c +2 -1
@@ -44,7 +44,8 @@ void nft_byteorder_eval(const struct nft_expr *expr,case NFT_BYTEORDER_NTOH :for (i =0 ; i < priv->len /8 ; i++) { src64 =nft_reg_load64 (&src[i]); -nft_reg_store64 (&dst[i],be64_to_cpu (src64)); +nft_reg_store64 (&dst[i], +be64_to_cpu ((__force __be64 )src64)); }break ;case NFT_BYTEORDER_HTON :
net/netfilter/nft_osf.c +1 -1
@@ -99,7 +99,7 @@ static int nft_osf_dump(struct sk_buff *skb, const struct nft_expr *expr)if (nla_put_u8 (skb,NFTA_OSF_TTL , priv->ttl)) goto nla_put_failure; -if (nla_put_be32 (skb,NFTA_OSF_FLAGS ,ntohl (priv->flags))) +if (nla_put_u32 (skb,NFTA_OSF_FLAGS ,ntohl ((__force __be32 )priv->flags))) goto nla_put_failure;if (nft_dump_register (skb,NFTA_OSF_DREG , priv->dreg))
net/netfilter/nft_socket.c +4 -4
@@ -163,7 +163,7 @@ static int nft_socket_init(const struct nft_ctx *ctx,return -EOPNOTSUPP ; } - priv->key =ntohl (nla_get_u32 (tb[NFTA_SOCKET_KEY ])); + priv->key =ntohl (nla_get_be32 (tb[NFTA_SOCKET_KEY ]));switch (priv->key) {case NFT_SOCKET_TRANSPARENT :case NFT_SOCKET_WILDCARD :
@@ -179,7 +179,7 @@ static int nft_socket_init(const struct nft_ctx *ctx,if (!tb[NFTA_SOCKET_LEVEL ])return -EINVAL ; - level =ntohl (nla_get_u32 (tb[NFTA_SOCKET_LEVEL ])); + level =ntohl (nla_get_be32 (tb[NFTA_SOCKET_LEVEL ]));if (level >255 )return -EOPNOTSUPP ;
@@ -202,12 +202,12 @@ static int nft_socket_dump(struct sk_buff *skb, {const struct nft_socket *priv =nft_expr_priv (expr); -if (nla_put_u32 (skb,NFTA_SOCKET_KEY ,htonl (priv->key))) +if (nla_put_be32 (skb,NFTA_SOCKET_KEY ,htonl (priv->key)))return -1 ;if (nft_dump_register (skb,NFTA_SOCKET_DREG , priv->dreg))return -1 ;if (priv->key ==NFT_SOCKET_CGROUPV2 && -nla_put_u32 (skb,NFTA_SOCKET_LEVEL ,htonl (priv->level))) +nla_put_be32 (skb,NFTA_SOCKET_LEVEL ,htonl (priv->level)))return -1 ;return 0 ; }
net/netfilter/nft_xfrm.c +4 -4
@@ -51,7 +51,7 @@ static int nft_xfrm_get_init(const struct nft_ctx *ctx,return -EOPNOTSUPP ; } - priv->key =ntohl (nla_get_u32 (tb[NFTA_XFRM_KEY ])); + priv->key =ntohl (nla_get_be32 (tb[NFTA_XFRM_KEY ]));switch (priv->key) {case NFT_XFRM_KEY_REQID :case NFT_XFRM_KEY_SPI :
@@ -134,13 +134,13 @@ static void nft_xfrm_state_get_key(const struct nft_xfrm *priv,WARN_ON_ONCE (1 );break ;case NFT_XFRM_KEY_DADDR_IP4 : - *dest = state->id.daddr.a4; + *dest = (__force __u32 )state->id.daddr.a4;return ;case NFT_XFRM_KEY_DADDR_IP6 :memcpy (dest, &state->id.daddr.in6,sizeof (struct in6_addr ));return ;case NFT_XFRM_KEY_SADDR_IP4 : - *dest = state->props.saddr.a4; + *dest = (__force __u32 )state->props.saddr.a4;return ;case NFT_XFRM_KEY_SADDR_IP6 :memcpy (dest, &state->props.saddr.in6,sizeof (struct in6_addr ));
@@ -149,7 +149,7 @@ static void nft_xfrm_state_get_key(const struct nft_xfrm *priv, *dest = state->props.reqid;return ;case NFT_XFRM_KEY_SPI : - *dest = state->id.spi; + *dest = (__force __u32 )state->id.spi;return ; }
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 12/18 netfilter: nf_tables: add and use BE register load-store helpers
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Same as the existing ones, no conversions. This is just for sparse sake only so that we no longer mix be16/u16 and be32/u32 types.
Alternative is to add __force __beX in various places, but this seems nicer.
objdiff shows no changes.
--- include/net/netfilter/nf_tables.h | 15 +++++++++++++++ net/bridge/netfilter/nft_meta_bridge.c | 2 +- net/netfilter/nft_tproxy.c | 6 +++--- 3 files changed, 19 insertions(+), 4 deletions(-)
include/net/netfilter/nf_tables.h +15 -0
@@ -157,11 +157,26 @@ static inline void nft_reg_store16(u32 *dreg, u16 val) *(u16 *)dreg = val; } +static inline void nft_reg_store_be16 (u32 *dreg,__be16 val) +{ +nft_reg_store16 (dreg, (__force __u16 )val); +} +static inline u16 nft_reg_load16 (const u32 *sreg) {return *(u16 *)sreg; } +static inline __be16 nft_reg_load_be16 (const u32 *sreg) +{ +return (__force __be16 )nft_reg_load16 (sreg); +} + +static inline __be32 nft_reg_load_be32 (const u32 *sreg) +{ +return *(__force __be32 *)sreg; +} +static inline void nft_reg_store64 (u32 *dreg,u64 val) {put_unaligned (val, (u64 *)dreg);
net/bridge/netfilter/nft_meta_bridge.c +1 -1
@@ -53,7 +53,7 @@ static void nft_meta_bridge_get_eval(const struct nft_expr *expr, goto err;br_vlan_get_proto (br_dev, &p_proto); -nft_reg_store16 (dest,htons (p_proto)); +nft_reg_store_be16 (dest,htons (p_proto));return ; }default :
net/netfilter/nft_tproxy.c +3 -3
@@ -52,11 +52,11 @@ static void nft_tproxy_eval_v4(const struct nft_expr *expr, skb->dev, NF_TPROXY_LOOKUP_ESTABLISHED);if (priv->sreg_addr) - taddr = regs->data[priv->sreg_addr]; + taddr =nft_reg_load_be32 (®s->data[priv->sreg_addr]); taddr =nf_tproxy_laddr4 (skb, taddr, iph->daddr);if (priv->sreg_port) - tport =nft_reg_load16 (®s->data[priv->sreg_port]); + tport =nft_reg_load_be16 (®s->data[priv->sreg_port]);if (!tport) tport = hp->dest;
@@ -124,7 +124,7 @@ static void nft_tproxy_eval_v6(const struct nft_expr *expr, taddr = *nf_tproxy_laddr6 (skb, &taddr, &iph->daddr);if (priv->sreg_port) - tport =nft_reg_load16 (®s->data[priv->sreg_port]); + tport =nft_reg_load_be16 (®s->data[priv->sreg_port]);if (!tport) tport = hp->dest;
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 13/18 netfilter: nf_tables: use correct integer types
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Sparse tool complains about mixing of different endianess types, so use the correct ones.
Add type casts where needed.
objdiff shows no changes except in nft_tunnel (type is changed).
--- net/netfilter/nft_cmp.c | 6 +++--- net/netfilter/nft_ct.c | 4 ++-- net/netfilter/nft_exthdr.c | 10 +++++----- net/netfilter/nft_tunnel.c | 3 ++- 4 files changed, 12 insertions(+), 11 deletions(-)
net/netfilter/nft_cmp.c +3 -3
@@ -125,13 +125,13 @@ static void nft_payload_n2h(union nft_cmp_offload_data *data, {switch (len) {case 2 : - data->val16 =ntohs (*((u16 *)val)); + data->val16 =ntohs (*((__be16 *)val));break ;case 4 : - data->val32 =ntohl (*((u32 *)val)); + data->val32 =ntohl (*((__be32 *)val));break ;case 8 : - data->val64 =be64_to_cpu (*((u64 *)val)); + data->val64 =be64_to_cpu (*((__be64 *)val));break ;default :WARN_ON_ONCE (1 );
net/netfilter/nft_ct.c +2 -2
@@ -204,12 +204,12 @@ static void nft_ct_get_eval(const struct nft_expr *expr,case NFT_CT_SRC_IP :if (nf_ct_l3num (ct) !=NFPROTO_IPV4 ) goto err; - *dest = tuple->src.u3.ip; + *dest = (__force __u32 )tuple->src.u3.ip;return ;case NFT_CT_DST_IP :if (nf_ct_l3num (ct) !=NFPROTO_IPV4 ) goto err; - *dest = tuple->dst.u3.ip; + *dest = (__force __u32 )tuple->dst.u3.ip;return ;case NFT_CT_SRC_IP6 :if (nf_ct_l3num (ct) !=NFPROTO_IPV6 )
net/netfilter/nft_exthdr.c +5 -5
@@ -266,7 +266,7 @@ static void nft_exthdr_tcp_set_eval(const struct nft_expr *expr,switch (priv->len) {case 2 : - old.v16 =get_unaligned ((u16 *)(opt + offset)); + old.v16 = (__force __be16 )get_unaligned ((u16 *)(opt + offset)); new.v16 = (__force __be16 )nft_reg_load16 ( ®s->data[priv->sreg]);
@@ -281,18 +281,18 @@ static void nft_exthdr_tcp_set_eval(const struct nft_expr *expr,if (old.v16 == new.v16)return ; -put_unaligned (new.v16, (u16 *)(opt + offset)); +put_unaligned (new.v16, (__be16 *)(opt + offset));inet_proto_csum_replace2 (&tcph->check, pkt->skb, old.v16, new.v16, false);break ;case 4 : - new.v32 = regs->data[priv->sreg]; - old.v32 =get_unaligned ((u32 *)(opt + offset)); + new.v32 =nft_reg_load_be32 (®s->data[priv->sreg]); + old.v32 = (__force __be32 )get_unaligned ((u32 *)(opt + offset));if (old.v32 == new.v32)return ; -put_unaligned (new.v32, (u32 *)(opt + offset)); +put_unaligned (new.v32, (__be32 *)(opt + offset));inet_proto_csum_replace4 (&tcph->check, pkt->skb, old.v32, new.v32, false);break ;
net/netfilter/nft_tunnel.c +2 -1
@@ -383,8 +383,9 @@ static int nft_tunnel_obj_opts_init(const struct nft_ctx *ctx,struct ip_tunnel_info *info, struct nft_tunnel_opts *opts) { - int err, rem, type = 0; struct nlattr *nla; +__be16 type =0 ; +int err, rem; err =nla_validate_nested_deprecated (attr,NFTA_TUNNEL_KEY_OPTS_MAX , nft_tunnel_opts_policy,NULL );
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 14/18 netfilter: nf_tables: move nft_cmp_fast_mask to where its used
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
... and cast result to u32 so sparse won't complain anymore.
--- include/net/netfilter/nf_tables_core.h | 10 ---------- net/netfilter/nft_cmp.c | 12 ++++++++++++ 2 files changed, 12 insertions(+), 10 deletions(-)
include/net/netfilter/nf_tables_core.h +0 -10
@@ -56,16 +56,6 @@ struct nft_immediate_expr {u8 dlen; }; -/* Calculate the mask for the nft_cmp_fast expression. On big endian the -* mask needs to include the *upper* bytes when interpreting that data as -* something smaller than the full u32, therefore a cpu_to_le32 is done. -*/ -static inline u32 nft_cmp_fast_mask (unsigned int len) -{ - return cpu_to_le32(~0U >> (sizeof_field(struct nft_cmp_fast_expr, - data) * BITS_PER_BYTE - len)); -} -extern const struct nft_expr_ops nft_cmp_fast_ops;extern const struct nft_expr_ops nft_cmp16_fast_ops;
net/netfilter/nft_cmp.c +12 -0
@@ -197,6 +197,18 @@ static const struct nft_expr_ops nft_cmp_ops = { .offload = nft_cmp_offload, }; +/* Calculate the mask for the nft_cmp_fast expression. On big endian the +* mask needs to include the *upper* bytes when interpreting that data as +* something smaller than the full u32, therefore a cpu_to_le32 is done. +*/ +static u32 nft_cmp_fast_mask (unsigned int len) +{ + __le32 mask = cpu_to_le32(~0U >> (sizeof_field(struct nft_cmp_fast_expr, + data) * BITS_PER_BYTE - len)); + +return (__force u32 )mask; +} +static int nft_cmp_fast_init (const struct nft_ctx *ctx,const struct nft_expr *expr,const struct nlattr *const tb[])
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 15/18 netfilter: nf_nat: in nf_nat_initialized(), use const struct nf_conn *
In reply to Pablo Neira AyusoFrom: James Yonan <[email protected]>
nf_nat_initialized() doesn't modify passed struct nf_conn, so declare as const.
This is helpful for code readability and makes it possible to call nf_nat_initialized() with a const struct nf_conn *.
--- include/net/netfilter/nf_nat.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/netfilter/nf_nat.h +1 -1
@@ -104,7 +104,7 @@ unsigned int nf_nat_inet_fn(void *priv, struct sk_buff *skb, const struct nf_hook_state *state); -static inline int nf_nat_initialized (struct nf_conn *ct, +static inline int nf_nat_initialized (const struct nf_conn *ct,enum nf_nat_manip_type manip) {if (manip ==NF_NAT_MANIP_SRC )
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 16/18 netfilter: ipvs: Use the bitmap API to allocate bitmaps
In reply to Pablo Neira AyusoFrom: Christophe JAILLET <[email protected]>
Use bitmap_zalloc()/bitmap_free() instead of hand-writing them.
It is less verbose and it improves the semantic.
--- net/netfilter/ipvs/ip_vs_mh.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
net/netfilter/ipvs/ip_vs_mh.c +2 -3
@@ -174,8 +174,7 @@ static int ip_vs_mh_populate(struct ip_vs_mh_state *s,return 0 ; } - table =kcalloc (BITS_TO_LONGS (IP_VS_MH_TAB_SIZE ), -sizeof (unsigned long ),GFP_KERNEL ); + table =bitmap_zalloc (IP_VS_MH_TAB_SIZE ,GFP_KERNEL );if (!table)return -ENOMEM ;
@@ -227,7 +226,7 @@ static int ip_vs_mh_populate(struct ip_vs_mh_state *s, } out: -kfree (table); +bitmap_free (table);return 0 ; }
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 17/18 netfilter: flowtable: prefer refcount_inc
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
With refcount_inc_not_zero, we'd also need a smp_rmb or similar, followed by a test of the CONFIRMED bit.
However, the ct pointer is taken from skb->_nfct, its refcount must not be 0 (else, we'd already have a use-after-free bug).
Use refcount_inc() instead to clarify the ct refcount is expected to be at least 1.
--- net/netfilter/nf_flow_table_core.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
net/netfilter/nf_flow_table_core.c +3 -8
@@ -53,14 +53,14 @@ struct flow_offload *flow_offload_alloc(struct nf_conn *ct) {struct flow_offload *flow; -if (unlikely (nf_ct_is_dying (ct) || - !refcount_inc_not_zero (&ct->ct_general.use))) +if (unlikely (nf_ct_is_dying (ct)))return NULL ; flow =kzalloc (sizeof (*flow),GFP_ATOMIC );if (!flow) - goto err_ct_refcnt; +return NULL ; +refcount_inc (&ct->ct_general.use); flow->ct = ct;flow_offload_fill_dir (flow,FLOW_OFFLOAD_DIR_ORIGINAL );
@@ -72,11 +72,6 @@ struct flow_offload *flow_offload_alloc(struct nf_conn *ct)__set_bit (NF_FLOW_DNAT , &flow->flags);return flow; - -err_ct_refcnt: -nf_ct_put (ct); - -return NULL ; }EXPORT_SYMBOL_GPL (flow_offload_alloc);
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 18/18 netfilter: xt_TPROXY: remove pr_debug invocations
In reply to Pablo Neira AyusoFrom: Justin Stitt <[email protected]>
pr_debug calls are no longer needed in this file.
Pablo suggested "a patch to remove these pr_debug calls". This patch has some other beneficial collateral as it also silences multiple Clang -Wformat warnings that were present in the pr_debug calls.
diff from v1 -> v2:
* converted if statement one-liner style
* x == NULL is now !x
--- net/netfilter/xt_TPROXY.c | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-)
net/netfilter/xt_TPROXY.c +2 -23
@@ -74,18 +74,10 @@ tproxy_tg4(struct net *net, struct sk_buff *skb, __be32 laddr, __be16 lport,/* This should be in a separate target, but we don't do multiple targets on the same rule yet */ skb->mark = (skb->mark & ~mark_mask) ^ mark_value; - -pr_debug ("redirecting: proto %hhu %pI4:%hu -> %pI4:%hu, mark: %x\n" , - iph->protocol, &iph->daddr,ntohs (hp->dest), - &laddr,ntohs (lport), skb->mark); -nf_tproxy_assign_sock (skb, sk);return NF_ACCEPT ; } -pr_debug ("no socket, dropping: proto %hhu %pI4:%hu -> %pI4:%hu, mark: %x\n" , - iph->protocol, &iph->saddr,ntohs (hp->source), - &iph->daddr,ntohs (hp->dest), skb->mark);return NF_DROP ; }
@@ -122,16 +114,12 @@ tproxy_tg6_v1(struct sk_buff *skb, const struct xt_action_param *par)int tproto; tproto =ipv6_find_hdr (skb, &thoff,-1 ,NULL ,NULL ); -if (tproto <0 ) { -pr_debug ("unable to find transport header in IPv6 packet, dropping\n" ); +if (tproto <0 )return NF_DROP ; - } hp =skb_header_pointer (skb, thoff,sizeof (_hdr), &_hdr); -if (hp ==NULL ) { -pr_debug ("unable to grab transport header contents in IPv6 packet, dropping\n" ); +if (!hp)return NF_DROP ; - }/* check if there's an ongoing connection on the packet * addresses, this happens if the redirect already happened
@@ -168,19 +156,10 @@ tproxy_tg6_v1(struct sk_buff *skb, const struct xt_action_param *par)/* This should be in a separate target, but we don't do multiple targets on the same rule yet */ skb->mark = (skb->mark & ~tgi->mark_mask) ^ tgi->mark_value; - -pr_debug ("redirecting: proto %hhu %pI6:%hu -> %pI6:%hu, mark: %x\n" , - tproto, &iph->saddr,ntohs (hp->source), - laddr,ntohs (lport), skb->mark); -nf_tproxy_assign_sock (skb, sk);return NF_ACCEPT ; } -pr_debug ("no socket, dropping: proto %hhu %pI6:%hu -> %pI6:%hu, mark: %x\n" , - tproto, &iph->saddr,ntohs (hp->source), - &iph->daddr,ntohs (hp->dest), skb->mark); -return NF_DROP ; }
Signature · 1 line
2.30.2