Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
fork

Configure Feed

Select the types of activity you want to include in your feed.

[NETFILTER]: SNMP NAT: fix memory corruption

Fix memory corruption caused by snmp_trap_decode:

- When snmp_trap_decode fails before the id and address are allocated,
the pointers contain random memory, but are freed by the caller
(snmp_parse_mangle).

- When snmp_trap_decode fails after allocating just the ID, it tries
to free both address and ID, but the address pointer still contains
random memory. The caller frees both ID and random memory again.

- When snmp_trap_decode fails after allocating both, it frees both,
and the callers frees both again.

The corruption can be triggered remotely when the ip_nat_snmp_basic
module is loaded and traffic on port 161 or 162 is NATed.

Found by multiple testcases of the trap-app and trap-enc groups of the
PROTOS c06-snmpv1 testsuite.

Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Patrick McHardy and committed by
David S. Miller
f41d5bb1 f5565f4a

+7 -8
+7 -8
net/ipv4/netfilter/ip_nat_snmp_basic.c
··· 1003 1003 1004 1004 return 1; 1005 1005 1006 + err_addr_free: 1007 + kfree((unsigned long *)trap->ip_address); 1008 + 1006 1009 err_id_free: 1007 1010 kfree(trap->id); 1008 1011 1009 - err_addr_free: 1010 - kfree((unsigned long *)trap->ip_address); 1011 - 1012 1012 return 0; 1013 1013 } 1014 1014 ··· 1126 1126 struct snmp_v1_trap trap; 1127 1127 unsigned char ret = snmp_trap_decode(&ctx, &trap, map, check); 1128 1128 1129 - /* Discard trap allocations regardless */ 1130 - kfree(trap.id); 1131 - kfree((unsigned long *)trap.ip_address); 1132 - 1133 - if (!ret) 1129 + if (ret) { 1130 + kfree(trap.id); 1131 + kfree((unsigned long *)trap.ip_address); 1132 + } else 1134 1133 return ret; 1135 1134 1136 1135 } else {