From owner-dev-commits-src-all@freebsd.org Fri Sep 10 13:09:22 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 4FE786AC542; Fri, 10 Sep 2021 13:09:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4H5bmy17cqz3hM0; Fri, 10 Sep 2021 13:09:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id F202A50CE; Fri, 10 Sep 2021 13:09:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 18AD9LNY048400; Fri, 10 Sep 2021 13:09:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 18AD9Lu8048399; Fri, 10 Sep 2021 13:09:21 GMT (envelope-from git) Date: Fri, 10 Sep 2021 13:09:21 GMT Message-Id: <202109101309.18AD9Lu8048399@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 10eb2a2bde61 - main - ipsec: Validate the protocol identifier in ipsec4_ctlinput() MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 10eb2a2bde616e52ae2939df90c04483383a34f7 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Sep 2021 13:09:22 -0000 The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=10eb2a2bde616e52ae2939df90c04483383a34f7 commit 10eb2a2bde616e52ae2939df90c04483383a34f7 Author: Mark Johnston AuthorDate: 2021-09-10 13:07:59 +0000 Commit: Mark Johnston CommitDate: 2021-09-10 13:09:00 +0000 ipsec: Validate the protocol identifier in ipsec4_ctlinput() key_allocsa() expects to handle only IPSec protocols and has an assertion to this effect. However, ipsec4_ctlinput() has to handle messages from ICMP unreachable packets and was not validating the protocol number. In practice such a packet would simply fail to match any SADB entries and would thus be ignored. Reported by: syzbot+6a9ef6fcfadb9f3877fe@syzkaller.appspotmail.com Reviewed by: ae MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D31890 --- sys/netipsec/ipsec_input.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sys/netipsec/ipsec_input.c b/sys/netipsec/ipsec_input.c index 07a3ef583be8..73202cbb528b 100644 --- a/sys/netipsec/ipsec_input.c +++ b/sys/netipsec/ipsec_input.c @@ -276,6 +276,7 @@ ipsec4_ctlinput(int code, struct sockaddr *sa, void *v) struct icmp *icp; struct ip *ip = v; uint32_t pmtu, spi; + uint8_t proto; if (code != PRC_MSGSIZE || ip == NULL) return (EINVAL); @@ -289,8 +290,13 @@ ipsec4_ctlinput(int code, struct sockaddr *sa, void *v) if (pmtu < V_ip4_ipsec_min_pmtu) return (EINVAL); + proto = ip->ip_p; + if (proto != IPPROTO_ESP && proto != IPPROTO_AH && + proto != IPPROTO_IPCOMP) + return (EINVAL); + memcpy(&spi, (caddr_t)ip + (ip->ip_hl << 2), sizeof(spi)); - sav = key_allocsa((union sockaddr_union *)sa, ip->ip_p, spi); + sav = key_allocsa((union sockaddr_union *)sa, proto, spi); if (sav == NULL) return (ENOENT);