From nobody Wed May 25 20:30:08 2022 X-Original-To: dev-commits-src-main@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 345721B4C230; Wed, 25 May 2022 20:30:09 +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 4L7jNx00Gwz3j19; Wed, 25 May 2022 20:30:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1653510609; 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=fvEx/KVI9uzc/HbnXCijaTGOxrGKKZHF+6nPZVtrofI=; b=q0h5Bly8q1FRuNp4TSH509ndkf90/V00Sbiua292OGck8Pyv1RtvGJVgxPbe4c12Ua7kk9 FHQFGcT2BtUO4UUKpdNRdG+046jNIazT8JZKmKYznCfZt+3rdLgkNZTX/Cj+8na1UBFY45 zCTgNxpOmc3BjwDPo1Dd4C5jDhQwWi9v1AfrwEKgH6OLkbQOYCr7AwoVV94aE5NTY9dGQR gv3Ob2xXCZZh3zdzjJV/ArDa0lRgOW3NZFVI8o5DnKgq6hrZmYVEpMCaYAyj4aPzYMCk0Z NmmswBiWWVpfoffdXvT+NASuKofy4V16dY88iiDkudoCqIDZW7lfOP49RLQTTg== 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 BE96F200BD; Wed, 25 May 2022 20:30:08 +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 24PKU8A3040560; Wed, 25 May 2022 20:30:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 24PKU8R9040557; Wed, 25 May 2022 20:30:08 GMT (envelope-from git) Date: Wed, 25 May 2022 20:30:08 GMT Message-Id: <202205252030.24PKU8R9040557@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: 579b45e20328 - main - unix/*: check new control size in unp_internalize() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 579b45e203287f78cfb4a91491893b2919aa9ec4 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1653510609; 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=fvEx/KVI9uzc/HbnXCijaTGOxrGKKZHF+6nPZVtrofI=; b=vnLnCimj6Ro5jgUvOcuN0TusukRsS9CRje5bKZe8j9THNguFJJm4lTfi34LKEFG1taf/fX xIfufMOrJhHIlP7F/wCvvN7UGdMoujeAZwDQ2KeXqu6P7NLpXZTcBrUb7joyULhxFhBFwq 1GO3dIsuWS/UfBkbwbtc855ZQ4gRILcnk311YTWSTrF5pEPyrr9MnzTAqrADAKzUaxs7bp 1k+cbc1d1aqNa9sxamnsWaDJxTqQ8W2XpweMEfLPCyG/Z8JIUaamk4rNcXLGUDJQDbiHHg O74SKoE0niXBJJN+HPFgMidVI4+5LGteWLVZSqSi8s4Jf/xbysnXVoNkPNJTCw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1653510609; a=rsa-sha256; cv=none; b=fjfcpw43vtkl5M3d9iuY2mKSWYXJa//GXbl7ZrX+4+u0KBWm0VOnJjTH5LTUIqLDWXwgr1 gvrFjuwqcyddLRTHp/6WJxd6QVvo3J+tacxCbV1Etaff/mP0MGx7ROPlyKSnXnxTtFaglM RcTx/nDEV7eZvosj6NuGUqdqUsR/78TCXdP+vFi8RLMR/RL/RNPjOs9NSJMbcarBAgRKDh FuR/6MLbDDgkd+y2ScDtQvcNgcubkShzxlxJsdaSPleffpkUxneW54yWEk3PrfpUU+7tdF InGtn7a2ioJen1LwSoDWrn+DKDFnWZSThRgDzLlqIypGcwZd6qzlnJxaojApUA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=579b45e203287f78cfb4a91491893b2919aa9ec4 commit 579b45e203287f78cfb4a91491893b2919aa9ec4 Author: Gleb Smirnoff AuthorDate: 2022-05-25 20:29:13 +0000 Commit: Gleb Smirnoff CommitDate: 2022-05-25 20:29:13 +0000 unix/*: check new control size in unp_internalize() Now that we call sbcreatecontrol() with M_WAITOK, we are expected to pass a valid size. Return same error code, we are returning for an oversized control from sockargs(). Reviewed by: markj Differential revision: https://reviews.freebsd.org/D35317 --- sys/kern/uipc_usrreq.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index f08b972c6de6..cf9e04034760 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -2241,6 +2241,19 @@ unp_internalize(struct mbuf **controlp, struct thread *td) oldfds = datalen / sizeof (int); if (oldfds == 0) break; + /* On some machines sizeof pointer is bigger than + * sizeof int, so we need to check if data fits into + * single mbuf. We could allocate several mbufs, and + * unp_externalize() should even properly handle that. + * But it is not worth to complicate the code for an + * insane scenario of passing over 200 file descriptors + * at once. + */ + newlen = oldfds * sizeof(fdep[0]); + if (CMSG_SPACE(newlen) > MCLBYTES) { + error = EMSGSIZE; + goto out; + } /* * Check that all the FDs passed in refer to legal * files. If not, reject the entire operation. @@ -2265,7 +2278,6 @@ unp_internalize(struct mbuf **controlp, struct thread *td) * Now replace the integer FDs with pointers to the * file structure and capability rights. */ - newlen = oldfds * sizeof(fdep[0]); *controlp = sbcreatecontrol(NULL, newlen, SCM_RIGHTS, SOL_SOCKET, M_WAITOK); fdp = data;