Skip to contentSkip to conversation

net/key/af_key.c: add range checks on ->sadb_x_policy_len

PATCH In review Dan Carpenter 2 participants 2 messages Sep 28, 2012 – Oct 1, 2012

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/key/af_key.c: add range checks on ->sadb_x_policy_len

Because sizeof() is size_t then if "len" is negative, it counts as a large positive value.

The call tree looks like:
pfkey_sendmsg()
-> pfkey_process()
-> pfkey_spdadd()

      -> parse_ipsecrequests()

---
This is a static checker fix. I'm not very familiar with this code. I think if we were to hit this then we would try to parse invalid data and it would return -EINVAL or similar error code pretty quickly.

net/key/af_key.c +3 -0
index 2ca7d7f..7714df0 100644
@@ -1923,6 +1923,9 @@ parse_ipsecrequests(struct xfrm_policy *xp, struct sadb_x_policy *pol)
 	int len = pol->sadb_x_policy_len*8 - sizeof(struct sadb_x_policy);
 	struct sadb_x_ipsecrequest *rq = (void*)(pol+1);
 
+	if (pol->sadb_x_policy_len * 8 < sizeof(struct sadb_x_policy))
+		return -EINVAL;
+
 	while (len >= sizeof(struct sadb_x_ipsecrequest)) {
 		if ((err = parse_ipsecrequest(xp, rq)) < 0)
 			return err;
maintainer
#1 lore raw

From: Dan Carpenter <[email protected]>
Date: Fri, 28 Sep 2012 11:21:19 +0300

Quoted 7 lines

Because sizeof() is size_t then if "len" is negative, it counts as a large positive value.

The call tree looks like:
pfkey_sendmsg()
-> pfkey_process()
-> pfkey_spdadd()

Quoted 7 lines
      -> parse_ipsecrequests()

---
This is a static checker fix. I'm not very familiar with this code. I think if we were to hit this then we would try to parse invalid data and it would return -EINVAL or similar error code pretty quickly.

Applied and queued up for -stable, thanks Dan.