Skip to content

Commit f674e72

Browse files
Dan Carpenterdavem330
authored andcommitted
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() Signed-off-by: Dan Carpenter <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 862096a commit f674e72

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

net/key/af_key.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,6 +1923,9 @@ parse_ipsecrequests(struct xfrm_policy *xp, struct sadb_x_policy *pol)
19231923
int len = pol->sadb_x_policy_len*8 - sizeof(struct sadb_x_policy);
19241924
struct sadb_x_ipsecrequest *rq = (void*)(pol+1);
19251925

1926+
if (pol->sadb_x_policy_len * 8 < sizeof(struct sadb_x_policy))
1927+
return -EINVAL;
1928+
19261929
while (len >= sizeof(struct sadb_x_ipsecrequest)) {
19271930
if ((err = parse_ipsecrequest(xp, rq)) < 0)
19281931
return err;

0 commit comments

Comments
 (0)