From nobody Fri Jul 19 17:11:31 2024 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 4WQbmz5hNhz5S0FK; Fri, 19 Jul 2024 17:11:31 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WQbmz2g8hz41DT; Fri, 19 Jul 2024 17:11:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1721409091; 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=wrtskWlyJqKDND24k80gcLmRnKNAcjDVbtU3J6y86B4=; b=UAEKoFjfZtAUrQCLfESMIxY014tbKZD+DDjuepCTR1exAsf46AwdldF8eCTamgCIWOmQ0o h8e2qSn3fTKbYnCY7fycnMjS754Phah+G8oMrA5av97UpfMzBKjdBTi3rm2qjfBjkaWU1W yAkBVEUObjTCT2lTsqnewxn7gM7hKt0b/BCNkLUA8ifqujxbXd8epHWMweSVmsAnYQ9fJf TH9Av1eKGJDYS0B8ELiRKY6pQLEkYwlsZ6RrDuuoeEBj84+qR1ibMQVL0cjbh0hrUV/hba sa+3HiLkKXPKDaf+dQkhxwiWk77xJB5ySNoUQcC85RVKDByPM41hl8JhZqABSA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1721409091; a=rsa-sha256; cv=none; b=bxvYDUbPC/DDf8zi3T76c/oj3vaoNE1MgnWo9THJy39daw5PW/3ChAjQS8zpQIljtBjBV0 ah3rG/KsBml2DGHnyWxIckUDyYyWiF2BEabTLbzzynHnAXp1MBSatbYrsgJhVtmWpd5J7O yAsDVX0Jq1OWqvuSeiDZpmPLCM0tAFUWN98DRx50G9Y/j18dJ4W4qjX8G+BD4qgiW/dUCR SPgNWeW8FCWbCSkIt6GbyZJfPAKgVrnFWkUZw1f2oeQcl/7NlJHcldUIuhU6aAzFSZUiS1 +AW2dkz0d7fIDU22x226yr/eE7y1AXOoPOPkEJEDWwelpkOCJAuqDNaLqFSMAw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1721409091; 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=wrtskWlyJqKDND24k80gcLmRnKNAcjDVbtU3J6y86B4=; b=CD6ei0eABGJgcQnP1Lei4uaJWRZlFZVSeMAKdfw6sM6OwNlWnMuqb7kJbRO4YZnbAFaNT2 ocxIa/qRngwKTmF3XBKLO874dsxjH+9+mJbuoralSn4xdAp3fw6OnVCynrbAYbSnNaYbO2 ws656FhoxbkNEpjhEaXot6oDWL8TNBmTPSwXfr280ke9Ww2PZPw9aXUXNiRLso4/p3a/jn IU7OTN8pWPKfiNz97L1b3uVP1qAe/pjDapiD6COssmPoB9LubCEmfcRVIaBBc1bH/VZGoZ B1bXaXmzONwbqchMWQA7aD4QvRM+ah55zf+zOnLGnbfXFyEVs+KzJzBdJeSpyA== 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 4WQbmz1yZ8zgqt; Fri, 19 Jul 2024 17:11:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 46JHBVTe044159; Fri, 19 Jul 2024 17:11:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 46JHBVdq044156; Fri, 19 Jul 2024 17:11:31 GMT (envelope-from git) Date: Fri, 19 Jul 2024 17:11:31 GMT Message-Id: <202407191711.46JHBVdq044156@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 9494dfe1b3fa - main - fwcontrol: Allocate full fw_asyreq structures passed to the kernel 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: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 9494dfe1b3faf5c48abaa9be4ec87e4669963942 Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=9494dfe1b3faf5c48abaa9be4ec87e4669963942 commit 9494dfe1b3faf5c48abaa9be4ec87e4669963942 Author: John Baldwin AuthorDate: 2024-07-19 17:08:14 +0000 Commit: John Baldwin CommitDate: 2024-07-19 17:09:32 +0000 fwcontrol: Allocate full fw_asyreq structures passed to the kernel The FW_ASYREQ ioctl accepts a struct fw_asyreq object as its argument, meaning that the kernel always copies in the full structure in sys_ioctl before passing the request down to the driver. However, fwcontrol was allocating smaller objects that contained only the request header and a variable-sized payload. This means that the kernel copy in sys_ioctl was reading off the end of this buffer. On current architectures this happened to be ok, but it is UB. Instead, allocate a full structure. Reported by: GCC 14 -Walloc-size Reviewed by: rlibby, brooks Differential Revision: https://reviews.freebsd.org/D46014 --- usr.sbin/fwcontrol/fwcontrol.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/usr.sbin/fwcontrol/fwcontrol.c b/usr.sbin/fwcontrol/fwcontrol.c index 94478259606d..ce908341a42a 100644 --- a/usr.sbin/fwcontrol/fwcontrol.c +++ b/usr.sbin/fwcontrol/fwcontrol.c @@ -207,7 +207,7 @@ read_write_quad(int fd, struct fw_eui64 eui, u_int32_t addr_lo, int readmode, u_ struct fw_asyreq *asyreq; u_int32_t *qld, res; - asyreq = (struct fw_asyreq *)malloc(sizeof(struct fw_asyreq_t) + 16); + asyreq = malloc(sizeof(*asyreq)); if (asyreq == NULL) err(EX_SOFTWARE, "%s:asyreq malloc", __func__); asyreq->req.len = 16; @@ -262,7 +262,7 @@ send_phy_config(int fd, int root_node, int gap_count) { struct fw_asyreq *asyreq; - asyreq = (struct fw_asyreq *)malloc(sizeof(struct fw_asyreq_t) + 12); + asyreq = malloc(sizeof(*asyreq)); if (asyreq == NULL) err(EX_SOFTWARE, "%s:asyreq malloc", __func__); asyreq->req.len = 12; @@ -289,7 +289,7 @@ link_on(int fd, int node) { struct fw_asyreq *asyreq; - asyreq = (struct fw_asyreq *)malloc(sizeof(struct fw_asyreq_t) + 12); + asyreq = malloc(sizeof(*asyreq)); if (asyreq == NULL) err(EX_SOFTWARE, "%s:asyreq malloc", __func__); asyreq->req.len = 12; @@ -308,7 +308,7 @@ reset_start(int fd, int node) { struct fw_asyreq *asyreq; - asyreq = (struct fw_asyreq *)malloc(sizeof(struct fw_asyreq_t) + 16); + asyreq = malloc(sizeof(*asyreq)); if (asyreq == NULL) err(EX_SOFTWARE, "%s:asyreq malloc", __func__); asyreq->req.len = 16;