From nobody Tue Aug 09 20:01:26 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 4M2P8k40qrz3j8Hq; Tue, 9 Aug 2022 20:01:26 +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 4M2P8k37nWz3mK9; Tue, 9 Aug 2022 20:01:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660075286; 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=8TWFRgkVr/NMjJtDyDutNbGV2KBmgDCbBRkh+Nrq74s=; b=uxSdlI7rvPwXSFkSIZ85FTuAdNwWphPCIgiyE17AMKR2XyanguTVv8CPnRFgMMeiwm0AVg 436K7NUOm7fDAahvBkdb47Fzya+TIOjR5NVS+hrDUpPZM2Sh3h2zeK69sKYSPz7MLROlI8 GgMbXTI51Y697I46RQny+nYvOzGwcKbJ2JUsuGHH4rz0q8mkDM7GXg5o80OSYyd8K4dMih xV3gXkn4G9RS9BaJCZ5Scoyp9+HATucbkpWHzoUdCUH4nJX2hFNvVyYIC9Wn0hsgnAFr4p 0ec2djXNUvfZJ32Xk8wln/k3lpQbghtkUA2AM7lHL/GVldnwfhDnRDCm/FH1/g== 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 4M2P8k2Dr8zkls; Tue, 9 Aug 2022 20:01:26 +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 279K1Qvn031432; Tue, 9 Aug 2022 20:01:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 279K1Qxe031431; Tue, 9 Aug 2022 20:01:26 GMT (envelope-from git) Date: Tue, 9 Aug 2022 20:01:26 GMT Message-Id: <202208092001.279K1Qxe031431@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 7dfe949791e7 - releng/13.1 - lib9p: Remove potential buffer overwrite in l9p_puqids() 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/releng/13.1 X-Git-Reftype: branch X-Git-Commit: 7dfe949791e764115dda17ec6b21fba2e0a86a2e Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660075286; 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=8TWFRgkVr/NMjJtDyDutNbGV2KBmgDCbBRkh+Nrq74s=; b=ceDTMGeT7Hq6ITGUu1/PwRtU6IEVKCPmgO09bc+BeqBxH620ZxpVpKtZcY7HJY5uAXzPyC ivlNfAU3m0jxm7jjf2e1s/2sPz8qC/TG6c6mzASIg+ygkGl/rNWBEh6ASN3VBStT6/uFqi kSHHQp6udKUitazOlTv1Ntxkjq3U7hKpmVY+RfHNZxrfNklrQrJydcXknADw3Uc1jDfe8D bkrdOO/IRMOuQwyLnhSQGM1lcJUCgw3KDskd6HNoQGQMMzML47uQUXUyr8DrUkMQBbyFw3 lsHuQxEfBQNUSEllLKRRtN0YfjGWf8h4dIrjU21wua3GC0JQBRjtZYHpbj56mA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1660075286; a=rsa-sha256; cv=none; b=X6xpL/3osTMUzROywBETw9KGyP+wongrUSc1jnFtHWUGEHcwrDIiPB+LNdaYm3EVfIXTJk ouTkSOgP6tU31GFtr+uPaT6u6GFkrAOtQE5N7jkj+MRUfIf1eChDMt5uCMNtcz9s1PIzye HhPsyNRYLFScj6Es3rYQnDgTzuk/cnwBfboe08Q2f0fT47ZbiqguO2j1APAUL8bC0rTUY2 aJ5BtFW+y7bUgHteBdm71A/lmQLgFK9uUUB3lqa/+Q/nhRttWQQYFuZ8UxMbJJVtP52aDq MEpV9kCd0LI83yOdChqOPjX1XMShH6Q7ZzPeA7HMLr6ZcxOLxHE7yAdtM9lwtA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch releng/13.1 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=7dfe949791e764115dda17ec6b21fba2e0a86a2e commit 7dfe949791e764115dda17ec6b21fba2e0a86a2e Author: Konrad Sewiłło-Jopek AuthorDate: 2022-08-08 16:25:48 +0000 Commit: Mark Johnston CommitDate: 2022-08-09 20:01:13 +0000 lib9p: Remove potential buffer overwrite in l9p_puqids() Structure l9p_f_wralk reserves at most L9P_MAX_WELEM entries and that number actually set the maximum we can safely use. Approved by: so Security: FreeBSD-SA-22:12.lib9p PR: 265385 Reviewed by: markj (cherry picked from commit 2dd83b3f0507fc7bc64b908fb88f285a3b9663c8) (cherry picked from commit c536045c51da78a85138e963d3b7e13a547713c9) --- contrib/lib9p/pack.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/contrib/lib9p/pack.c b/contrib/lib9p/pack.c index 88f0ccb4ad73..cf0ae9111b76 100644 --- a/contrib/lib9p/pack.c +++ b/contrib/lib9p/pack.c @@ -343,13 +343,17 @@ l9p_puqids(struct l9p_message *msg, uint16_t *num, struct l9p_qid *qids) ssize_t ret, r; r = l9p_pu16(msg, num); - if (r > 0) { - for (i = 0, lim = *num; i < lim; i++) { - ret = l9p_puqid(msg, &qids[i]); - if (ret < 0) - return (-1); - r += ret; - } + if (r <= 0) + return (r); + + if (*num > L9P_MAX_WELEM) + return (-1); + + for (i = 0, lim = *num; i < lim; i++) { + ret = l9p_puqid(msg, &qids[i]); + if (ret < 0) + return (-1); + r += ret; } return (r); }