]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
netfilter: avoid erronous array bounds warning
authorFlorian Westphal <fw@strlen.de>
Mon, 24 Sep 2018 12:10:04 +0000 (14:10 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Fri, 28 Sep 2018 12:47:40 +0000 (14:47 +0200)
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>
include/linux/netfilter.h

index 07efffd0c759d0b509dec19acb6b718cbab06031..bbe99d2b28b4c62063450b7c4dadc4013c377897 100644 (file)
@@ -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;