netfilter: nf_nat_snmp_basic: add missing length checks in ASN.1 cbs
authorJann Horn <jannh@google.com>
Wed, 6 Feb 2019 21:56:15 +0000 (22:56 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 23 Feb 2019 08:07:27 +0000 (09:07 +0100)
commit6a3f7237871c4d5c090ab9a6fce3ba6a1baf1f82
tree7c636d7202a8898fd910db675ced4455127bc778
parenta7e0b9680aecee238ab50c3781131c40df68a63b
netfilter: nf_nat_snmp_basic: add missing length checks in ASN.1 cbs

commit c4c07b4d6fa1f11880eab8e076d3d060ef3f55fc upstream.

The generic ASN.1 decoder infrastructure doesn't guarantee that callbacks
will get as much data as they expect; callbacks have to check the `datalen`
parameter before looking at `data`. Make sure that snmp_version() and
snmp_helper() don't read/write beyond the end of the packet data.

(Also move the assignment to `pdata` down below the check to make it clear
that it isn't necessarily a pointer we can use before the `datalen` check.)

Fixes: cc2d58634e0f ("netfilter: nf_nat_snmp_basic: use asn1 decoder library")
Signed-off-by: Jann Horn <jannh@google.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/ipv4/netfilter/nf_nat_snmp_basic_main.c