Skip to content

Commit f313985

Browse files
qsngregkh
authored andcommitted
xfrm: validate new SA's prefixlen using SA family when sel.family is unset
[ Upstream commit 3f0ab59 ] This expands the validation introduced in commit 07bf790 ("xfrm: Validate address prefix lengths in the xfrm selector.") syzbot created an SA with usersa.sel.family = AF_UNSPEC usersa.sel.prefixlen_s = 128 usersa.family = AF_INET Because of the AF_UNSPEC selector, verify_newsa_info doesn't put limits on prefixlen_{s,d}. But then copy_from_user_state sets x->sel.family to usersa.family (AF_INET). Do the same conversion in verify_newsa_info before validating prefixlen_{s,d}, since that's how prefixlen is going to be used later on. Reported-by: syzbot+cc39f136925517aed571@syzkaller.appspotmail.com Fixes: 1da177e ("Linux-2.6.12-rc2") Signed-off-by: Sabrina Dubroca <sd@queasysnail.net> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com> Signed-off-by: Antony Antony <antony.antony@secunet.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 974955b commit f313985

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

net/xfrm/xfrm_user.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ static int verify_newsa_info(struct xfrm_usersa_info *p,
148148
struct nlattr **attrs)
149149
{
150150
int err;
151+
u16 family = p->sel.family;
151152

152153
err = -EINVAL;
153154
switch (p->family) {
@@ -166,7 +167,10 @@ static int verify_newsa_info(struct xfrm_usersa_info *p,
166167
goto out;
167168
}
168169

169-
switch (p->sel.family) {
170+
if (!family && !(p->flags & XFRM_STATE_AF_UNSPEC))
171+
family = p->family;
172+
173+
switch (family) {
170174
case AF_UNSPEC:
171175
break;
172176

0 commit comments

Comments
 (0)