A vulnerability in the atodn() function used by the legacy pluto daemon can
lead to a remote buffer overflow when parsing DNS TXT records in manually
configured Opportunistic Encryption setups. All versions since 2.0.0 are affected.
An audit of code from The Libreswan Project revealed a remote buffer overflow in
the atodn() function used by both libreswan, openswan, and older versions of
strongSwan and superfreeswan when called from atoid(). Vulnerable are strongSwan
versions 2.0.0 to 4.3.4.
When X.509 support was added to FreeS/WAN, ASN.1 parsing was added to the
atoid() function, which converts an ASCII ID representation into an internal
struct id representation using a static buffer via the
temporary_cyclic_buffer() function.
When enabling Opportunistic Encryption ("OE"), which strongSwan does not permit
via the ipsec.conf configuration file but which experts can set up manually
using the ipsec whack script, the pluto daemon requests DNS TXT records to
obtain public RSA keys of itself and its peers. These records can contain an
IPsec gateway specification with a fully qualified hostname that is passed to
atoid().
While DNS TXT records cannot contain ASN.1 representations, the code mistakenly
checked for such an interpretation if the DNS TXT FQDN contained an = symbol.
Since DNS TXT buffers can be larger than what the ASN.1 parsing code expected,
parsing such a record can trigger a buffer overflow, leading to remote code
execution, specifically when overflowing into the struct kernel_ops table of
function pointers.
The strongSwan atodn() function was totally rewritten with the 4.3.5 release in
October 2009 and the potential vulnerability was removed.
Upgrade to strongSwan 4.3.5 or newer. A signed patch for older releases is available under https://download.strongswan.org/security/CVE-2013-2054/.
This issue is closely related to CVE-2013-2052 (Libreswan) and CVE-2013-2053 (Openswan). Credit to Florian Weimer of the Red Hat Product Security Team for finding this vulnerability and reporting it responsibly.