[RHEL7,COMMIT] ms/xfrm: check id proto in validate_tmpl()

Submitted by Vasily Averin on Dec. 3, 2020, 8:59 a.m.

Details

Message ID 202012030859.0B38x2Vl001569@vz7build.vvs.sw.ru
State New
Series "ms/xfrm: check id proto in validate_tmpl()"
Headers show

Commit Message

Vasily Averin Dec. 3, 2020, 8:59 a.m.
The commit is pushed to "branch-rh7-3.10.0-1160.6.1.vz7.171.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1160.6.1.vz7.171.1
------>
commit 5e388af20c7563b2539eeef905bfd2fef71110a3
Author: Cong Wang <xiyou.wangcong@gmail.com>
Date:   Thu Dec 3 11:59:02 2020 +0300

    ms/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().
    
    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>
    
    (cherry-picked from commit 6a53b7593233ab9e4f96873ebacc0f653a55c3e1)
    https://jira.sw.ru/browse/PSBM-123084
    Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
---
 net/xfrm/xfrm_user.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

Patch hide | download patch | download mbox

diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index 472e1e2..e2dd99f 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -1391,6 +1391,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;