summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorFlorian Westphal <fw@strlen.de>2018-09-24 14:10:04 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-11-04 14:51:43 +0100
commit723b7d86877da81c945dc78c02a4d523c8b238bd (patch)
tree464890afc7d8e5dfcd2b4108d715cc61cd406cdd /include
parent8d3156b3c109dbceea5ece40cfb74b3a22ee2fb1 (diff)
downloadlinux-stable-723b7d86877da81c945dc78c02a4d523c8b238bd.tar.gz
linux-stable-723b7d86877da81c945dc78c02a4d523c8b238bd.tar.bz2
linux-stable-723b7d86877da81c945dc78c02a4d523c8b238bd.zip
netfilter: avoid erronous array bounds warning
[ Upstream commit 421c119f558761556afca6a62ad183bc2d8659e0 ] Unfortunately some versions of gcc emit following warning: $ make net/xfrm/xfrm_output.o linux/compiler.h:252:20: warning: array subscript is above array bounds [-Warray-bounds] hook_head = rcu_dereference(net->nf.hooks_arp[hook]); ^~~~~~~~~~~~~~~~~~~~~ xfrm_output_resume passes skb_dst(skb)->ops->family as its 'pf' arg so compiler can't know that we'll never access hooks_arp[]. (NFPROTO_IPV4 or NFPROTO_IPV6 are only possible cases). Avoid this by adding an explicit WARN_ON_ONCE() check. This patch has no effect if the family is a compile-time constant as gcc will remove the switch() construct entirely. Reported-by: David Ahern <dsahern@gmail.com> Signed-off-by: Florian Westphal <fw@strlen.de> Reviewed-by: David Ahern <dsahern@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'include')
-rw-r--r--include/linux/netfilter.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
index dd2052f0efb7..11b7b8ab0696 100644
--- a/include/linux/netfilter.h
+++ b/include/linux/netfilter.h
@@ -215,6 +215,8 @@ static inline int nf_hook(u_int8_t pf, unsigned int hook, struct net *net,
break;
case NFPROTO_ARP:
#ifdef CONFIG_NETFILTER_FAMILY_ARP
+ if (WARN_ON_ONCE(hook >= ARRAY_SIZE(net->nf.hooks_arp)))
+ break;
hook_head = rcu_dereference(net->nf.hooks_arp[hook]);
#endif
break;