netfilter: x_tables: fix unconditional helper 12/154912/1
authorFlorian Westphal <fw@strlen.de>
Tue, 22 Mar 2016 17:02:52 +0000 (18:02 +0100)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Wed, 11 Oct 2017 11:15:37 +0000 (20:15 +0900)
commit80d19aafa9b53c1627f2c6532e1719746214620b
tree712633399a085bb206f246588c9878ea3ebe34bd
parent68e9ca49b6e6b6e082c977cd6d4e372dda2d89d2
netfilter: x_tables: fix unconditional helper

commit 54d83fc74aa9ec72794373cb47432c5f7fb1a309 upstream.

Ben Hawkes says:

 In the mark_source_chains function (net/ipv4/netfilter/ip_tables.c) it
 is possible for a user-supplied ipt_entry structure to have a large
 next_offset field. This field is not bounds checked prior to writing a
 counter value at the supplied offset.

Problem is that mark_source_chains should not have been called --
the rule doesn't have a next entry, so its supposed to return
an absolute verdict of either ACCEPT or DROP.

However, the function conditional() doesn't work as the name implies.
It only checks that the rule is using wildcard address matching.

However, an unconditional rule must also not be using any matches
(no -m args).

The underflow validator only checked the addresses, therefore
passing the 'unconditional absolute verdict' test, while
mark_source_chains also tested for presence of matches, and thus
proceeeded to the next (not-existent) rule.

Unify this so that all the callers have same idea of 'unconditional rule'.

Reported-by: Ben Hawkes <hawkes@google.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Willy Tarreau <w@1wt.eu>
[sw0312.kim: cherry-pick from linux-3.10.y to fix CVE-2016-3134]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: I9933fbbadd0d7490b33fd7248576e0f96d2d6b76
net/ipv4/netfilter/arp_tables.c
net/ipv4/netfilter/ip_tables.c
net/ipv6/netfilter/ip6_tables.c