From nobody Wed Apr 6 03:04:45 2022 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id C65281A85050; Wed, 6 Apr 2022 03:04:46 +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 4KY8WL0hd0z4f0X; Wed, 6 Apr 2022 03:04:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649214286; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=fEVLYSnLOBXqDGoYVi7EJE3NhT+ykccUfe1xQVpJnvA=; b=Vfef76DC2FPFMLujDLMsJDUtWxpSyvmLnC92cLqK5vnQlNSqr7eB6sKoCjqnBXyCjAdWJv 14Ic2dyQhD4kM4qirKq04KwaJIe4Rq/Va5ITTklcTK2QRY2/Tx2tFi3SxNCOM6maGiZn6y 6vgDpmCW72APVNouR9pSuaGhfZymqdV3hiVACg36++mbWz2a40HjRhmu5VYKFGj29k98oi tzcjuUFjjtZRBAhgF1RVfS8uapM7oRxFlaUXXkGoia/p8tU6UIdFwjVesjxlWqIdLUtTnw E+dal9bGeOfcavxWWE6OPY5nyNqhwKKqLs49lQ3ocNnC1GnYGQrpAyuoEsur3w== 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 C596E130F9; Wed, 6 Apr 2022 03:04:45 +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 23634j8o035099; Wed, 6 Apr 2022 03:04:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 23634j2m035098; Wed, 6 Apr 2022 03:04:45 GMT (envelope-from git) Date: Wed, 6 Apr 2022 03:04:45 GMT Message-Id: <202204060304.23634j2m035098@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ed Maste Subject: git: 0d1f1dc951c6 - releng/12.3 - netmap: Fix integer overflow in nmreq_copyin List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: emaste X-Git-Repository: src X-Git-Refname: refs/heads/releng/12.3 X-Git-Reftype: branch X-Git-Commit: 0d1f1dc951c667f9d993acba42358d115997564e Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649214286; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=fEVLYSnLOBXqDGoYVi7EJE3NhT+ykccUfe1xQVpJnvA=; b=g1b3QbTKIvyjw4o7dzrBffryGwmiZzWt6YiZckF6Q97pYiSbx0ZceTGVoXr0EvpsWxXEJp XJ1sErCXtGI4y2AQz7KAXHW5KtxsBBapXCklGXiBzbKZCXMxPKy3ZGhgO0WGpAbiVfOgJ+ NrN2ymQsdE4rf69mO0moO5vD4rw2KTq2wy5pCePewmmwcOz84AO8FELvZf8apn1HjtlJPg tr/wiWyJqNsCkZuOC4TrwXpIUieNmNGVK25gxR2uTtkVeHazdDNUBS8dfqW5gXkjeGOpvC GN/gT75o2T9lfeH/WMepYGJABSxfO18cjLBT1NKIkvzr/VW+7Ez1o0R2s3L51g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1649214286; a=rsa-sha256; cv=none; b=KTJ2ZEhAnuy4R6sfheUENcEQM8bEFi/cutTqiYnIQ1ntj78BoYl0NAyfEKCvD7hw3YRCMu 4+MNe2K8j3RhcFeoTHLslUlORGaKs7Q6sAvvLUdqCMZfwUmFPYlb695LdtgBskKQrq8+ku x6SpljMf02DhugtyqY2+vc0DbKMfHYL/zZNVFoIkuKywQCBnnv0pN6dFn2eY5daaEQ3c5X 2AOsB54rqot/C6knRNbFQJT9F1n3Yn0VdtqOOAEgfA5sJtIDbKXnoG9CsIYwyg2NVQjayA EmV6jaYXiLLcTrP6SDo2sB5weeNSWXBsX0aguU1n7N2MF9wYFl6BzOE5q+UnUQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch releng/12.3 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=0d1f1dc951c667f9d993acba42358d115997564e commit 0d1f1dc951c667f9d993acba42358d115997564e Author: Vincenzo Maffione AuthorDate: 2022-04-05 23:19:58 +0000 Commit: Ed Maste CommitDate: 2022-04-05 23:19:58 +0000 netmap: Fix integer overflow in nmreq_copyin An unsanitized field in an option could be abused, causing an integer overflow followed by kernel memory corruption. This might be used to escape jails/containers. Reported by: Reno Robert and Lucas Leong (@_wmliang_) of Trend Micro Zero Day Initiative Security: CVE-2022-23085 (cherry picked from commit 694ea59c7021c25417e6d516362d2f59b4e2c343) (cherry picked from commit 95602165e33a3045a27245cc1e61e67bf4feeed1) Approved by: so Security: FreeBSD-SA-22:04.netmap --- sys/dev/netmap/netmap.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/sys/dev/netmap/netmap.c b/sys/dev/netmap/netmap.c index 6532856b21a1..cefc72c60817 100644 --- a/sys/dev/netmap/netmap.c +++ b/sys/dev/netmap/netmap.c @@ -3086,7 +3086,7 @@ nmreq_opt_size_by_type(uint32_t nro_reqtype, uint64_t nro_size) int nmreq_copyin(struct nmreq_header *hdr, int nr_body_is_user) { - size_t rqsz, optsz, bufsz; + size_t rqsz, optsz, bufsz, optbodysz; int error = 0; char *ker = NULL, *p; struct nmreq_option **next, *src, **opt_tab; @@ -3134,8 +3134,18 @@ nmreq_copyin(struct nmreq_header *hdr, int nr_body_is_user) error = copyin(src, &buf, sizeof(*src)); if (error) goto out_err; + /* Validate nro_size to avoid integer overflow of optsz and bufsz. */ + if (buf.nro_size > NETMAP_REQ_MAXSIZE) { + error = EMSGSIZE; + goto out_err; + } optsz += sizeof(*src); - optsz += nmreq_opt_size_by_type(buf.nro_reqtype, buf.nro_size); + optbodysz = nmreq_opt_size_by_type(buf.nro_reqtype, buf.nro_size); + if (optbodysz > NETMAP_REQ_MAXSIZE) { + error = EMSGSIZE; + goto out_err; + } + optsz += optbodysz; if (rqsz + optsz > NETMAP_REQ_MAXSIZE) { error = EMSGSIZE; goto out_err;