netfilter: conntrack sparse annotations
Subsystems (2)
Florian Westphal
maintainerv2 cover netfilter: conntrack sparse annotations
This series reduces the number of generated sparse warnings in the netfilter codebase.
In some cases its just due to a missing '__rcu' annotation of the base pointer, but in some other cases there is a direct access to a __rcu annotated base pointer.
v2: keep unrelated EXPORT_SYMBOL in patch 3.
Florian Westphal (3):
netfilter: nf_conntrack: add missing __rcu annotations
netfilter: nf_conntrack: use rcu accessors where needed
netfilter: h323: merge nat hook pointers into one
include/linux/netfilter/nf_conntrack_h323.h | 109 ++++---- include/linux/netfilter/nf_conntrack_sip.h | 2 +- include/net/netfilter/nf_conntrack_timeout.h | 2 +- net/ipv4/netfilter/nf_nat_h323.c | 42 +-- net/netfilter/nf_conntrack_broadcast.c | 6 +- net/netfilter/nf_conntrack_h323_main.c | 259 +++++++------------ net/netfilter/nf_conntrack_helper.c | 2 +- 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/nfnetlink_cthelper.c | 10 +- net/netfilter/xt_CT.c | 23 +- 13 files changed, 230 insertions(+), 263 deletions(-)
Signature · 1 line
2.35.1
Florian Westphal
maintainerPATCH v2 1/3 netfilter: nf_conntrack: add missing __rcu annotations
Access to the hook pointers use correct helpers but the pointers lack the needed __rcu annotation.
---
no changes.
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.35.1
Florian Westphal
maintainerPATCH v2 2/3 netfilter: nf_conntrack: use rcu accessors where needed
In reply to Florian WestphalSparse 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.
---
no changes.
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.35.1
Florian Westphal
maintainerPATCH v2 3/3 netfilter: h323: merge nat hook pointers into one
In reply to Florian Westphalsparse 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.
---
keep EXPORT_SYMBOL_GPL(get_h225_addr), its not part of nfct_h323_nat_hooks, else link failure if conntrack_h323 is a module.
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.35.1
Pablo Neira Ayuso
maintainerQuoted 6 lines · Florian Westphal
This series reduces the number of generated sparse warnings in the netfilter codebase.
In some cases its just due to a missing '
__rcu' annotation of the base pointer, but in some other cases there is a direct access to a__rcuannotated base pointer.
Series applied, thanks