Commit 907c383f authored by Stefan Nuernberger's avatar Stefan Nuernberger Committed by Kleber Sacilotto de Souza

net/ipv4: defensive cipso option parsing

BugLink: https://bugs.launchpad.net/bugs/1810947

commit 076ed3da upstream.

commit 40413955 ("Cipso: cipso_v4_optptr enter infinite loop") fixed
a possible infinite loop in the IP option parsing of CIPSO. The fix
assumes that ip_options_compile filtered out all zero length options and
that no other one-byte options beside IPOPT_END and IPOPT_NOOP exist.
While this assumption currently holds true, add explicit checks for zero
length and invalid length options to be safe for the future. Even though
ip_options_compile should have validated the options, the introduction of
new one-byte options can still confuse this code without the additional
checks.
Signed-off-by: default avatarStefan Nuernberger <snu@amazon.com>
Cc: David Woodhouse <dwmw@amazon.co.uk>
Cc: Simon Veith <sveith@amazon.de>
Cc: stable@vger.kernel.org
Acked-by: default avatarPaul Moore <paul@paul-moore.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarJuerg Haefliger <juergh@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent 0913fa48
...@@ -1582,7 +1582,7 @@ static int cipso_v4_parsetag_loc(const struct cipso_v4_doi *doi_def, ...@@ -1582,7 +1582,7 @@ static int cipso_v4_parsetag_loc(const struct cipso_v4_doi *doi_def,
* *
* Description: * Description:
* Parse the packet's IP header looking for a CIPSO option. Returns a pointer * Parse the packet's IP header looking for a CIPSO option. Returns a pointer
* to the start of the CIPSO option on success, NULL if one if not found. * to the start of the CIPSO option on success, NULL if one is not found.
* *
*/ */
unsigned char *cipso_v4_optptr(const struct sk_buff *skb) unsigned char *cipso_v4_optptr(const struct sk_buff *skb)
...@@ -1592,10 +1592,8 @@ unsigned char *cipso_v4_optptr(const struct sk_buff *skb) ...@@ -1592,10 +1592,8 @@ unsigned char *cipso_v4_optptr(const struct sk_buff *skb)
int optlen; int optlen;
int taglen; int taglen;
for (optlen = iph->ihl*4 - sizeof(struct iphdr); optlen > 0; ) { for (optlen = iph->ihl*4 - sizeof(struct iphdr); optlen > 1; ) {
switch (optptr[0]) { switch (optptr[0]) {
case IPOPT_CIPSO:
return optptr;
case IPOPT_END: case IPOPT_END:
return NULL; return NULL;
case IPOPT_NOOP: case IPOPT_NOOP:
...@@ -1604,6 +1602,11 @@ unsigned char *cipso_v4_optptr(const struct sk_buff *skb) ...@@ -1604,6 +1602,11 @@ unsigned char *cipso_v4_optptr(const struct sk_buff *skb)
default: default:
taglen = optptr[1]; taglen = optptr[1];
} }
if (!taglen || taglen > optlen)
return NULL;
if (optptr[0] == IPOPT_CIPSO)
return optptr;
optlen -= taglen; optlen -= taglen;
optptr += taglen; optptr += taglen;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment