ASA-2019-00123 – Linux kernel: Out-of-bounds read and write in SNMP NAT module

Allele Security Alert



ASA-2019-00123, CVE-2019-9162


Out-of-bounds read and write in SNMP NAT module


Linux foundation


Linux kernel

Affected version(s)

Linux kernel versions before 5.0

Linux kernel versions 4.20.x before 4.20.12
Linux kernel versions 4.19.x before 4.19.25
Linux kernel versions 4.14.x before 4.14.103

Linux kernel versions since the following commit:

netfilter: nf_nat_snmp_basic: use asn1 decoder library

Fixed version(s)

Linux kernel version 5.0

Linux kernel version 4.20.12
Linux kernel version 4.19.25
Linux kernel version 4.14.103

Linux kernel versions with the following commit applied:

netfilter: nf_nat_snmp_basic: add missing length checks in ASN.1 cbs

Proof of concept



It was found that there are insufficient ASN.1 sequence length checks (a.k.a. an array index error) in the Linux kernel in the snmp_version() and snmp_helper() functions in the net/ipv4/netfilter/nf_nat_snmp_basic_main.c in the [nf_nat_snmp_basic] module making out-of-bounds read and write operations possible. An unprivileged local attacker can use this flaw to cause a kernel OOPS condition and thus a denial of service (DoS). Due to the nature of the flaw, an attack from the network or privilege escalation cannot be fully ruled out.

Technical details

The commit cc2d58634e0f (“netfilter: nf_nat_snmp_basic: use asn1 decoder library”, first in 4.16) changed the nf_nat_snmp_basic module (which, when enabled, parses and modifies the ASN.1-encoded payloads of SNMP messages) so that the kernel’s ASN.1 infrastructure is used instead of an open-coded parser. The common ASN.1 decoder can invoke callbacks when certain objects are encountered. The SNMP helper has two such callbacks defined in nf_nat_snmp_basic.asn1:

– For the `version` field of a `Message` (a `INTEGER`), snmp_version() is invoked.
– For each `IpAddress` (according to RFC 1155, a 4-byte octet string), snmp_helper() is invoked.

These callbacks contain the following code:

int snmp_version(void *context, size_t hdrlen, unsigned char tag, const void *data, size_t datalen)
if (*(unsigned char *)data > 1)
return -ENOTSUPP;
return 1;
int snmp_helper(void *context, size_t hdrlen, unsigned char tag, const void *data, size_t datalen)
struct snmp_ctx *ctx = (struct snmp_ctx *)context;
__be32 *pdata = (__be32 *)data;

if (*pdata == ctx->from) {
pr_debug("%s: %pI4 to %pI4\n", __func__,
(void *)&ctx->from, (void *)&ctx->to);

if (*ctx->check)
fast_csum(ctx, (unsigned char *)data - ctx->begin);
*pdata = ctx->to;

return 1;

The problem is that both of these callbacks can be invoked by the ASN.1 parser with `data` pointing at the end of the packet and `datalen==0` (even though, for the `INTEGER` type, X.690 says in section 8.3.1 that “The contents octets shall consist of one or more octets”), but they don’t check whether there is sufficient input available. This means that snmp_version() can read up to one byte out-of-bounds and leak whether that byte was <=1, and snmp_helper() can read and potentially also write up to four bytes out-of-bounds.

There are two scenarios in which this bug might be attacked:

  1. A router that performs NAT translation is explicitly set up to invoke the SNMP helper, and a device in the NATted network wants to attack the router. This is probably very rare, since the router would need to be explicitly configured to perform SNMP translation. On top of that, to corrupt memory, an attacker would need to be able to completely fill an SKB; it isn’t clear to me whether that is possible remotely.
  2. A local attacker could exploit the bug by setting up new network namespaces with an iptables configuration that invokes SNMP translation. This probably works as a local privilege escalation against some distribution kernels. The normal autoloading path for this code was only set up in commit 95c97998aa9f (“netfilter: nf_nat_snmp_basic: add missing helper alias name”, first in 4.20), but from a glance, it looks like it would be possible on kernels before 4.20 to instead first load one of the openvswitch module’s aliases “net-pf-16-proto-16-family-ovs_*” through ctrl_getfamily(), then use ovs_ct_add_helper() to trigger loading of “nf_nat_snmp_basic” through the alias “ip_nat_snmp_basic”.


Jann Horn (Google Project Zero)


Issue 1776: Linux: out-of-bounds read and write in SNMP NAT module

Linux kernel: OOB R/W in SNMP NAT module (CVE-2019-9162); virtual address 0 mappable (CVE-2019-9213)

netfilter: nf_nat_snmp_basic: add missing length checks in ASN.1 cbs

netfilter: nf_nat_snmp_basic: use asn1 decoder library

netfilter: nf_nat_snmp_basic: add missing length checks in ASN.1 cbs

netfilter: nf_nat_snmp_basic: use asn1 decoder library

Linux 5.0

Linux 4.20.12

Linux 4.14.103

Linux 4.19.25

CVE-2019-9162 - Red Hat Customer Portal


CVE-2019-9162 in Ubuntu

CVE-2019-9162 | SUSE



If there is any error in this alert or you wish a comprehensive analysis, let us know.

Last modified: November 29, 2019

We are not responsible for any data loss, device corruption or any other type of issue due to the use of any information mentioned in our security alerts.