From nobody Sat Mar 19 17:53:34 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 885361A28265; Sat, 19 Mar 2022 17:53:34 +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 4KLT5B3CKcz4ccF; Sat, 19 Mar 2022 17:53:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1647712414; 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=xXQbDCs60DX8m3PO5XP/LYmrKz4QwWakyiiWJ0taGVc=; b=Yaw5/GcN6Eut5qxK1UhQmmCtqIGW8qC3jRQrcuSHM247oagYjLLyySjaEsX9troq7sJMtQ S53OTcsNY3xprfhU4izFVACOWvTe8YMQ7NzD/bUlSKB5km89+Acl9V1VsCOjEeHM3yQpiu BWK4FqzQzmUigEOTyKN3PznYiPDtMYw84BdO2YKfavg5dhegeQpNUNokD44NN6Dfm3cD70 xYG35SLlzBhnSOoWgLVx5dOuXk29MVaj9N8KlEwZBRgAtrnO1R5gYeTaXx1LTxBIB7Y0B8 lfcFS//WtSGpLXCKnAlT2dZscmWHy1AeNqbCv/6G9QVx48xi5n1r8l0gsFx7eg== 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 4FB0C17D35; Sat, 19 Mar 2022 17:53:34 +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 22JHrYL1003959; Sat, 19 Mar 2022 17:53:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 22JHrYA5003958; Sat, 19 Mar 2022 17:53:34 GMT (envelope-from git) Date: Sat, 19 Mar 2022 17:53:34 GMT Message-Id: <202203191753.22JHrYA5003958@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Vincenzo Maffione Subject: git: 9df8dd3ea36c - stable/13 - 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: vmaffione X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 9df8dd3ea36c8b3abe8fc182647472ca9cd83efd Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1647712414; 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=xXQbDCs60DX8m3PO5XP/LYmrKz4QwWakyiiWJ0taGVc=; b=XPy5r4T8uPCDM7ftF/7L15or9iI8/5UGpGsSdHZKcsYxgeKUW/X66lgYurgQJXZM1mNx90 8Wg8fRT9EbUcJoPfIT32744f6AT3jWbe+JMk0TZkKdTkXfx/DUh/BF2KBokiuVwwAK6dFE yecCiVQZcA51kTKWIstUZz5arfzE4hUBwV0CIVfEjtUdHj+PNEI5EjdNvZzh7Aue05t0eI ZmEkNh6Jakl6BG7812OL/kHYle86v3qDnXDWuezHl0gz37W119gvxGZyyb3UZarICAQdBK HynWCbjh8w2vdtcXGQL+zGUY9kHm2mhIbOVxGUjPMMS+7YvE4IZVd7idxbvlaQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1647712414; a=rsa-sha256; cv=none; b=oy/3187WJuNhSbiU+/m6bPRMnkM2JW612er1vhNPBJPr4xAn+qzx/+I2sGmkQHaPCKzhbM kk3HOAUc6sZkOja7//cPHP7NWqCHunTbNpOsRLWFbr/RCP23puLH+cSu6oApVicxZmoKSu slqVpzYtqnqj1KiBttikGYI8ZthnCDKT/lspGWLQP142tpZk/UUhXoxNH350X27AviYJXu 58pplcd1Gtex1TUvxmT6gxsGBuw8BgQFjKQzTsVGtRmBYBr3Z53KKt6CHxU7EEETNznSfZ yyI3Y//zn0W0D4Iwy5+EDkSiUMLik1tPaQ96YxZMSW1beqRgV/Xo4rifbGuYtw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by vmaffione: URL: https://cgit.FreeBSD.org/src/commit/?id=9df8dd3ea36c8b3abe8fc182647472ca9cd83efd commit 9df8dd3ea36c8b3abe8fc182647472ca9cd83efd Author: Vincenzo Maffione AuthorDate: 2022-03-16 06:57:54 +0000 Commit: Vincenzo Maffione CommitDate: 2022-03-19 17:36:27 +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) --- 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 f9698096b47a..0c04098bb401 100644 --- a/sys/dev/netmap/netmap.c +++ b/sys/dev/netmap/netmap.c @@ -3096,7 +3096,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; @@ -3144,8 +3144,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;