Skip to contentSkip to conversation

xfrm: check id proto in validate_tmpl()

PATCH In review Cong Wang 2 participants 2 messages Nov 27, 2017 – Nov 29, 2017

Subsystems (3)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH 1/1 xfrm: check id proto in validate_tmpl()

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().

Cc Steffen Klassert <[email protected]>
Cc Herbert Xu <[email protected]>
---
 net/xfrm/xfrm_user.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
net/xfrm/xfrm_user.c +15 -0
index 983b0233767b..c2cfcc6fdb34 100644
@@ -1445,6 +1445,21 @@ static int validate_tmpl(int nr, struct xfrm_user_tmpl *ut, u16 family)
 		default:
 			return -EINVAL;
 		}
+
+		switch (ut[i].id.proto) {
+		case IPPROTO_AH:
+		case IPPROTO_ESP:
+		case IPPROTO_COMP:
+#if IS_ENABLED(CONFIG_IPV6)
+		case IPPROTO_ROUTING:
+		case IPPROTO_DSTOPTS:
+#endif
+		case IPSEC_PROTO_ANY:
+			break;
+		default:
+			return -EINVAL;
+		}
+
 	}
 
 	return 0;
Signature · 1 line
2.13.0
maintainer
#1 lore raw
Quoted 9 lines · Cong Wang

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.

Quoted 8 lines

This patch fixes it by checking the proto value in validate_tmpl() and rejecting invalid ones, like what iproute2 does in xfrm_xfrmproto_getbyname().

Cc Steffen Klassert <[email protected]>
Cc Herbert Xu <[email protected]>

Patch applied, thanks!