Skip to content

Commit 8555288

Browse files
congwanggregkh
authored andcommitted
xfrm: check id proto in validate_tmpl()
commit 6a53b75 upstream. syzbot reported a kernel warning in xfrm_state_fini(), which indicates that we have entries left in the list net->xfrm.state_all whose proto is zero. And xfrm_id_proto_match() doesn't consider them as a match with IPSEC_PROTO_ANY in this case. Proto with value 0 is probably not a valid value, at least verify_newsa_info() doesn't consider it valid either. This patch fixes it by checking the proto value in validate_tmpl() and rejecting invalid ones, like what iproute2 does in xfrm_xfrmproto_getbyname(). Reported-by: syzbot <syzkaller@googlegroups.com> Cc: Steffen Klassert <steffen.klassert@secunet.com> Cc: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 46b3171 commit 8555288

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

net/xfrm/xfrm_user.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,21 @@ static int validate_tmpl(int nr, struct xfrm_user_tmpl *ut, u16 family)
14061406
default:
14071407
return -EINVAL;
14081408
}
1409+
1410+
switch (ut[i].id.proto) {
1411+
case IPPROTO_AH:
1412+
case IPPROTO_ESP:
1413+
case IPPROTO_COMP:
1414+
#if IS_ENABLED(CONFIG_IPV6)
1415+
case IPPROTO_ROUTING:
1416+
case IPPROTO_DSTOPTS:
1417+
#endif
1418+
case IPSEC_PROTO_ANY:
1419+
break;
1420+
default:
1421+
return -EINVAL;
1422+
}
1423+
14091424
}
14101425

14111426
return 0;

0 commit comments

Comments
 (0)