Skip to content

Commit 07bf790

Browse files
committed
xfrm: Validate address prefix lengths in the xfrm selector.
We don't validate the address prefix lengths in the xfrm selector we got from userspace. This can lead to undefined behaviour in the address matching functions if the prefix is too big for the given address family. Fix this by checking the prefixes and refuse SA/policy insertation when a prefix is invalid. Fixes: 1da177e ("Linux-2.6.12-rc2") Reported-by: Air Icy <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent 25432eb commit 07bf790

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

net/xfrm/xfrm_user.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,16 @@ static int verify_newsa_info(struct xfrm_usersa_info *p,
151151
err = -EINVAL;
152152
switch (p->family) {
153153
case AF_INET:
154+
if (p->sel.prefixlen_d > 32 || p->sel.prefixlen_s > 32)
155+
goto out;
156+
154157
break;
155158

156159
case AF_INET6:
157160
#if IS_ENABLED(CONFIG_IPV6)
161+
if (p->sel.prefixlen_d > 128 || p->sel.prefixlen_s > 128)
162+
goto out;
163+
158164
break;
159165
#else
160166
err = -EAFNOSUPPORT;
@@ -1359,10 +1365,16 @@ static int verify_newpolicy_info(struct xfrm_userpolicy_info *p)
13591365

13601366
switch (p->sel.family) {
13611367
case AF_INET:
1368+
if (p->sel.prefixlen_d > 32 || p->sel.prefixlen_s > 32)
1369+
return -EINVAL;
1370+
13621371
break;
13631372

13641373
case AF_INET6:
13651374
#if IS_ENABLED(CONFIG_IPV6)
1375+
if (p->sel.prefixlen_d > 128 || p->sel.prefixlen_s > 128)
1376+
return -EINVAL;
1377+
13661378
break;
13671379
#else
13681380
return -EAFNOSUPPORT;

0 commit comments

Comments
 (0)