From nobody Sat Nov 30 16:51:45 2024 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 4Y0x0K6mPsz5fJBt; Sat, 30 Nov 2024 16:51:45 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Y0x0K54WGz4pQ4; Sat, 30 Nov 2024 16:51:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732985505; 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=GfccOn69c89WXytP4it5vWp3+Dpq0sk3mfpECU6XZrw=; b=XXWpgoF6kuMdrvVLfHBqxkPSThez644/VQPkz2nQSGEpUFhvdvqaBcVNnUnvZqIaSf++rG tvduy/Cg8nXDu/KtVoGZVgsauMSG6kB+mWgvn5ZPqonfHKQ8/Ci5+FXEWpVua+TpCt0mGK RgVqAEzYtBezMIsSzGtMco4j0pcmko7OabfwOo4zHZ57jI7VB5Ljq/52QUifWUSNlXuxVn SBflDC/pxWgdrxIPp2mUdEMEoDwaDP31OcnRwzpDryA3NFVBeh4ZyWkhKl+Cf7BOLLr7CL G1HSsiGeYjroWxY87tbLpbGHjJdvW7STAj7JNxaFg/K0pHttkOah560VxlrtpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732985505; 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=GfccOn69c89WXytP4it5vWp3+Dpq0sk3mfpECU6XZrw=; b=ka7tS6C3s86pFuEFzSmlIzZjSeya24/9IbDcW4OvXihm82wFfrIEbAU7BoCuuMck0yA83w Qb60FDiLo/LpdNIg+XDR7zpHsovLEkPlFcPdXdQw+kDxamq/h4tAWBGUvHsHRZFfTrVFBI oAiN/4GQ2hL01zYjH4jbvqRIBrE32DuShl49ROC4xzuMtdyLAqn5mocSO6BtHhRvY1Ikqv ysDSflkTC5ANnXVAejlqIdYyN2x3WTmTfnQhVAwxjRK8/e6RJsoTwG8JQFI8zQknrCbQWK nQM3eaTA1KAwI1CMF9glRFr59+90A6XdRyBDtX90ou47DOvBoOQIO3hR9LdhoA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1732985505; a=rsa-sha256; cv=none; b=IDze63cQrQOFcSanaKA/qUT0PUCj4pqKI1Kqa9NQ6IKqXv4663pe0XPBPi/crTZbcVPh/P 7qPVFH1pG2cVWBauM4Me7U3x6+Ra1I/NLnqvrvQoHTYGo6nAzzPSM+J3aTAlA7o5QSVunc Uu4jSoOwbpqQs4g8qC1F3QQpabuZVB8E2/Nrkgh5KYHDbj1yZcjb/VHLbfXM7ZnezTICQj CmIV/h5cN5CJsolS6cRjkoG5dHnMLt2JOHoXpwTyTr6JqOcdMc7Cp3SQRptCqOIN8NBZ/a HYE2Z+ezOCsJ3j4FgRdfmqgygGYLIZf72t5ASo9Ytls/ZxAx7PbaJEK7DL0YtA== 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 4Y0x0K4fcPzGW0; Sat, 30 Nov 2024 16:51:45 +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 4AUGpjAW051894; Sat, 30 Nov 2024 16:51:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4AUGpjRI051891; Sat, 30 Nov 2024 16:51:45 GMT (envelope-from git) Date: Sat, 30 Nov 2024 16:51:45 GMT Message-Id: <202411301651.4AUGpjRI051891@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 94bac852544e - stable/13 - fwcontrol: Allocate full fw_asyreq structures passed to the kernel 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: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 94bac852544e52ba3b67ca5f6004ff644c920669 Auto-Submitted: auto-generated The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=94bac852544e52ba3b67ca5f6004ff644c920669 commit 94bac852544e52ba3b67ca5f6004ff644c920669 Author: John Baldwin AuthorDate: 2024-07-19 17:08:14 +0000 Commit: John Baldwin CommitDate: 2024-11-29 19:29:28 +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 (cherry picked from commit 9494dfe1b3faf5c48abaa9be4ec87e4669963942) --- 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;