netfilter: replace raw warnings with
Subsystems (2)
cover netfilter: replace raw warnings with
This patch series replaces raw WARN_ON and WARN_ON_ONCE macros with DEBUG_NET_WARN_ON_ONCE across various netfilter subsystems.
Currently, several internal invariant checks use standard warnings on packet processing paths or control-plane loops. If triggered, these can trigger full system panics when panic_on_warn=1 is enabled. In most of these cases, the condition is already handled gracefully by dropping the packet, applying a defensive fallback, or returning a proper error code to userspace via netlink.
By migrating to DEBUG_NET_WARN_ON_ONCE, we preserve full stack trace diagnostic capability for developers running kernels compiled with CONFIG_DEBUG_NET=y, while protecting production environments from system panics.
Fernando Fernandez Mancera (9):
netfilter: xtables: use DEBUG_NET_WARN_ON_ONCE in packet and control
paths
netfilter: nf_tables: use DEBUG_NET_WARN_ON_ONCE in packet and control
paths
netfilter: nfnetlink: use DEBUG_NET_WARN_ON_ONCE for attribute
validation
netfilter: conntrack: use DEBUG_NET_WARN_ON_ONCE on packet paths
netfilter: nat: use DEBUG_NET_WARN_ON_ONCE in core and helper paths
netfilter: tproxy: use DEBUG_NET_WARN_ON_ONCE for protocol fallbacks
netfilter: bpf: use DEBUG_NET_WARN_ON_ONCE for missing BTF structures
netfilter: flowtable: use DEBUG_NET_WARN_ON_ONCE in offload path
netfilter: conncount: use DEBUG_NET_WARN_ON_ONCE on reaching count
limit
net/ipv4/netfilter/ip_tables.c | 6 ++-- net/ipv4/netfilter/iptable_nat.c | 4 ++- net/ipv4/netfilter/nf_nat_pptp.c | 16 +++++++--- net/ipv4/netfilter/nf_tproxy_ipv4.c | 2 +- net/ipv6/netfilter/ip6_tables.c | 6 ++-- net/ipv6/netfilter/ip6table_nat.c | 4 ++- net/ipv6/netfilter/nf_tproxy_ipv6.c | 2 +- net/netfilter/nf_bpf_link.c | 4 ++- net/netfilter/nf_conncount.c | 3 +- net/netfilter/nf_conntrack_core.c | 2 +- net/netfilter/nf_conntrack_extend.c | 3 +- net/netfilter/nf_conntrack_helper.c | 4 ++- net/netfilter/nf_conntrack_ovs.c | 2 +- net/netfilter/nf_conntrack_proto_icmp.c | 3 +- net/netfilter/nf_conntrack_seqadj.c | 2 +- net/netfilter/nf_conntrack_sip.c | 5 +++- net/netfilter/nf_flow_table_core.c | 4 +-- net/netfilter/nf_flow_table_ip.c | 4 +-- net/netfilter/nf_flow_table_offload.c | 4 +-- net/netfilter/nf_nat_core.c | 39 +++++++++++++++++-------- net/netfilter/nf_nat_masquerade.c | 6 ++-- net/netfilter/nf_nat_proto.c | 14 +++++---- net/netfilter/nf_nat_redirect.c | 5 ++-- net/netfilter/nf_tables_api.c | 38 +++++++++++++++++------- net/netfilter/nf_tables_core.c | 8 +++-- net/netfilter/nf_tables_offload.c | 2 +- net/netfilter/nf_tables_trace.c | 6 ++-- net/netfilter/nfnetlink.c | 4 ++- net/netfilter/nfnetlink_cttimeout.c | 3 +- net/netfilter/nft_ct.c | 2 +- net/netfilter/nft_ct_fast.c | 2 +- net/netfilter/nft_exthdr.c | 2 +- net/netfilter/nft_fib.c | 2 +- net/netfilter/nft_inner.c | 2 +- net/netfilter/nft_lookup.c | 2 +- net/netfilter/nft_masq.c | 2 +- net/netfilter/nft_meta.c | 10 +++---- net/netfilter/nft_payload.c | 6 ++-- net/netfilter/nft_redir.c | 2 +- net/netfilter/nft_reject.c | 8 +++-- net/netfilter/nft_rt.c | 2 +- net/netfilter/nft_set_hash.c | 2 +- net/netfilter/nft_set_pipapo.c | 2 +- net/netfilter/nft_set_rbtree.c | 6 ++-- net/netfilter/nft_socket.c | 8 +++-- net/netfilter/nft_tunnel.c | 2 +- net/netfilter/nft_xfrm.c | 6 ++-- net/netfilter/x_tables.c | 12 ++++++-- net/netfilter/xt_NETMAP.c | 4 --- net/netfilter/xt_cluster.c | 4 +-- net/netfilter/xt_nat.c | 30 +++++++++---------- net/netfilter/xt_socket.c | 3 +- 52 files changed, 203 insertions(+), 123 deletions(-)
Signature · 1 line
2.54.0
PATCH 1/9 netfilter: xtables: use DEBUG_NET_WARN_ON_ONCE in packet and control paths
Replace WARN_ON and WARN_ON_ONCE with DEBUG_NET_WARN_ON_ONCE in the xtables matching and target execution loops. This prevents unnecessary system panics when panic_on_warn=1 is enabled in production systems. Also, remove a redundant hook verification macro block in xt_NETMAP.c.
--- net/ipv4/netfilter/ip_tables.c | 6 +++--- net/ipv4/netfilter/iptable_nat.c | 4 +++- net/ipv6/netfilter/ip6_tables.c | 6 +++--- net/ipv6/netfilter/ip6table_nat.c | 4 +++- net/netfilter/x_tables.c | 12 +++++++++--- net/netfilter/xt_NETMAP.c | 4 ---- net/netfilter/xt_cluster.c | 4 ++-- net/netfilter/xt_nat.c | 30 +++++++++++++++--------------- net/netfilter/xt_socket.c | 3 ++- 9 files changed, 40 insertions(+), 33 deletions(-)
net/ipv4/netfilter/ip_tables.c +3 -3
@@ -254,7 +254,7 @@ ipt_do_table(void *priv, acpar.hotdrop = false; acpar.state = state; -WARN_ON (!(table->valid_hooks & (1 << hook))); +DEBUG_NET_WARN_ON_ONCE (!(table->valid_hooks & (1 << hook)));local_bh_disable (); addend =xt_write_recseq_begin (); private =READ_ONCE (table->private);/* Address dependency. */
@@ -279,7 +279,7 @@ ipt_do_table(void *priv,const struct xt_entry_match *ematch;struct xt_counters *counter; -WARN_ON (!e); +DEBUG_NET_WARN_ON_ONCE (!e);if (!ip_packet_match (ip, indev, outdev, &e->ip, acpar.fragoff)) { no_match:
@@ -298,7 +298,7 @@ ipt_do_table(void *priv,ADD_COUNTER (*counter, skb->len,1 ); t =ipt_get_target_c (e); -WARN_ON (!t->u.kernel.target); +DEBUG_NET_WARN_ON_ONCE (!t->u.kernel.target);#if IS_ENABLED (CONFIG_NETFILTER_XT_TARGET_TRACE )/* The packet is traced: log it */
net/ipv4/netfilter/iptable_nat.c +3 -1
@@ -65,8 +65,10 @@ static int ipt_nat_register_lookups(struct net *net) xt_nat_net =net_generic (net, iptable_nat_net_id); table =xt_find_table (net,NFPROTO_IPV4 ,"nat" ); -if (WARN_ON_ONCE (!table)) +if (unlikely (!table)) { +DEBUG_NET_WARN_ON_ONCE (1 );return -ENOENT ; + } ops =kmemdup (nf_nat_ipv4_ops,sizeof (nf_nat_ipv4_ops),GFP_KERNEL );if (!ops)
net/ipv6/netfilter/ip6_tables.c +3 -3
@@ -275,7 +275,7 @@ ip6t_do_table(void *priv, struct sk_buff *skb, acpar.hotdrop = false; acpar.state = state; -WARN_ON (!(table->valid_hooks & (1 << hook))); +DEBUG_NET_WARN_ON_ONCE (!(table->valid_hooks & (1 << hook)));local_bh_disable (); addend =xt_write_recseq_begin ();
@@ -301,7 +301,7 @@ ip6t_do_table(void *priv, struct sk_buff *skb,const struct xt_entry_match *ematch;struct xt_counters *counter; -WARN_ON (!e); +DEBUG_NET_WARN_ON_ONCE (!e); acpar.thoff =0 ;if (!ip6_packet_match (skb, indev, outdev, &e->ipv6, &acpar.thoff, &acpar.fragoff, &acpar.hotdrop)) {
@@ -321,7 +321,7 @@ ip6t_do_table(void *priv, struct sk_buff *skb,ADD_COUNTER (*counter, skb->len,1 ); t =ip6t_get_target_c (e); -WARN_ON (!t->u.kernel.target); +DEBUG_NET_WARN_ON_ONCE (!t->u.kernel.target);#if IS_ENABLED (CONFIG_NETFILTER_XT_TARGET_TRACE )/* The packet is traced: log it */
net/ipv6/netfilter/ip6table_nat.c +3 -1
@@ -66,8 +66,10 @@ static int ip6t_nat_register_lookups(struct net *net)int i, ret; table =xt_find_table (net,NFPROTO_IPV6 ,"nat" ); -if (WARN_ON_ONCE (!table)) +if (unlikely (!table)) { +DEBUG_NET_WARN_ON_ONCE (1 );return -ENOENT ; + } xt_nat_net =net_generic (net, ip6table_nat_net_id); ops =kmemdup (nf_nat_ipv6_ops,sizeof (nf_nat_ipv6_ops),GFP_KERNEL );
net/netfilter/x_tables.c +9 -3
@@ -714,8 +714,10 @@ int xt_compat_add_offset(u_int8_t af, unsigned int offset, int delta)WARN_ON (!mutex_is_locked (&xt[af].compat_mutex)); -if (WARN_ON (!xp->compat_tab)) +if (unlikely (!xp->compat_tab)) { +DEBUG_NET_WARN_ON_ONCE (1 );return -ENOMEM ; + }if (xp->cur >= xp->number)return -EINVAL ;
@@ -769,8 +771,10 @@ int xt_compat_init_offsets(u8 af, unsigned int number)if (!number || number > (INT_MAX /sizeof (struct compat_delta )))return -EINVAL ; -if (WARN_ON (xt[af].compat_tab)) +if (unlikely (xt[af].compat_tab)) { +DEBUG_NET_WARN_ON_ONCE (1 );return -EINVAL ; + } mem =sizeof (struct compat_delta ) * number;if (mem >XT_MAX_TABLE_SIZE )
@@ -1973,8 +1977,10 @@ int xt_register_template(const struct xt_table *table,mutex_lock (&xt[af].mutex);list_for_each_entry (t, &xt_templates[af], list) { -if (WARN_ON_ONCE (strcmp (table->name, t->name) ==0 )) +if (strcmp (table->name, t->name) ==0 ) { +DEBUG_NET_WARN_ON_ONCE (1 ); goto out_unlock; + } } ret = -ENOMEM ;
net/netfilter/xt_NETMAP.c +0 -4
@@ -74,10 +74,6 @@ netmap_tg4(struct sk_buff *skb, const struct xt_action_param *par)const struct nf_nat_ipv4_multi_range_compat *mr = par->targinfo;struct nf_nat_range2 newrange; -WARN_ON (xt_hooknum (par) !=NF_INET_PRE_ROUTING && -xt_hooknum (par) !=NF_INET_POST_ROUTING && -xt_hooknum (par) !=NF_INET_LOCAL_OUT && -xt_hooknum (par) !=NF_INET_LOCAL_IN ); ct =nf_ct_get (skb, &ctinfo); netmask = ~(mr->range[0 ].min_ip ^ mr->range[0 ].max_ip);
net/netfilter/xt_cluster.c +2 -2
@@ -49,7 +49,7 @@ xt_cluster_hash(const struct nf_conn *ct, hash =xt_cluster_hash_ipv6 (nf_ct_orig_ipv6_src (ct), info);break ;default : -WARN_ON (1 ); +DEBUG_NET_WARN_ON_ONCE (1 );break ; }
@@ -69,7 +69,7 @@ xt_cluster_is_multicast_addr(const struct sk_buff *skb, u_int8_t family) is_multicast =ipv6_addr_is_multicast (&ipv6_hdr (skb)->daddr);break ;default : -WARN_ON (1 ); +DEBUG_NET_WARN_ON_ONCE (1 );break ; }return is_multicast;
net/netfilter/xt_nat.c +15 -15
@@ -57,9 +57,9 @@ xt_snat_target_v0(struct sk_buff *skb, const struct xt_action_param *par)struct nf_conn *ct; ct =nf_ct_get (skb, &ctinfo); -WARN_ON (!(ct !=NULL && - (ctinfo ==IP_CT_NEW || ctinfo ==IP_CT_RELATED || - ctinfo ==IP_CT_RELATED_REPLY ))); +DEBUG_NET_WARN_ON_ONCE (!(ct !=NULL && + (ctinfo ==IP_CT_NEW || ctinfo ==IP_CT_RELATED || + ctinfo ==IP_CT_RELATED_REPLY )));xt_nat_convert_range (&range, &mr->range[0 ]);return nf_nat_setup_info (ct, &range,NF_NAT_MANIP_SRC );
@@ -74,8 +74,8 @@ xt_dnat_target_v0(struct sk_buff *skb, const struct xt_action_param *par)struct nf_conn *ct; ct =nf_ct_get (skb, &ctinfo); -WARN_ON (!(ct !=NULL && - (ctinfo ==IP_CT_NEW || ctinfo ==IP_CT_RELATED ))); +DEBUG_NET_WARN_ON_ONCE (!(ct !=NULL && + (ctinfo ==IP_CT_NEW || ctinfo ==IP_CT_RELATED )));xt_nat_convert_range (&range, &mr->range[0 ]);return nf_nat_setup_info (ct, &range,NF_NAT_MANIP_DST );
@@ -90,9 +90,9 @@ xt_snat_target_v1(struct sk_buff *skb, const struct xt_action_param *par)struct nf_conn *ct; ct =nf_ct_get (skb, &ctinfo); -WARN_ON (!(ct !=NULL && - (ctinfo ==IP_CT_NEW || ctinfo ==IP_CT_RELATED || - ctinfo ==IP_CT_RELATED_REPLY ))); +DEBUG_NET_WARN_ON_ONCE (!(ct !=NULL && + (ctinfo ==IP_CT_NEW || ctinfo ==IP_CT_RELATED || + ctinfo ==IP_CT_RELATED_REPLY )));memcpy (&range, range_v1,sizeof (*range_v1));memset (&range.base_proto,0 ,sizeof (range.base_proto));
@@ -109,8 +109,8 @@ xt_dnat_target_v1(struct sk_buff *skb, const struct xt_action_param *par)struct nf_conn *ct; ct =nf_ct_get (skb, &ctinfo); -WARN_ON (!(ct !=NULL && - (ctinfo ==IP_CT_NEW || ctinfo ==IP_CT_RELATED ))); +DEBUG_NET_WARN_ON_ONCE (!(ct !=NULL && + (ctinfo ==IP_CT_NEW || ctinfo ==IP_CT_RELATED )));memcpy (&range, range_v1,sizeof (*range_v1));memset (&range.base_proto,0 ,sizeof (range.base_proto));
@@ -126,9 +126,9 @@ xt_snat_target_v2(struct sk_buff *skb, const struct xt_action_param *par)struct nf_conn *ct; ct =nf_ct_get (skb, &ctinfo); -WARN_ON (!(ct !=NULL && - (ctinfo ==IP_CT_NEW || ctinfo ==IP_CT_RELATED || - ctinfo ==IP_CT_RELATED_REPLY ))); +DEBUG_NET_WARN_ON_ONCE (!(ct !=NULL && + (ctinfo ==IP_CT_NEW || ctinfo ==IP_CT_RELATED || + ctinfo ==IP_CT_RELATED_REPLY )));return nf_nat_setup_info (ct, range,NF_NAT_MANIP_SRC ); }
@@ -141,8 +141,8 @@ xt_dnat_target_v2(struct sk_buff *skb, const struct xt_action_param *par)struct nf_conn *ct; ct =nf_ct_get (skb, &ctinfo); -WARN_ON (!(ct !=NULL && - (ctinfo ==IP_CT_NEW || ctinfo ==IP_CT_RELATED ))); +DEBUG_NET_WARN_ON_ONCE (!(ct !=NULL && + (ctinfo ==IP_CT_NEW || ctinfo ==IP_CT_RELATED )));return nf_nat_setup_info (ct, range,NF_NAT_MANIP_DST ); }
net/netfilter/xt_socket.c +2 -1
@@ -161,7 +161,8 @@ static int socket_mt_enable_defrag(struct net *net, int family)return nf_defrag_ipv6_enable (net);#endif } -WARN_ONCE (1 ,"Unknown family %d\n" , family); +pr_warn_once ("xt_socket: Unknown family %d\n" , family); +DEBUG_NET_WARN_ON_ONCE (1 );return 0 ; }
Signature · 1 line
2.54.0
PATCH 2/9 netfilter: nf_tables: use DEBUG_NET_WARN_ON_ONCE in packet and control paths
In reply to Fernando Fernandez ManceraReplace raw warning macros with DEBUG_NET_WARN_ON_ONCE across the nf_tables API, core engine, and expression evaluations. This prevents unnecessary system panics when panic_on_warn=1 is enabled in production systems.
--- net/netfilter/nf_tables_api.c | 38 +++++++++++++++++++++++-------- net/netfilter/nf_tables_core.c | 8 ++++--- net/netfilter/nf_tables_offload.c | 2 +- net/netfilter/nf_tables_trace.c | 6 +++-- net/netfilter/nft_ct.c | 2 +- net/netfilter/nft_ct_fast.c | 2 +- net/netfilter/nft_exthdr.c | 2 +- net/netfilter/nft_fib.c | 2 +- net/netfilter/nft_inner.c | 2 +- net/netfilter/nft_lookup.c | 2 +- net/netfilter/nft_masq.c | 2 +- net/netfilter/nft_meta.c | 10 ++++---- net/netfilter/nft_payload.c | 6 ++--- net/netfilter/nft_redir.c | 2 +- net/netfilter/nft_reject.c | 8 +++++-- net/netfilter/nft_rt.c | 2 +- net/netfilter/nft_set_hash.c | 2 +- net/netfilter/nft_set_pipapo.c | 2 +- net/netfilter/nft_set_rbtree.c | 6 +++-- net/netfilter/nft_socket.c | 8 ++++--- net/netfilter/nft_tunnel.c | 2 +- net/netfilter/nft_xfrm.c | 6 ++--- 22 files changed, 76 insertions(+), 46 deletions(-)
net/netfilter/nf_tables_api.c +28 -10
@@ -3378,8 +3378,10 @@ static int nf_tables_delchain(struct sk_buff *skb, const struct nfnl_info *info,*/ int nft_register_expr (struct nft_expr_type *type) { -if (WARN_ON_ONCE (type->maxattr >NFT_EXPR_MAXATTR )) +if (unlikely (type->maxattr >NFT_EXPR_MAXATTR )) { +DEBUG_NET_WARN_ON_ONCE (1 );return -ENOMEM ; + }nfnl_lock (NFNL_SUBSYS_NFTABLES );if (type->family ==NFPROTO_UNSPEC )
@@ -3691,8 +3693,10 @@ int nft_expr_clone(struct nft_expr *dst, struct nft_expr *src, gfp_t gfp) {int err; -if (WARN_ON_ONCE (!src->ops->clone)) +if (unlikely (!src->ops->clone)) { +DEBUG_NET_WARN_ON_ONCE (1 );return -EINVAL ; + } dst->ops = src->ops; err = src->ops->clone (dst, src, gfp);
@@ -8327,8 +8331,10 @@ static int nf_tables_newobj(struct sk_buff *skb, const struct nfnl_info *info,return 0 ; type =nft_obj_type_get (net, objtype, family); -if (WARN_ON_ONCE (IS_ERR (type))) +if (IS_ERR (type)) { +DEBUG_NET_WARN_ON_ONCE (1 );return PTR_ERR (type); + }nft_ctx_init (&ctx, net, skb, info->nlh, family, table,NULL , nla);
@@ -10306,19 +10312,25 @@ static int nf_tables_commit_chain_prepare(struct net *net, struct nft_chain *cha prule = (struct nft_rule_dp *)data; data += offsetof(struct nft_rule_dp , data); -if (WARN_ON_ONCE (data > data_boundary)) +if (unlikely (data > data_boundary)) { +DEBUG_NET_WARN_ON_ONCE (1 );return -ENOMEM ; + } size =0 ;nft_rule_for_each_expr (expr, last, rule) { -if (WARN_ON_ONCE (data + size + expr->ops->size > data_boundary)) +if (unlikely (data + size + expr->ops->size > data_boundary)) { +DEBUG_NET_WARN_ON_ONCE (1 );return -ENOMEM ; + }memcpy (data + size, expr, expr->ops->size); size += expr->ops->size; } -if (WARN_ON_ONCE (size >=1 <<12 )) +if (unlikely (size >=1 <<12 )) { +DEBUG_NET_WARN_ON_ONCE (1 );return -ENOMEM ; + } prule->handle = rule->handle; prule->dlen = size;
@@ -10329,8 +10341,10 @@ static int nf_tables_commit_chain_prepare(struct net *net, struct nft_chain *cha chain->blob_next->size += (unsigned long )(data - (void *)prule); } -if (WARN_ON_ONCE (data > data_boundary)) +if (unlikely (data > data_boundary)) { +DEBUG_NET_WARN_ON_ONCE (1 );return -ENOMEM ; + } prule = (struct nft_rule_dp *)data;nft_last_rule (chain, prule);
@@ -11636,8 +11650,10 @@ int nft_parse_register_load(const struct nft_ctx *ctx, next_register =DIV_ROUND_UP (len,NFT_REG32_SIZE ) + reg;/* Can't happen: nft_validate_register_load() should have failed */ -if (WARN_ON_ONCE (next_register >NFT_REG32_NUM )) +if (unlikely (next_register >NFT_REG32_NUM )) { +DEBUG_NET_WARN_ON_ONCE (1 );return -EINVAL ; + }/* find first register that did not see an earlier store. */ invalid_reg =find_next_zero_bit (ctx->reg_inited,NFT_REG32_NUM , reg);
@@ -11884,8 +11900,10 @@ int nft_data_init(const struct nft_ctx *ctx, struct nft_data *data,struct nlattr *tb[NFTA_DATA_MAX +1 ];int err; -if (WARN_ON_ONCE (!desc->size)) +if (unlikely (!desc->size)) { +DEBUG_NET_WARN_ON_ONCE (1 );return -EINVAL ; + } err =nla_parse_nested_deprecated (tb,NFTA_DATA_MAX , nla, nft_data_policy,NULL );
@@ -11950,7 +11968,7 @@ int nft_data_dump(struct sk_buff *skb, int attr, const struct nft_data *data,break ;default : err = -EINVAL ; -WARN_ON (1 ); +DEBUG_NET_WARN_ON_ONCE (1 ); }nla_nest_end (skb, nest);
net/netfilter/nf_tables_core.c +5 -3
@@ -314,8 +314,10 @@ nft_do_chain(struct nft_pktinfo *pkt, void *priv)switch (regs.verdict.code) {case NFT_JUMP : -if (WARN_ON_ONCE (stackptr >=NFT_JUMP_STACK_SIZE )) -return NF_DROP ; +if (unlikely (stackptr >=NFT_JUMP_STACK_SIZE )) { +DEBUG_NET_WARN_ON_ONCE (1 ); +return NF_DROP_REASON (pkt->skb,SKB_DROP_REASON_NETFILTER_DROP ,ELOOP ); + } jumpstack[stackptr].rule =nft_rule_next (rule); stackptr++; fallthrough;
@@ -326,7 +328,7 @@ nft_do_chain(struct nft_pktinfo *pkt, void *priv)case NFT_RETURN :break ;default : -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 ); }if (stackptr >0 ) {
net/netfilter/nf_tables_offload.c +1 -1
@@ -361,7 +361,7 @@ static int nft_block_setup(struct nft_base_chain *basechain, err =nft_flow_offload_unbind (bo, basechain);break ;default : -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 ); err = -EOPNOTSUPP ; }
net/netfilter/nf_tables_trace.c +4 -2
@@ -227,8 +227,10 @@ static const struct nft_chain *nft_trace_get_chain(const struct nft_rule_dp *rul last = (const struct nft_rule_dp_last *)rule; -if (WARN_ON_ONCE (!last->chain)) +if (unlikely (!last->chain)) { +DEBUG_NET_WARN_ON_ONCE (1 );return &info->basechain->chain; + }return last->chain; }
@@ -354,7 +356,7 @@ void nft_trace_notify(const struct nft_pktinfo *pkt,return ; nla_put_failure: -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 );kfree_skb (skb); }
net/netfilter/nft_ct.c +1 -1
@@ -1136,7 +1136,7 @@ static void nft_ct_helper_obj_eval(struct nft_object *obj, to_assign = priv->helper6;break ;default : -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 );return ; }
net/netfilter/nft_ct_fast.c +1 -1
@@ -53,7 +53,7 @@ void nft_ct_get_fast_eval(const struct nft_expr *expr,return ;#endif default : -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 ); regs->verdict.code =NFT_BREAK ;break ; }
net/netfilter/nft_exthdr.c +1 -1
@@ -298,7 +298,7 @@ static void nft_exthdr_tcp_set_eval(const struct nft_expr *expr, old.v32, new.v32, false);break ;default : -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 );break ; }
net/netfilter/nft_fib.c +1 -1
@@ -155,7 +155,7 @@ void nft_fib_store_result(void *reg, const struct nft_fib *priv,strscpy_pad (reg, dev ? dev->name :"" ,IFNAMSIZ );break ;default : -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 ); *dreg =0 ;break ; }
net/netfilter/nft_inner.c +1 -1
@@ -308,7 +308,7 @@ static void nft_inner_eval(const struct nft_expr *expr, struct nft_regs *regs,nft_meta_inner_eval ((struct nft_expr *)&priv->expr, regs, pkt, &tun_ctx);break ;default : -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 ); goto err; }nft_inner_save_tun_ctx (pkt, &tun_ctx);
net/netfilter/nft_lookup.c +1 -1
@@ -50,7 +50,7 @@ __nft_set_do_lookup(const struct net *net, const struct nft_set *set,if (set->ops == &nft_set_rbtree_type.ops)return nft_rbtree_lookup (net, set, key); -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 );#endif return set->ops->lookup (net, set, key); }
net/netfilter/nft_masq.c +1 -1
@@ -123,7 +123,7 @@ static void nft_masq_eval(const struct nft_expr *expr,break ;#endif default : -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 );break ; } }
net/netfilter/nft_meta.c +5 -5
@@ -116,12 +116,12 @@ nft_meta_get_eval_pkttype_lo(const struct nft_pktinfo *pkt,nft_reg_store8 (dest,PACKET_MULTICAST );break ;default : -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 );return false; }break ;default : -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 );return false; }
@@ -460,7 +460,7 @@ void nft_meta_get_eval(const struct nft_expr *expr,nft_meta_get_eval_sdifname (dest, pkt);break ;default : -WARN_ON (1 ); +DEBUG_NET_WARN_ON_ONCE (1 ); goto err; }return ;
@@ -506,7 +506,7 @@ void nft_meta_set_eval(const struct nft_expr *expr,break ;#endif default : -WARN_ON (1 ); +DEBUG_NET_WARN_ON_ONCE (1 ); } }EXPORT_SYMBOL_GPL (nft_meta_set_eval);
@@ -886,7 +886,7 @@ void nft_meta_inner_eval(const struct nft_expr *expr,nft_reg_store8 (dest, tun_ctx->l4proto);break ;default : -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 ); goto err; }return ;
net/netfilter/nft_payload.c +3 -3
@@ -196,7 +196,7 @@ void nft_payload_eval(const struct nft_expr *expr, goto err;break ;default : -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 ); goto err; } offset += priv->offset;
@@ -603,7 +603,7 @@ void nft_payload_inner_eval(const struct nft_expr *expr, struct nft_regs *regs, offset = tun_ctx->inner_thoff;break ;default : -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 ); goto err; } offset += priv->offset;
@@ -866,7 +866,7 @@ static void nft_payload_set_eval(const struct nft_expr *expr, goto err;break ;default : -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 ); goto err; }
net/netfilter/nft_redir.c +1 -1
@@ -126,7 +126,7 @@ static void nft_redir_eval(const struct nft_expr *expr,break ;#endif default : -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 );break ; } }
net/netfilter/nft_reject.c +6 -2
@@ -102,8 +102,10 @@ static u8 icmp_code_v4[NFT_REJECT_ICMPX_MAX + 1] = {int nft_reject_icmp_code (u8 code) { -if (WARN_ON_ONCE (code >NFT_REJECT_ICMPX_MAX )) +if (unlikely (code >NFT_REJECT_ICMPX_MAX )) { +DEBUG_NET_WARN_ON_ONCE (1 );return ICMP_NET_UNREACH ; + }return icmp_code_v4[code]; }
@@ -120,8 +122,10 @@ static u8 icmp_code_v6[NFT_REJECT_ICMPX_MAX + 1] = {int nft_reject_icmpv6_code (u8 code) { -if (WARN_ON_ONCE (code >NFT_REJECT_ICMPX_MAX )) +if (unlikely (code >NFT_REJECT_ICMPX_MAX )) { +DEBUG_NET_WARN_ON_ONCE (1 );return ICMPV6_NOROUTE ; + }return icmp_code_v6[code]; }
net/netfilter/nft_rt.c +1 -1
@@ -93,7 +93,7 @@ void nft_rt_get_eval(const struct nft_expr *expr,break ;#endif default : -WARN_ON (1 ); +DEBUG_NET_WARN_ON_ONCE (1 ); goto err; }return ;
net/netfilter/nft_set_hash.c +1 -1
@@ -385,7 +385,7 @@ static void nft_rhash_walk(const struct nft_ctx *ctx, struct nft_set *set,break ;default : iter->err = -EINVAL ; -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 );break ; } }
net/netfilter/nft_set_pipapo.c +1 -1
@@ -2199,7 +2199,7 @@ static void nft_pipapo_walk(const struct nft_ctx *ctx, struct nft_set *set,break ;default : iter->err = -EINVAL ; -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 );break ; } }
net/netfilter/nft_set_rbtree.c +4 -2
@@ -654,8 +654,10 @@ static int nft_array_may_resize(const struct nft_set *set, bool flush) } realloc_array: -if (WARN_ON_ONCE (nelems > new_max_intervals)) +if (unlikely (nelems > new_max_intervals)) { +DEBUG_NET_WARN_ON_ONCE (1 );return -ENOMEM ; + }if (priv->array_next) {if (max_intervals == new_max_intervals)
@@ -878,7 +880,7 @@ static void nft_rbtree_walk(const struct nft_ctx *ctx,break ;default : iter->err = -EINVAL ; -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 );break ; } }
net/netfilter/nft_socket.c +5 -3
@@ -71,8 +71,10 @@ static noinline int nft_socket_cgroup_subtree_level(void)if (level >255 )return -ERANGE ; -if (WARN_ON_ONCE (level <0 )) +if (unlikely (level <0 )) { +DEBUG_NET_WARN_ON_ONCE (1 );return -EINVAL ; + }return level; }
@@ -97,7 +99,7 @@ static struct sock *nft_socket_do_lookup(const struct nft_pktinfo *pkt)break ;#endif default : -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 );break ; }
@@ -152,7 +154,7 @@ static void nft_socket_eval(const struct nft_expr *expr,break ;#endif default : -WARN_ON (1 ); +DEBUG_NET_WARN_ON_ONCE (1 ); regs->verdict.code =NFT_BREAK ; }
net/netfilter/nft_tunnel.c +1 -1
@@ -60,7 +60,7 @@ static void nft_tunnel_get_eval(const struct nft_expr *expr, regs->verdict.code =NFT_BREAK ;break ;default : -WARN_ON (1 ); +DEBUG_NET_WARN_ON_ONCE (1 ); regs->verdict.code =NFT_BREAK ; } }
net/netfilter/nft_xfrm.c +3 -3
@@ -132,7 +132,7 @@ static void nft_xfrm_state_get_key(const struct nft_xfrm *priv,switch (priv->key) {case NFT_XFRM_KEY_UNSPEC :case __NFT_XFRM_KEY_MAX: -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 );break ;case NFT_XFRM_KEY_DADDR_IP4 : *dest = (__force __u32 )state->id.daddr.a4;
@@ -206,7 +206,7 @@ static void nft_xfrm_get_eval(const struct nft_expr *expr,nft_xfrm_get_eval_out (priv, regs, pkt);break ;default : -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 ); regs->verdict.code =NFT_BREAK ;break ; }
@@ -252,7 +252,7 @@ static int nft_xfrm_validate(const struct nft_ctx *ctx, const struct nft_expr *e (1 <<NF_INET_POST_ROUTING );break ;default : -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 );return -EINVAL ; }
Signature · 1 line
2.54.0
PATCH 3/9 netfilter: nfnetlink: use DEBUG_NET_WARN_ON_ONCE for attribute validation
In reply to Fernando Fernandez ManceraReplace WARN_ON and WARN_ONCE with DEBUG_NET_WARN_ON_ONCE in the nfnetlink and cttimeout interfaces. These validation failures are already handled by returning -EINVAL to userspace.
--- net/netfilter/nfnetlink.c | 4 +++- net/netfilter/nfnetlink_cttimeout.c | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-)
net/netfilter/nfnetlink.c +3 -1
@@ -117,8 +117,10 @@ int nfnetlink_subsys_register(const struct nfnetlink_subsystem *n)/* Sanity-check attr_count size to avoid stack buffer overflow. */ for (cb_id =0 ; cb_id < n->cb_count; cb_id++) -if (WARN_ON (n->cb[cb_id].attr_count >NFNL_MAX_ATTR_COUNT )) +if (unlikely (n->cb[cb_id].attr_count >NFNL_MAX_ATTR_COUNT )) { +DEBUG_NET_WARN_ON_ONCE (1 );return -EINVAL ; + }nfnl_lock (n->subsys_id);if (table[n->subsys_id].subsys) {
net/netfilter/nfnetlink_cttimeout.c +2 -1
@@ -476,7 +476,8 @@ static int cttimeout_default_get(struct sk_buff *skb, timeouts = &nf_generic_pernet (info->net)->timeout;break ;default : -WARN_ONCE (1 ,"Missing timeouts for proto %d" , l4proto->l4proto); +pr_warn_once ("Missing timeouts for proto %d\n" , l4proto->l4proto); +DEBUG_NET_WARN_ON_ONCE (1 );break ; }
Signature · 1 line
2.54.0
PATCH 4/9 netfilter: conntrack: use DEBUG_NET_WARN_ON_ONCE on packet paths
In reply to Fernando Fernandez ManceraReplace WARN_ON and WARN_ON_ONCE with DEBUG_NET_WARN_ON_ONCE inside conntrack confirmation, extension management, helper assignment, and protocol parsing loops. This prevents unnecessary system panics when panic_on_warn=1 is enabled in production systems.
--- net/netfilter/nf_conntrack_core.c | 2 +- net/netfilter/nf_conntrack_extend.c | 3 ++- net/netfilter/nf_conntrack_helper.c | 4 +++- net/netfilter/nf_conntrack_ovs.c | 2 +- net/netfilter/nf_conntrack_proto_icmp.c | 3 ++- net/netfilter/nf_conntrack_seqadj.c | 2 +- net/netfilter/nf_conntrack_sip.c | 5 ++++- 7 files changed, 14 insertions(+), 7 deletions(-)
net/netfilter/nf_conntrack_core.c +1 -1
@@ -1244,7 +1244,7 @@ __nf_conntrack_confirm(struct sk_buff *skb)* unconfirmed conntrack. */ if (unlikely (nf_ct_is_confirmed (ct))) { -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 );nf_conntrack_double_unlock (hash, reply_hash);local_bh_enable ();return NF_DROP ;
net/netfilter/nf_conntrack_extend.c +2 -1
@@ -95,7 +95,8 @@ void *nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp)struct nf_ct_ext *new;/* Conntrack must not be confirmed to avoid races on reallocation. */ -WARN_ON (nf_ct_is_confirmed (ct)); +if (unlikely (nf_ct_is_confirmed (ct))) +DEBUG_NET_WARN_ON_ONCE (1 );/* struct nf_ct_ext uses u8 to store offsets/size */ BUILD_BUG_ON (total_extension_size () >255u );
net/netfilter/nf_conntrack_helper.c +3 -1
@@ -198,8 +198,10 @@ int __nf_ct_try_assign_helper(struct nf_conn *ct, struct nf_conn *tmpl,if (test_bit (IPS_HELPER_BIT , &ct->status))return 0 ; -if (WARN_ON_ONCE (!tmpl)) +if (unlikely (!tmpl)) { +DEBUG_NET_WARN_ON_ONCE (1 );return 0 ; + } help =nfct_help (tmpl);if (help !=NULL ) {
net/netfilter/nf_conntrack_ovs.c +1 -1
@@ -53,7 +53,7 @@ int nf_ct_helper(struct sk_buff *skb, struct nf_conn *ct,break ; }default : -WARN_ONCE (1 ,"helper invoked on non-IP family!" ); +DEBUG_NET_WARN_ONCE (1 ,"helper invoked on non-IP family!" );return NF_DROP ; }
net/netfilter/nf_conntrack_proto_icmp.c +2 -1
@@ -117,7 +117,8 @@ int nf_conntrack_inet_error(struct nf_conn *tmpl, struct sk_buff *skb,enum ip_conntrack_dir dir;struct nf_conn *ct; -WARN_ON (skb_nfct (skb)); +if (unlikely (skb_nfct (skb))) +DEBUG_NET_WARN_ON_ONCE (1 ); zone =nf_ct_zone_tmpl (tmpl, skb, &tmp);/* Are they talking about one of our connections? */
net/netfilter/nf_conntrack_seqadj.c +1 -1
@@ -38,7 +38,7 @@ int nf_ct_seqadj_set(struct nf_conn *ct, enum ip_conntrack_info ctinfo,return 0 ;if (unlikely (!seqadj)) { -WARN_ONCE (1 ,"Missing nfct_seqadj_ext_add() setup call\n" ); +DEBUG_NET_WARN_ONCE (1 ,"Missing nfct_seqadj_ext_add() setup call\n" );return 0 ; }
net/netfilter/nf_conntrack_sip.c +4 -1
@@ -599,7 +599,10 @@ int ct_sip_parse_header_uri(const struct nf_conn *ct, const char *dptr, ret =ct_sip_walk_headers (ct, dptr, dataoff ? *dataoff :0 , datalen, type, in_header, matchoff, matchlen); -WARN_ON (ret <0 ); +if (unlikely (ret <0 )) { +DEBUG_NET_WARN_ON_ONCE (1 ); +return -1 ; + }if (ret ==0 )return ret;
Signature · 1 line
2.54.0
Pablo Neira Ayuso
maintainerRe: [PATCH 4/9 nf-next] netfilter: conntrack: use DEBUG_NET_WARN_ON_ONCE on packet paths
Hi Fernando,
I'm a making a bit more in-depth review for this specific patch.
I think, in general about this series, it would be good to avoid, things like:
DEBUG_NET_WARN_ON_ONCE(blah);
func(blah->info, ...);but it might not be trivial in all cases, sometimes it is simply better to remove in that case.
The patch in this series for nf_tables (already upstream) always follow the idiom:
if (cond) {
DEBUG_NET_WARN_ON_ONCE(1);
terminal statament (ie. return, break...)
}I will try to provide you with hints on what to do in other patches in this series to speed up inclusion.
Now comments on this specific patch, see below.
Quoted 21 lines · Fernando Fernandez Mancera
Replace
WARN_ONandWARN_ON_ONCEwithDEBUG_NET_WARN_ON_ONCEinside conntrack confirmation, extension management, helper assignment, and protocol parsing loops. This prevents unnecessary system panics when panic_on_warn=1 is enabled in production systems.Signed-off-by Fernando Fernandez Mancera <[email protected]>--- net/netfilter/nf_conntrack_core.c | 2 +- net/netfilter/nf_conntrack_extend.c | 3 ++- net/netfilter/nf_conntrack_helper.c | 4 +++- net/netfilter/nf_conntrack_ovs.c | 2 +- net/netfilter/nf_conntrack_proto_icmp.c | 3 ++- net/netfilter/nf_conntrack_seqadj.c | 2 +- net/netfilter/nf_conntrack_sip.c | 5 ++++- 7 files changed, 14 insertions(+), 7 deletions(-)net/netfilter/nf_conntrack_core.c +0
-0
net/netfilter/nf_conntrack_core.c __nf_conntrack_confirm(struct sk_buff *skb) · line 1250
Quoted 8 lines
net/netfilter/nf_conntrack_core.c +1
-1@@ -1244,7 +1244,7 @@ __nf_conntrack_confirm(struct sk_buff *skb)* unconfirmed conntrack. */ if (unlikely (nf_ct_is_confirmed (ct))) { -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 );nf_conntrack_double_unlock (hash, reply_hash);local_bh_enable ();return NF_DROP ;
OK, explicit drop, fine. Keep it.
net/netfilter/nf_conntrack_extend.c void *nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp) · line 99
Quoted 11 lines
net/netfilter/nf_conntrack_extend.c +2
-1@@ -95,7 +95,8 @@ void *nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp)struct nf_ct_ext *new;/* Conntrack must not be confirmed to avoid races on reallocation. */ -WARN_ON (nf_ct_is_confirmed (ct)); +if (unlikely (nf_ct_is_confirmed (ct))) +DEBUG_NET_WARN_ON_ONCE (1 );
Keep it, but return NULL here. It provide good context, extensions can only be added with a unconfirmed conntrack.
Quoted 7 lines
net/netfilter/nf_conntrack_extend.c +0
-0/* struct nf_ct_ext uses u8 to store offsets/size */ BUILD_BUG_ON (total_extension_size () >255u );net/netfilter/nf_conntrack_helper.c +0
-0
net/netfilter/nf_conntrack_helper.c int __nf_ct_try_assign_helper(struct nf_conn *ct, struct nf_conn *tmpl, · line 204
Quoted 8 lines
net/netfilter/nf_conntrack_helper.c +3
-1@@ -198,8 +198,10 @@ int __nf_ct_try_assign_helper(struct nf_conn *ct, struct nf_conn *tmpl,if (test_bit (IPS_HELPER_BIT , &ct->status))return 0 ; -if (WARN_ON_ONCE (!tmpl)) +if (unlikely (!tmpl)) { +DEBUG_NET_WARN_ON_ONCE (1 );return 0 ; + }
Useless for netfilter:
if (!exp && tmpl)
__nf_ct_try_assign_helper(ct, tmpl, GFP_ATOMIC);_BUT_ it can catch bugs in other existing users, eg. net/sched/act_ct.c
if (!nf_ct_is_confirmed(ct) && commit && p->helper && !nfct_help(ct)) {
err = __nf_ct_try_assign_helper(ct, p->tmpl, GFP_ATOMIC);keep it.
it is also fine that there is a branch and return (to skip it).
net/netfilter/nf_conntrack_ovs.c int nf_ct_helper(struct sk_buff *skb, struct nf_conn *ct, · line 57
Quoted 13 lines
net/netfilter/nf_conntrack_helper.c +0
-0help =nfct_help (tmpl);if (help !=NULL ) {net/netfilter/nf_conntrack_ovs.c +1
-1@@ -53,7 +53,7 @@ int nf_ct_helper(struct sk_buff *skb, struct nf_conn *ct,break ; }default : -WARN_ONCE (1 ,"helper invoked on non-IP family!" ); +DEBUG_NET_WARN_ONCE (1 ,"helper invoked on non-IP family!" );return NF_DROP ;
OK, this is in a branch with an explicit action (drop packet) LGTm.
net/netfilter/nf_conntrack_proto_icmp.c int nf_conntrack_inet_error(struct nf_conn *tmpl, struct sk_buff *skb, · line 121
Quoted 13 lines
net/netfilter/nf_conntrack_ovs.c +0
-0}net/netfilter/nf_conntrack_proto_icmp.c +2
-1@@ -117,7 +117,8 @@ int nf_conntrack_inet_error(struct nf_conn *tmpl, struct sk_buff *skb,enum ip_conntrack_dir dir;struct nf_conn *ct; -WARN_ON (skb_nfct (skb)); +if (unlikely (skb_nfct (skb))) +DEBUG_NET_WARN_ON_ONCE (1 );
nf_conntrack_in
[ reset skb->nfct ]
nf_conntrack_handle_icmp
nf_conntrack_icmpv4_error
nf_conntrack_inet_error
There is nf_conntrack_inet_error() which performs the ct lookup. There is resolve_normal_ct() too, but these two are coming later.
[ ... snippet that resets skb->nfct ... ]
unsigned intnf_conntrack_in(struct sk_buff *skb, const struct nf_hook_state *state)
{
enum ip_conntrack_info ctinfo;
struct nf_conn *ct, *tmpl;
u_int8_t protonum;
int dataoff, ret;
tmpl = nf_ct_get(skb, &ctinfo);
if (tmpl || ctinfo == IP_CT_UNTRACKED) {
/* Previously seen (loopback or untracked)? Ignore. */
if ((tmpl && !nf_ct_is_template(tmpl)) ||
ctinfo == IP_CT_UNTRACKED)
return NF_ACCEPT;
skb->_nfct = 0; <--------- this is reset here.
}[ end of snippet ]
I don't remember to have seen this WARN_ON, so remove it.
net/netfilter/nf_conntrack_seqadj.c int nf_ct_seqadj_set(struct nf_conn *ct, enum ip_conntrack_info ctinfo, · line 41
Quoted 13 lines
net/netfilter/nf_conntrack_proto_icmp.c +0
-0zone =nf_ct_zone_tmpl (tmpl, skb, &tmp);/* Are they talking about one of our connections? */ net/netfilter/nf_conntrack_seqadj.c +1
-1@@ -38,7 +38,7 @@ int nf_ct_seqadj_set(struct nf_conn *ct, enum ip_conntrack_info ctinfo,return 0 ;if (unlikely (!seqadj)) { -WARN_ONCE (1 ,"Missing nfct_seqadj_ext_add() setup call\n" ); +DEBUG_NET_WARN_ONCE (1 ,"Missing nfct_seqadj_ext_add() setup call\n" );
This WARN_ONCE is now gone in the nf.git/nf-next.git.
Quoted 8 lines
net/netfilter/nf_conntrack_seqadj.c +0
-0return 0 ; }net/netfilter/nf_conntrack_sip.c +0
-0
net/netfilter/nf_conntrack_sip.c int ct_sip_parse_header_uri(const struct nf_conn *ct, const char *dptr, · line 605
Quoted 8 lines
net/netfilter/nf_conntrack_sip.c +4
-1@@ -599,7 +599,10 @@ int ct_sip_parse_header_uri(const struct nf_conn *ct, const char *dptr, ret =ct_sip_walk_headers (ct, dptr, dataoff ? *dataoff :0 , datalen, type, in_header, matchoff, matchlen); -WARN_ON (ret <0 ); +if (unlikely (ret <0 )) { +DEBUG_NET_WARN_ON_ONCE (1 ); +return -1 ; + }
ct_sip_walk_headers() can never return < 0. This WARN_ON can be removed.
net/netfilter/nf_conntrack_sip.c int ct_sip_parse_header_uri(const struct nf_conn *ct, const char *dptr, · line 607
Quoted 2 lines
net/netfilter/nf_conntrack_sip.c +0
-0if (ret ==0 )return ret;
Thanks.
Florian Westphal
maintainerRe: [PATCH 4/9 nf-next] netfilter: conntrack: use DEBUG_NET_WARN_ON_ONCE on packet paths
Quoted 11 lines · Pablo Neira Ayuso
net/netfilter/nf_conntrack_proto_icmp.c int nf_conntrack_inet_error(struct nf_conn *tmpl, struct sk_buff *skb, · line 121
Quoted 11 lines
net/netfilter/nf_conntrack_proto_icmp.c +2
-1@@ -117,7 +117,8 @@ int nf_conntrack_inet_error(struct nf_conn *tmpl, struct sk_buff *skb,enum ip_conntrack_dir dir;struct nf_conn *ct; -WARN_ON (skb_nfct (skb)); +if (unlikely (skb_nfct (skb))) +DEBUG_NET_WARN_ON_ONCE (1 );
Should be
DEBUG_NET_WARN_ON_ONCE(skb_nfct(skb)));
?
Quoted 26 lines
nf_conntrack_in
[ resetskb->nfct]
nf_conntrack_handle_icmp
nf_conntrack_icmpv4_error
nf_conntrack_inet_errorThere is
nf_conntrack_inet_error()which performs the ct lookup. There isresolve_normal_ct()too, but these two are coming later.[ ... snippet that resets
skb->nfct... ]
unsigned intnf_conntrack_in(struct sk_buff *skb, const struct nf_hook_state *state){ enum ip_conntrack_info ctinfo; struct nf_conn *ct, *tmpl; u_int8_t protonum; int dataoff, ret; tmpl = nf_ct_get(skb, &ctinfo); if (tmpl || ctinfo == IP_CT_UNTRACKED) { /* Previously seen (loopback or untracked)? Ignore. */ if ((tmpl && !nf_ct_is_template(tmpl)) || ctinfo == IP_CT_UNTRACKED) return NF_ACCEPT; skb->_nfct = 0; <--------- this is reset here. }
Quoted 3 lines
[ end of snippet ]
I don't remember to have seen this
WARN_ON, so remove it.
I would keep the DEBUG_NET_WARN_ON_ONCE(), else this gives a refcount leak.
Or, move it closer to the end:
191 /* Update skb to refer to this connection */
HERE.
192 nf_ct_set(skb, ct, ctinfo);
193 return NF_ACCEPT;
194 }
Pablo Neira Ayuso
maintainerRe: [PATCH 4/9 nf-next] netfilter: conntrack: use DEBUG_NET_WARN_ON_ONCE on packet paths
Quoted 50 lines · Florian Westphal
Quoted 11 lines · Pablo Neira Ayuso
net/netfilter/nf_conntrack_proto_icmp.c int nf_conntrack_inet_error(struct nf_conn *tmpl, struct sk_buff *skb, · line 121
Quoted 11 lines
net/netfilter/nf_conntrack_proto_icmp.c +2
-1@@ -117,7 +117,8 @@ int nf_conntrack_inet_error(struct nf_conn *tmpl, struct sk_buff *skb,enum ip_conntrack_dir dir;struct nf_conn *ct; -WARN_ON (skb_nfct (skb)); +if (unlikely (skb_nfct (skb))) +DEBUG_NET_WARN_ON_ONCE (1 );Should be
DEBUG_NET_WARN_ON_ONCE(skb_nfct(skb)));
?Quoted 26 lines
nf_conntrack_in
[ resetskb->nfct]
nf_conntrack_handle_icmp
nf_conntrack_icmpv4_error
nf_conntrack_inet_errorThere is
nf_conntrack_inet_error()which performs the ct lookup. There isresolve_normal_ct()too, but these two are coming later.[ ... snippet that resets
skb->nfct... ]
unsigned intnf_conntrack_in(struct sk_buff *skb, const struct nf_hook_state *state){ enum ip_conntrack_info ctinfo; struct nf_conn *ct, *tmpl; u_int8_t protonum; int dataoff, ret; tmpl = nf_ct_get(skb, &ctinfo); if (tmpl || ctinfo == IP_CT_UNTRACKED) { /* Previously seen (loopback or untracked)? Ignore. */ if ((tmpl && !nf_ct_is_template(tmpl)) || ctinfo == IP_CT_UNTRACKED) return NF_ACCEPT; skb->_nfct = 0; <--------- this is reset here. }Quoted 3 lines
[ end of snippet ]
I don't remember to have seen this
WARN_ON, so remove it.I would keep the
DEBUG_NET_WARN_ON_ONCE(), else this gives a refcount leak.
Quoted 7 lines
Or, move it closer to the end:
191 /* Update skb to refer to this connection */
HERE.
192nf_ct_set(skb, ct, ctinfo);
193 returnNF_ACCEPT;
194 }
OK, let's keep it around. Thanks.
Re: [PATCH 4/9 nf-next] netfilter: conntrack: use DEBUG_NET_WARN_ON_ONCE on packet paths
In reply to Florian WestphalQuoted 9 lines · Florian Westphal
Quoted 8 lines · Pablo Neira Ayuso
Quoted 8 lines
net/netfilter/nf_conntrack_proto_icmp.c +0
-0@@ -117,7 +117,8 @@ int nf_conntrack_inet_error(struct nf_conn *tmpl, struct sk_buff *skb,enum ip_conntrack_dir dir;struct nf_conn *ct;
Quoted 8 lines
Quoted 3 lines
net/netfilter/nf_conntrack_proto_icmp.c int nf_conntrack_inet_error(struct nf_conn *tmpl, struct sk_buff *skb, · line 121
Quoted 3 lines
net/netfilter/nf_conntrack_proto_icmp.c +2
-1-WARN_ON (skb_nfct (skb)); +if (unlikely (skb_nfct (skb))) +DEBUG_NET_WARN_ON_ONCE (1 );Should be
DEBUG_NET_WARN_ON_ONCE(skb_nfct(skb)));
?
It makes sense, nice catch. Thanks!
Quoted 33 lines
Quoted 26 lines
nf_conntrack_in
[ resetskb->nfct]
nf_conntrack_handle_icmp
nf_conntrack_icmpv4_error
nf_conntrack_inet_errorThere is
nf_conntrack_inet_error()which performs the ct lookup. There isresolve_normal_ct()too, but these two are coming later.[ ... snippet that resets
skb->nfct... ]
unsigned intnf_conntrack_in(struct sk_buff *skb, const struct nf_hook_state *state){ enum ip_conntrack_info ctinfo; struct nf_conn *ct, *tmpl; u_int8_t protonum; int dataoff, ret; tmpl = nf_ct_get(skb, &ctinfo); if (tmpl || ctinfo == IP_CT_UNTRACKED) { /* Previously seen (loopback or untracked)? Ignore. */ if ((tmpl && !nf_ct_is_template(tmpl)) || ctinfo == IP_CT_UNTRACKED) return NF_ACCEPT; skb->_nfct = 0; <--------- this is reset here. }Quoted 3 lines
[ end of snippet ]
I don't remember to have seen this
WARN_ON, so remove it.I would keep the
DEBUG_NET_WARN_ON_ONCE(), else this gives a refcount leak.
Quoted 8 lines
Or, move it closer to the end:
191 /* Update skb to refer to this connection */
HERE.
192nf_ct_set(skb, ct, ctinfo);
193 returnNF_ACCEPT;
194 }
As Pablo agreed too, let's keep it where it is. Thank you!
Re: [PATCH 4/9 nf-next] netfilter: conntrack: use DEBUG_NET_WARN_ON_ONCE on packet paths
In reply to Pablo Neira AyusoQuoted 7 lines · Pablo Neira Ayuso
Hi Fernando,
I'm a making a bit more in-depth review for this specific patch.
I think, in general about this series, it would be good to avoid, things like:
Quoted 7 lines
DEBUG_NET_WARN_ON_ONCE(blah); func(blah->info, ...);but it might not be trivial in all cases, sometimes it is simply better to remove in that case.
Makes sense.
Quoted 8 lines
The patch in this series for
nf_tables(already upstream) always follow the idiom:if (cond) { DEBUG_NET_WARN_ON_ONCE(1); terminal statament (ie. return, break...) }
Quoted 5 lines
I will try to provide you with hints on what to do in other patches in this series to speed up inclusion.
Now comments on this specific patch, see below.
Thank you Pablo for the comments, they are quite useful. As this goes to nf-next now we don't have time pressure. I will amend this patch locally and will wait for the comments in other patches. No need to rush the review, we can take this the slow-path.
Thank you again!
Quoted 179 lines · Fernando Fernandez Mancera
Quoted 21 lines
Replace
WARN_ONandWARN_ON_ONCEwithDEBUG_NET_WARN_ON_ONCEinside conntrack confirmation, extension management, helper assignment, and protocol parsing loops. This prevents unnecessary system panics when panic_on_warn=1 is enabled in production systems.Signed-off-by Fernando Fernandez Mancera <[email protected]>--- net/netfilter/nf_conntrack_core.c | 2 +- net/netfilter/nf_conntrack_extend.c | 3 ++- net/netfilter/nf_conntrack_helper.c | 4 +++- net/netfilter/nf_conntrack_ovs.c | 2 +- net/netfilter/nf_conntrack_proto_icmp.c | 3 ++- net/netfilter/nf_conntrack_seqadj.c | 2 +- net/netfilter/nf_conntrack_sip.c | 5 ++++- 7 files changed, 14 insertions(+), 7 deletions(-)net/netfilter/nf_conntrack_core.c +0
-0net/netfilter/nf_conntrack_core.c __nf_conntrack_confirm(struct sk_buff *skb) · line 1250
Quoted 8 lines
net/netfilter/nf_conntrack_core.c +1
-1@@ -1244,7 +1244,7 @@ __nf_conntrack_confirm(struct sk_buff *skb)* unconfirmed conntrack. */ if (unlikely (nf_ct_is_confirmed (ct))) { -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 );nf_conntrack_double_unlock (hash, reply_hash);local_bh_enable ();return NF_DROP ;OK, explicit drop, fine. Keep it.
net/netfilter/nf_conntrack_extend.c void *nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp) · line 99
Quoted 11 lines
net/netfilter/nf_conntrack_extend.c +2
-1@@ -95,7 +95,8 @@ void *nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp)struct nf_ct_ext *new;/* Conntrack must not be confirmed to avoid races on reallocation. */ -WARN_ON (nf_ct_is_confirmed (ct)); +if (unlikely (nf_ct_is_confirmed (ct))) +DEBUG_NET_WARN_ON_ONCE (1 );Keep it, but return NULL here. It provide good context, extensions can only be added with a unconfirmed conntrack.
Quoted 7 lines
net/netfilter/nf_conntrack_extend.c +0
-0/* struct nf_ct_ext uses u8 to store offsets/size */ BUILD_BUG_ON (total_extension_size () >255u );net/netfilter/nf_conntrack_helper.c +0
-0net/netfilter/nf_conntrack_helper.c int __nf_ct_try_assign_helper(struct nf_conn *ct, struct nf_conn *tmpl, · line 204
Quoted 8 lines
net/netfilter/nf_conntrack_helper.c +3
-1@@ -198,8 +198,10 @@ int __nf_ct_try_assign_helper(struct nf_conn *ct, struct nf_conn *tmpl,if (test_bit (IPS_HELPER_BIT , &ct->status))return 0 ; -if (WARN_ON_ONCE (!tmpl)) +if (unlikely (!tmpl)) { +DEBUG_NET_WARN_ON_ONCE (1 );return 0 ; + }Useless for netfilter:
if (!exp && tmpl) __nf_ct_try_assign_helper(ct, tmpl, GFP_ATOMIC);_BUT_ it can catch bugs in other existing users, eg.
net/sched/act_ct.cif (!nf_ct_is_confirmed(ct) && commit && p->helper && !nfct_help(ct)) { err = __nf_ct_try_assign_helper(ct, p->tmpl, GFP_ATOMIC);keep it.
it is also fine that there is a branch and return (to skip it).
net/netfilter/nf_conntrack_ovs.c int nf_ct_helper(struct sk_buff *skb, struct nf_conn *ct, · line 57
Quoted 13 lines
net/netfilter/nf_conntrack_helper.c +0
-0help =nfct_help (tmpl);if (help !=NULL ) {net/netfilter/nf_conntrack_ovs.c +1
-1@@ -53,7 +53,7 @@ int nf_ct_helper(struct sk_buff *skb, struct nf_conn *ct,break ; }default : -WARN_ONCE (1 ,"helper invoked on non-IP family!" ); +DEBUG_NET_WARN_ONCE (1 ,"helper invoked on non-IP family!" );return NF_DROP ;OK, this is in a branch with an explicit action (drop packet) LGTm.
net/netfilter/nf_conntrack_proto_icmp.c int nf_conntrack_inet_error(struct nf_conn *tmpl, struct sk_buff *skb, · line 121
Quoted 13 lines
net/netfilter/nf_conntrack_ovs.c +0
-0}net/netfilter/nf_conntrack_proto_icmp.c +2
-1@@ -117,7 +117,8 @@ int nf_conntrack_inet_error(struct nf_conn *tmpl, struct sk_buff *skb,enum ip_conntrack_dir dir;struct nf_conn *ct; -WARN_ON (skb_nfct (skb)); +if (unlikely (skb_nfct (skb))) +DEBUG_NET_WARN_ON_ONCE (1 );
nf_conntrack_in
[ resetskb->nfct]
nf_conntrack_handle_icmp
nf_conntrack_icmpv4_error
nf_conntrack_inet_errorThere is
nf_conntrack_inet_error()which performs the ct lookup. There isresolve_normal_ct()too, but these two are coming later.[ ... snippet that resets
skb->nfct... ]
unsigned intnf_conntrack_in(struct sk_buff *skb, const struct nf_hook_state *state){ enum ip_conntrack_info ctinfo; struct nf_conn *ct, *tmpl; u_int8_t protonum; int dataoff, ret; tmpl = nf_ct_get(skb, &ctinfo); if (tmpl || ctinfo == IP_CT_UNTRACKED) { /* Previously seen (loopback or untracked)? Ignore. */ if ((tmpl && !nf_ct_is_template(tmpl)) || ctinfo == IP_CT_UNTRACKED) return NF_ACCEPT; skb->_nfct = 0; <--------- this is reset here. }[ end of snippet ]
I don't remember to have seen this
WARN_ON, so remove it.net/netfilter/nf_conntrack_seqadj.c int nf_ct_seqadj_set(struct nf_conn *ct, enum ip_conntrack_info ctinfo, · line 41
Quoted 13 lines
net/netfilter/nf_conntrack_proto_icmp.c +0
-0zone =nf_ct_zone_tmpl (tmpl, skb, &tmp);/* Are they talking about one of our connections? */ net/netfilter/nf_conntrack_seqadj.c +1
-1@@ -38,7 +38,7 @@ int nf_ct_seqadj_set(struct nf_conn *ct, enum ip_conntrack_info ctinfo,return 0 ;if (unlikely (!seqadj)) { -WARN_ONCE (1 ,"Missing nfct_seqadj_ext_add() setup call\n" ); +DEBUG_NET_WARN_ONCE (1 ,"Missing nfct_seqadj_ext_add() setup call\n" );This
WARN_ONCEis now gone in the nf.git/nf-next.git.Quoted 8 lines
net/netfilter/nf_conntrack_seqadj.c +0
-0return 0 ; }net/netfilter/nf_conntrack_sip.c +0
-0net/netfilter/nf_conntrack_sip.c int ct_sip_parse_header_uri(const struct nf_conn *ct, const char *dptr, · line 605
Quoted 8 lines
net/netfilter/nf_conntrack_sip.c +4
-1@@ -599,7 +599,10 @@ int ct_sip_parse_header_uri(const struct nf_conn *ct, const char *dptr, ret =ct_sip_walk_headers (ct, dptr, dataoff ? *dataoff :0 , datalen, type, in_header, matchoff, matchlen); -WARN_ON (ret <0 ); +if (unlikely (ret <0 )) { +DEBUG_NET_WARN_ON_ONCE (1 ); +return -1 ; + }
ct_sip_walk_headers()can never return < 0. ThisWARN_ONcan be removed.net/netfilter/nf_conntrack_sip.c int ct_sip_parse_header_uri(const struct nf_conn *ct, const char *dptr, · line 607
Quoted 2 lines
net/netfilter/nf_conntrack_sip.c +0
-0if (ret ==0 )return ret;Thanks.
PATCH 5/9 netfilter: nat: use DEBUG_NET_WARN_ON_ONCE in core and helper paths
In reply to Fernando Fernandez ManceraReplace WARN_ON and WARN_ON_ONCE with DEBUG_NET_WARN_ON_ONCE across core NAT setup functions, masquerade, redirect, and helpers. This prevents unnecessary system panics when panic_on_warn=1 is enabled in production systems.
--- net/ipv4/netfilter/nf_nat_pptp.c | 16 +++++++++---- net/netfilter/nf_nat_core.c | 39 +++++++++++++++++++++---------- net/netfilter/nf_nat_masquerade.c | 6 +++-- net/netfilter/nf_nat_proto.c | 14 +++++++---- net/netfilter/nf_nat_redirect.c | 5 ++-- 5 files changed, 55 insertions(+), 25 deletions(-)
net/ipv4/netfilter/nf_nat_pptp.c +12 -4
@@ -53,8 +53,10 @@ static void pptp_nat_expected(struct nf_conn *ct,struct nf_conn_nat *nat; nat =nf_ct_nat_ext_add (ct); -if (WARN_ON_ONCE (!nat)) +if (unlikely (!nat)) { +DEBUG_NET_WARN_ON_ONCE (1 );return ; + } nat_pptp_info = &nat->help.nat_pptp_info; ct_pptp_info =nfct_help_data (master);
@@ -132,8 +134,10 @@ pptp_outbound_pkt(struct sk_buff *skb,__be16 new_callid;unsigned int cid_off; -if (WARN_ON_ONCE (!nat)) +if (unlikely (!nat)) { +DEBUG_NET_WARN_ON_ONCE (1 );return NF_DROP ; + } nat_pptp_info = &nat->help.nat_pptp_info; ct_pptp_info =nfct_help_data (ct);
@@ -204,8 +208,10 @@ pptp_exp_gre(struct nf_conntrack_expect *expect_orig,struct nf_ct_pptp_master *ct_pptp_info;struct nf_nat_pptp *nat_pptp_info; -if (WARN_ON_ONCE (!nat)) +if (unlikely (!nat)) { +DEBUG_NET_WARN_ON_ONCE (1 );return ; + } nat_pptp_info = &nat->help.nat_pptp_info; ct_pptp_info =nfct_help_data (ct);
@@ -241,8 +247,10 @@ pptp_inbound_pkt(struct sk_buff *skb,__be16 new_pcid;unsigned int pcid_off; -if (WARN_ON_ONCE (!nat)) +if (unlikely (!nat)) { +DEBUG_NET_WARN_ON_ONCE (1 );return NF_DROP ; + } nat_pptp_info = &nat->help.nat_pptp_info; new_pcid = nat_pptp_info->pns_call_id;
net/netfilter/nf_nat_core.c +27 -12
@@ -366,8 +366,10 @@ nf_nat_used_tuple_harder(const struct nf_conntrack_tuple *tuple,if (thash->tuple.dst.dir ==IP_CT_DIR_ORIGINAL ) goto out; -if (WARN_ON_ONCE (ct == ignored_conntrack)) +if (unlikely (ct == ignored_conntrack)) { +DEBUG_NET_WARN_ON_ONCE (1 ); goto out; + } flags =READ_ONCE (ct->status);if (!nf_nat_may_kill (ct, flags))
@@ -773,11 +775,13 @@ nf_nat_setup_info(struct nf_conn *ct,if (nf_ct_is_confirmed (ct))return NF_ACCEPT ; -WARN_ON (maniptype !=NF_NAT_MANIP_SRC && - maniptype !=NF_NAT_MANIP_DST ); +if (unlikely (maniptype !=NF_NAT_MANIP_SRC && maniptype !=NF_NAT_MANIP_DST )) +DEBUG_NET_WARN_ON_ONCE (1 ); -if (WARN_ON (nf_nat_initialized (ct, maniptype))) +if (unlikely (nf_nat_initialized (ct, maniptype))) { +DEBUG_NET_WARN_ON_ONCE (1 );return NF_DROP ; + }/* What we've got will look like inverse of reply. Normally * this is what is in the conntrack, except for prior
@@ -955,8 +959,8 @@ nf_nat_inet_fn(void *priv, struct sk_buff *skb,break ;default :/* ESTABLISHED */ -WARN_ON (ctinfo !=IP_CT_ESTABLISHED && - ctinfo !=IP_CT_ESTABLISHED_REPLY ); +if (unlikely (ctinfo !=IP_CT_ESTABLISHED && ctinfo !=IP_CT_ESTABLISHED_REPLY )) +DEBUG_NET_WARN_ON_ONCE (1 );if (nf_nat_oif_changed (state->hook, ctinfo, nat, state->out)) goto oif_changed; }
@@ -1143,8 +1147,10 @@ nfnetlink_parse_nat_setup(struct nf_conn *ct,/* Should not happen, restricted to creating new conntracks * via ctnetlink. */ -if (WARN_ON_ONCE (nf_nat_initialized (ct, manip))) +if (unlikely (nf_nat_initialized (ct, manip))) { +DEBUG_NET_WARN_ON_ONCE (1 );return -EEXIST ; + }/* No NAT information has been passed, allocate the null-binding */ if (attr ==NULL )
@@ -1181,8 +1187,10 @@ int nf_nat_register_fn(struct net *net, u8 pf, const struct nf_hook_ops *ops,struct nf_hook_ops *nat_ops;int i, ret; -if (WARN_ON_ONCE (pf >=ARRAY_SIZE (nat_net->nat_proto_net))) +if (unlikely (pf >=ARRAY_SIZE (nat_net->nat_proto_net))) { +DEBUG_NET_WARN_ON_ONCE (1 );return -EINVAL ; + } nat_proto_net = &nat_net->nat_proto_net[pf];
@@ -1193,8 +1201,10 @@ int nf_nat_register_fn(struct net *net, u8 pf, const struct nf_hook_ops *ops, } } -if (WARN_ON_ONCE (i == ops_count)) +if (unlikely (i == ops_count)) { +DEBUG_NET_WARN_ON_ONCE (1 );return -EINVAL ; + }mutex_lock (&nf_nat_proto_mutex);if (!nat_proto_net->nat_hook_ops) {
@@ -1235,7 +1245,8 @@ int nf_nat_register_fn(struct net *net, u8 pf, const struct nf_hook_ops *ops, nat_ops = nat_proto_net->nat_hook_ops; priv = nat_ops[hooknum].priv; -if (WARN_ON_ONCE (!priv)) { +if (unlikely (!priv)) { +DEBUG_NET_WARN_ON_ONCE (1 );mutex_unlock (&nf_nat_proto_mutex);return -EOPNOTSUPP ; }
@@ -1264,8 +1275,10 @@ void nf_nat_unregister_fn(struct net *net, u8 pf, const struct nf_hook_ops *ops, nat_proto_net = &nat_net->nat_proto_net[pf];mutex_lock (&nf_nat_proto_mutex); -if (WARN_ON (nat_proto_net->users ==0 )) +if (unlikely (nat_proto_net->users ==0 )) { +DEBUG_NET_WARN_ON_ONCE (1 ); goto unlock; + } nat_proto_net->users--;
@@ -1276,8 +1289,10 @@ void nf_nat_unregister_fn(struct net *net, u8 pf, const struct nf_hook_ops *ops,break ; } } -if (WARN_ON_ONCE (i == ops_count)) +if (unlikely (i == ops_count)) { +DEBUG_NET_WARN_ON_ONCE (1 ); goto unlock; + } priv = nat_ops[hooknum].priv;nf_hook_entries_delete_raw (&priv->entries, ops);
net/netfilter/nf_nat_masquerade.c +4 -2
@@ -36,7 +36,8 @@ nf_nat_masquerade_ipv4(struct sk_buff *skb, unsigned int hooknum,const struct rtable *rt;__be32 newsrc, nh; -WARN_ON (hooknum !=NF_INET_POST_ROUTING ); +if (unlikely (hooknum !=NF_INET_POST_ROUTING )) +DEBUG_NET_WARN_ON_ONCE (1 ); ct =nf_ct_get (skb, &ctinfo);
@@ -297,7 +298,8 @@ int nf_nat_masquerade_inet_register_notifiers(void)int ret =0 ;mutex_lock (&masq_mutex); -if (WARN_ON_ONCE (masq_refcnt ==UINT_MAX )) { +if (masq_refcnt ==UINT_MAX ) { +DEBUG_NET_WARN_ON_ONCE (1 ); ret = -EOVERFLOW ; goto out_unlock; }
net/netfilter/nf_nat_proto.c +9 -5
@@ -373,7 +373,7 @@ unsigned int nf_nat_manip_pkt(struct sk_buff *skb, struct nf_conn *ct,return NF_ACCEPT ;break ;default : -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 );break ; }
@@ -491,7 +491,7 @@ void nf_nat_csum_recalc(struct sk_buff *skb,#endif } -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 ); } int nf_nat_icmp_reply_translation(struct sk_buff *skb,
@@ -509,7 +509,8 @@ int nf_nat_icmp_reply_translation(struct sk_buff *skb,struct nf_conntrack_tuple target;unsigned long statusbit; -WARN_ON (ctinfo !=IP_CT_RELATED && ctinfo !=IP_CT_RELATED_REPLY ); +if (unlikely (ctinfo !=IP_CT_RELATED && ctinfo !=IP_CT_RELATED_REPLY )) +DEBUG_NET_WARN_ON_ONCE (1 );if (skb_ensure_writable (skb, hdrlen +sizeof (*inside)))return 0 ;
@@ -823,7 +824,8 @@ int nf_nat_icmpv6_reply_translation(struct sk_buff *skb,struct nf_conntrack_tuple target;unsigned long statusbit; -WARN_ON (ctinfo !=IP_CT_RELATED && ctinfo !=IP_CT_RELATED_REPLY ); +if (unlikely (ctinfo !=IP_CT_RELATED && ctinfo !=IP_CT_RELATED_REPLY )) +DEBUG_NET_WARN_ON_ONCE (1 );if (skb_ensure_writable (skb, hdrlen +sizeof (*inside)))return 0 ;
@@ -1074,8 +1076,10 @@ int nf_nat_inet_register_fn(struct net *net, const struct nf_hook_ops *ops) {int ret; -if (WARN_ON_ONCE (ops->pf !=NFPROTO_INET )) +if (ops->pf !=NFPROTO_INET ) { +DEBUG_NET_WARN_ON_ONCE (1 );return -EINVAL ; + } ret =nf_nat_register_fn (net,NFPROTO_IPV6 , ops, nf_nat_ipv6_ops,ARRAY_SIZE (nf_nat_ipv6_ops));
net/netfilter/nf_nat_redirect.c +3 -2
@@ -52,8 +52,9 @@ nf_nat_redirect_ipv4(struct sk_buff *skb, const struct nf_nat_range2 *range, {union nf_inet_addr newdst = {}; -WARN_ON (hooknum !=NF_INET_PRE_ROUTING && - hooknum !=NF_INET_LOCAL_OUT ); +if (unlikely (hooknum !=NF_INET_PRE_ROUTING && + hooknum !=NF_INET_LOCAL_OUT )) +DEBUG_NET_WARN_ON_ONCE (1 );/* Local packets: make them go to loopback */ if (hooknum ==NF_INET_LOCAL_OUT ) {
Signature · 1 line
2.54.0
PATCH 6/9 netfilter: tproxy: use DEBUG_NET_WARN_ON_ONCE for protocol fallbacks
In reply to Fernando Fernandez ManceraReplace WARN_ON calls with DEBUG_NET_WARN_ON_ONCE in the default switch blocks of nf_tproxy_get_sock_v4 and v6. Unsupported transport protocols are already safely handled by returning a NULL socket pointer. This prevents unnecessary system panics when panic_on_warn=1 is enabled in production systems.
--- net/ipv4/netfilter/nf_tproxy_ipv4.c | 2 +- net/ipv6/netfilter/nf_tproxy_ipv6.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
net/ipv4/netfilter/nf_tproxy_ipv4.c +1 -1
@@ -137,7 +137,7 @@ nf_tproxy_get_sock_v4(struct net *net, struct sk_buff *skb, }break ;default : -WARN_ON (1 ); +DEBUG_NET_WARN_ON_ONCE (1 ); sk =NULL ; }
net/ipv6/netfilter/nf_tproxy_ipv6.c +1 -1
@@ -136,7 +136,7 @@ nf_tproxy_get_sock_v6(struct net *net, struct sk_buff *skb, int thoff, }break ;default : -WARN_ON (1 ); +DEBUG_NET_WARN_ON_ONCE (1 ); sk =NULL ; }
Signature · 1 line
2.54.0
PATCH 7/9 netfilter: bpf: use DEBUG_NET_WARN_ON_ONCE for missing BTF structures
In reply to Fernando Fernandez ManceraReplace WARN_ON_ONCE with DEBUG_NET_WARN_ON_ONCE in nf_ptr_to_btf_id. The function already returns false when a structure lookup fails, which causes the BPF verifier to reject the program load and report the error cleanly to userspace. This prevents unnecessary system panics when panic_on_warn=1 is enabled in production systems.
--- net/netfilter/nf_bpf_link.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/netfilter/nf_bpf_link.c +3 -1
@@ -280,8 +280,10 @@ static bool nf_ptr_to_btf_id(struct bpf_insn_access_aux *info, const char *name)return false; type_id =btf_find_by_name_kind (btf, name,BTF_KIND_STRUCT ); -if (WARN_ON_ONCE (type_id <0 )) +if (unlikely (type_id <0 )) { +DEBUG_NET_WARN_ON_ONCE (1 );return false; + } info->btf = btf; info->btf_id = type_id;
Signature · 1 line
2.54.0
PATCH 8/9 netfilter: flowtable: use DEBUG_NET_WARN_ON_ONCE in offload path
In reply to Fernando Fernandez ManceraReplace WARN_ON and WARN_ON_ONCE with DEBUG_NET_WARN_ON_ONCE in the flowtable core, IP hook, and offload paths. Errors are handled properly in packet path and in control-plane meaningful errors are returned to the user. This prevents unnecessary system panics when panic_on_warn=1 is enabled in production systems.
--- net/netfilter/nf_flow_table_core.c | 4 ++-- net/netfilter/nf_flow_table_ip.c | 4 ++-- net/netfilter/nf_flow_table_offload.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-)
net/netfilter/nf_flow_table_core.c +2 -2
@@ -141,7 +141,7 @@ static int flow_offload_fill_route(struct flow_offload *flow, flow_tuple->dst_cookie =flow_offload_dst_cookie (flow_tuple);break ;default : -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 );break ; } flow_tuple->xmit_type = route->tuple[dir].xmit_type;
@@ -534,7 +534,7 @@ static void nf_flow_table_extend_ct_timeout(struct nf_conn *ct) new_timeout =nf_flow_table_tcp_timeout (ct);break ;default : -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 );break ; }
net/netfilter/nf_flow_table_ip.c +2 -2
@@ -906,7 +906,7 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb, xmit.source = tuplehash->tuple.out.h_source;break ;default : -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 );return NF_DROP ; } xmit.tuple = other_tuple;
@@ -1227,7 +1227,7 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb, xmit.source = tuplehash->tuple.out.h_source;break ;default : -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 );return NF_DROP ; } xmit.tuple = other_tuple;
net/netfilter/nf_flow_table_offload.c +2 -2
@@ -1055,7 +1055,7 @@ static void flow_offload_work_handler(struct work_struct *work)NF_FLOW_TABLE_STAT_DEC_ATOMIC (net, count_wq_stats);break ;default : -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 ); }clear_bit (NF_FLOW_HW_PENDING , &offload->flow->flags);
@@ -1180,7 +1180,7 @@ static int nf_flow_table_block_setup(struct nf_flowtable *flowtable, }break ;default : -WARN_ON_ONCE (1 ); +DEBUG_NET_WARN_ON_ONCE (1 ); err = -EOPNOTSUPP ; }up_write (&flowtable->flow_block_lock);
Signature · 1 line
2.54.0
PATCH 9/9 netfilter: conncount: use DEBUG_NET_WARN_ON_ONCE on reaching count limit
In reply to Fernando Fernandez ManceraReplace WARN_ON_ONCE with DEBUG_NET_WARN_ON_ONCE in __nf_conncount_add. The function handles count limit breaches safely by returning -EOVERFLOW, so a production backtrace is not needed. This prevents unnecessary system panics when panic_on_warn=1 is enabled in production systems.
--- net/netfilter/nf_conncount.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/netfilter/nf_conncount.c +2 -1
@@ -246,7 +246,8 @@ static int __nf_conncount_add(struct net *net, list->last_gc_count = list->count; add_new_node: -if (WARN_ON_ONCE (list->count >INT_MAX )) { +if (unlikely (list->count >INT_MAX )) { +DEBUG_NET_WARN_ON_ONCE (1 ); err = -EOVERFLOW ; goto out_put; }
Signature · 1 line
2.54.0
Quoted 10 lines · Fernando Fernandez Mancera
This patch series replaces raw
WARN_ONandWARN_ON_ONCEmacros withDEBUG_NET_WARN_ON_ONCEacross various netfilter subsystems.Currently, several internal invariant checks use standard warnings on packet processing paths or control-plane loops. If triggered, these can trigger full system panics when panic_on_warn=1 is enabled. In most of these cases, the condition is already handled gracefully by dropping the packet, applying a defensive fallback, or returning a proper error code to userspace via netlink.
Quoted 5 lines
By migrating to
DEBUG_NET_WARN_ON_ONCE, we preserve full stack trace diagnostic capability for developers running kernels compiled withCONFIG_DEBUG_NET=y, while protecting production environments from system panics.
And of course, the tile is not formatted properly for the cover letter. It should be:
"netfilter: replace raw warnings with network debug macros"
*sigh*
Thanks,
Fernando.