From nobody Mon Aug 08 16:53:45 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 4M1j2f1gHPz4YWDv; Mon, 8 Aug 2022 16:53: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 4M1j2f0p3Tz3MTw; Mon, 8 Aug 2022 16:53:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1659977626; 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=LtsuSurQJ5RMqiJyBQ59oo6XWDiDB5Rni2Scyjywq0c=; b=NleVGwTUoqDURit5ZDAjcMZS+TyuwN+bTTAui1zmZt0snRON2kozmxY8Pbj2YTMXyMiktE x/tL3hjwYDn1v6TAVHtrEUh0b+PJKxPcQ/xjDmQ8Z+TP8vIDIn8n0mUF1ghMSbdIBm9YqY laLF362AF6NhU1Vb5y/hm7x4oiPXqj14pYFa3AcwBoqMSmHetbSnfFTzWfFXjdFF1IDbI2 RIacwxb0nYX56OsMX3fvetwQwbBJoKarCmke+/OpCfF7CE+YkWbzpSWj5somryLVQLmN8H t1qMjLN5U7pcNO8Vj9UufVx5FiSeEh1q0bDD2cuZm080+SdMuKY1wa4NKMHL1Q== 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 4M1j2d70Tpz1059; Mon, 8 Aug 2022 16:53: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 278GrjLD019082; Mon, 8 Aug 2022 16:53:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 278GrjFn019081; Mon, 8 Aug 2022 16:53:45 GMT (envelope-from git) Date: Mon, 8 Aug 2022 16:53:45 GMT Message-Id: <202208081653.278GrjFn019081@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: 2dd83b3f0507 - main - lib9p: Remove potential buffer overwrite in l9p_puqids() 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 2dd83b3f0507fc7bc64b908fb88f285a3b9663c8 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1659977626; 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=LtsuSurQJ5RMqiJyBQ59oo6XWDiDB5Rni2Scyjywq0c=; b=rSSL4bboD+4fI6KGsx6+Pmdd0OB1svK2ieUue1kob/SyjVWx5pulx+rdYbN4G5cvn/lpzW Bhd23psZOyYUWWjw33d8lobygYwjY7Q0sT9wje0e8LtimC38o9Nbj0hDtBtQJRmj8JnabF 8twymmhaiuFjY7ygTxfxcAZRFsJXwiSjkNvkcRVEWM6x7iBabroCy33qrlq7wpKRHj7W+S cTjnET2eFp7DJqQC3P04W3baeT27QDNfEU5VSszcWU1rJ+RVy3hHexGJ8kPwQo0ccYp+wH mDXvvZPnHIevLY2NlVJx9jc2vd5EZfJ2wpwB1ApNnGyPKlg/3r6AC+HAXW8BIQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1659977626; a=rsa-sha256; cv=none; b=isF88pMjcxbwA3TYIEyVBKN8YAXe0hBN3eklKpdaDZo0HC1cHs2fM25SBjiYiyHfaO1ftf YEU+yKbDwYUOJJlGsnnPQYYuhzgJr24ZH5N8qjyKeStZRUmI4YtRGAYV7/GoNmjIz/m18H phWyg5QHu1KEp6Jsx8l7vNxtZvyfe5Yw5gq4qZj0ClEDtOTdib8xFpJ+KMWeyjAQAVHozl potkavsvyoa0YKuXwtG/L230I8pIJi9rG7ezYSIim9NkjKxCQy3SXNZ/xDnwyfjcRl1jw+ qP+gxTn96YujN1gYjRVt9X51UC6+ZECBqig0UAzrNEkWExARPOqbErc0tUP2Yg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=2dd83b3f0507fc7bc64b908fb88f285a3b9663c8 commit 2dd83b3f0507fc7bc64b908fb88f285a3b9663c8 Author: Konrad Sewiłło-Jopek AuthorDate: 2022-08-08 16:25:48 +0000 Commit: Mark Johnston CommitDate: 2022-08-08 16:50:43 +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. PR: 265385 Reviewed by: markj MFC after: 1 day Differential Revision: https://reviews.freebsd.org/D35907 --- 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); }