From nobody Tue Nov 03 09:00:16 2026 X-Original-To: dev-commits-src-all@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 4jJjFr35j9z6yPGq for ; Tue, 03 Nov 2026 09:00:16 +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) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jJjFr26Rsz4HxT for ; Tue, 03 Nov 2026 09:00:16 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793696416; 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=HNOLdGPlBkByde/0MJeP51dV3t/CJHBymXF1l8WOleo=; b=LM4Rfy5fYTCMITGmh9DH5sHA9VjpSTmGdhKJj9XceyxnPMJ2RN5UwlML27ctsZB6f99sRs a0xA9fkBerrYRI4J5qbvFErQkfvAoI0BAjMOcXGWkAhDR7Q8mHL192t35LbpT5MRVP0gLw 3vEF23TFJ1n7oFjJXnECpKjfqgG8iIzTi30q/Hsg/GwF5AUWj0Porw4G2BxrvwnKSMCMR+ gJOUsbG2MJrGJP465G2sCrVDaiJThC/Da7j8Dxd/M08v46rmGlYSD604dJElEPrbW0P+Y2 TVhbCImnVWr7E6sAfFwl485IIeVlcR93mRRzISsj2Npd5/gSIU1xyrBaiA4mJQ== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1793696416; b=yyvaZSpHpM5LO8LqGPjrPYM9uKlr86hr/bcRb65VYtQLeh6DM2denkRDGEb1De1+ysBNT4 w/l9wqroy6/siE8Lvu1IOIIcYEHa49VPd936uwf8TjiZTco+IVdgFeMp2GwbnWVWQfJJNo 1LdWd3qkh32NdXUYj/EsViL1G9tKOoKcUqtYxLU4/LRXpp/NZwlkAhAYbXpD6kLfZuKRJC xQq1axs33vOX/YYvbCtUaTjcUBXB2Xw5/VQMFgF8bxPJ5D46z+T/Go+1CnxBQ/leGjfDIp HfsVjP3Otqpq6tS3ic1YfxuPxXyXQL6wn7/3V+ZR7i9qvUyLEIYRGlN8Xwu8zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793696416; 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=HNOLdGPlBkByde/0MJeP51dV3t/CJHBymXF1l8WOleo=; b=MKzcT2k/QvtrMT3836GA63hVIks25X37SinmLXz2SmS2drJBXH3Bcj30DNanNp9/YLUjno Pky4H99iYD3JYmG2ACeK/UprGnXQEF+1SXsmIaCNQrDyExP/1Gaed1/1CWxtIogOiqMMSf OZvPssT9dEQaJoc0w94eq6fav+hSLM4YnUWsJA/pq7f0ALTEEXSunRCKcKNJKBYtJ83ubW P08U/NbuFt4CdP4MsFRetyV07xv5FP2Q8kKaz20ST5egO3rDcF/u+5xEAsrP2m8xnbSsRe cEMJK6U8eVZh5vKmmFhZHyulOWHZBtbi1oC8k2e10ASF6Z4DWorxjSXoQMs8bw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jJjFr1mxQz1P8v for ; Tue, 03 Nov 2026 09:00:16 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 43cd4 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 03 Nov 2026 09:00:16 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ram Kishore Vegesna Subject: git: 67ec6588a58e - stable/14 - ocs_fc: Fix config space bounds, double PRLI response and a stack overflow List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: ram X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 67ec6588a58e5bf522132fc6a6b4c3196b506f15 Auto-Submitted: auto-generated Date: Tue, 03 Nov 2026 09:00:16 +0000 Message-Id: <6ae9a2a0.43cd4.3ffd2811@gitrepo.freebsd.org> The branch stable/14 has been updated by ram: URL: https://cgit.FreeBSD.org/src/commit/?id=67ec6588a58e5bf522132fc6a6b4c3196b506f15 commit 67ec6588a58e5bf522132fc6a6b4c3196b506f15 Author: Ram Kishore Vegesna AuthorDate: 2026-10-19 17:29:31 +0000 Commit: Ram Kishore Vegesna CommitDate: 2026-11-03 08:58:54 +0000 ocs_fc: Fix config space bounds, double PRLI response and a stack overflow Fix three unrelated problems found by security review of the driver. ECD helper ioctl: - OCS_ECD_HELPER_CFG_READ* and OCS_ECD_HELPER_CFG_WRITE* passed a user supplied offset straight to pci_read_config() and pci_write_config(). Reject accesses that extend past PCIE_REGMAX, so that a wide access starting in range cannot run past the end of config space. - Use the real access width (1, 2 or 4 bytes) of the command for both the BAR and the config space checks, rather than assuming 4 bytes, so that narrow accesses at the very end of the BAR or config space are not rejected while wider ones remain bounded. PRLI: - When a PRLI carries an FC-4 type other than the one the driver supports, ocs_d_send_prli_rsp() sent an LS_RJT and started node shutdown, but then fell through and sent a second response on the same IO (another LS_RJT, or a PRLI LS_ACC when the initiator is accepted), followed by a conflicting transition to __ocs_d_device_ready. The two responses posted two WQEs for one IO and caused a double ocs_ref_put(), a use after free of the ELS IO. Return after dispatching the LS_RJT so that exactly one response is sent. - __ocs_d_port_logged_in calls ocs_d_send_prli_rsp() without checking the FC-4 type, so any port that has completed a PLOGI can trigger this with a single PRLI, whether or not target mode is enabled. Management: - The active profile id is a uint32_t that is formatted as "0x%02x" with sprintf() into a buffer of MAX_PROFILE_LENGTH (5) bytes, which overflows for any id above 0xff. Size the buffer for the longest possible string ("0x" plus 8 hex digits and the terminating NUL) and use ocs_snprintf(). - Use ocs_snprintf() for nv_wwpn as well, as nv_wwnn already does. MFC after: 1 week Sponsored by: Broadcom Reviewed by: ken (cherry picked from commit 039a8e11f887e359af1346b04e05180b9a49920c) --- sys/dev/ocs_fc/ocs_device.c | 2 ++ sys/dev/ocs_fc/ocs_ioctl.c | 42 +++++++++++++++++++++++++++++++++++++++++- sys/dev/ocs_fc/ocs_mgmt.c | 8 +++++--- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/sys/dev/ocs_fc/ocs_device.c b/sys/dev/ocs_fc/ocs_device.c index d9c283541d3c..4d85970df675 100644 --- a/sys/dev/ocs_fc/ocs_device.c +++ b/sys/dev/ocs_fc/ocs_device.c @@ -74,6 +74,8 @@ ocs_d_send_prli_rsp(ocs_io_t *io, uint16_t ox_id) FC_EXPL_REQUEST_NOT_SUPPORTED, 0, NULL, NULL); node->shutdown_reason = OCS_NODE_SHUTDOWN_DEFAULT; ocs_node_transition(node, __ocs_d_initiate_shutdown, NULL); + /* Send only one response per PRLI; the LS_RJT owns the IO */ + return; } /* If the back-end doesn't want to talk to this initiator, we send an LS_RJT */ diff --git a/sys/dev/ocs_fc/ocs_ioctl.c b/sys/dev/ocs_fc/ocs_ioctl.c index a978f1084452..18dd3fbbac4c 100644 --- a/sys/dev/ocs_fc/ocs_ioctl.c +++ b/sys/dev/ocs_fc/ocs_ioctl.c @@ -41,6 +41,8 @@ #include #include +#include + static d_open_t ocs_open; static d_close_t ocs_close; static d_ioctl_t ocs_ioctl; @@ -299,6 +301,28 @@ no_support: return error; } +/** + * @brief return the access width in bytes of an ECD helper BAR/config command + */ +static uint32_t +ocs_ecd_helper_width(ocs_ecd_helper_cmd_t cmd) +{ + switch (cmd) { + case OCS_ECD_HELPER_BAR_READ8: + case OCS_ECD_HELPER_BAR_WRITE8: + case OCS_ECD_HELPER_CFG_READ8: + case OCS_ECD_HELPER_CFG_WRITE8: + return (sizeof(uint8_t)); + case OCS_ECD_HELPER_BAR_READ16: + case OCS_ECD_HELPER_BAR_WRITE16: + case OCS_ECD_HELPER_CFG_READ16: + case OCS_ECD_HELPER_CFG_WRITE16: + return (sizeof(uint16_t)); + default: + return (sizeof(uint32_t)); + } +} + /** * @brief perform requested Elx CoreDump helper function * @@ -318,6 +342,7 @@ ocs_process_ecd_helper (ocs_t *ocs, ocs_ioctl_ecd_helper_t *req) uint8_t v8; uint16_t v16; uint32_t v32; + uint32_t width; /* Check the BAR read/write commands for valid bar */ switch(req->cmd) { @@ -327,6 +352,7 @@ ocs_process_ecd_helper (ocs_t *ocs, ocs_ioctl_ecd_helper_t *req) case OCS_ECD_HELPER_BAR_WRITE8: case OCS_ECD_HELPER_BAR_WRITE16: case OCS_ECD_HELPER_BAR_WRITE32: + width = ocs_ecd_helper_width(req->cmd); if (req->bar >= PCI_MAX_BAR) { device_printf(ocs->dev, "Error: bar %d out of range\n", req->bar); return -EFAULT; @@ -335,13 +361,27 @@ ocs_process_ecd_helper (ocs_t *ocs, ocs_ioctl_ecd_helper_t *req) device_printf(ocs->dev, "Error: bar %d not defined\n", req->bar); return -EFAULT; } - if ((uint64_t)req->offset + sizeof(uint32_t) > + if ((uint64_t)req->offset + width > rman_get_size(ocs->reg[req->bar].res)) { device_printf(ocs->dev, "Error: bar %d offset 0x%x out of range\n", req->bar, req->offset); return -EFAULT; } break; + case OCS_ECD_HELPER_CFG_READ8: + case OCS_ECD_HELPER_CFG_READ16: + case OCS_ECD_HELPER_CFG_READ32: + case OCS_ECD_HELPER_CFG_WRITE8: + case OCS_ECD_HELPER_CFG_WRITE16: + case OCS_ECD_HELPER_CFG_WRITE32: + width = ocs_ecd_helper_width(req->cmd); + if ((uint64_t)req->offset + width - 1 > PCIE_REGMAX) { + device_printf(ocs->dev, + "Error: config offset 0x%x out of range\n", + req->offset); + return -EFAULT; + } + break; default: break; } diff --git a/sys/dev/ocs_fc/ocs_mgmt.c b/sys/dev/ocs_fc/ocs_mgmt.c index 5b7f6557c017..483e80ce649a 100644 --- a/sys/dev/ocs_fc/ocs_mgmt.c +++ b/sys/dev/ocs_fc/ocs_mgmt.c @@ -2076,7 +2076,8 @@ ocs_mgmt_get_active_profile_cb(int32_t status, uint32_t active_profile, void *ul ocs_sem_v(&(result->semaphore)); } -#define MAX_PROFILE_LENGTH 5 +/* "0x", up to 8 hex digits and a NUL for a uint32_t id */ +#define MAX_PROFILE_LENGTH 11 /** * @brief Get active profile @@ -2107,7 +2108,7 @@ get_active_profile(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf) } if (result.status == 0) { /* Success. */ - sprintf(result_string, "0x%02x", result.active_profile_id); + ocs_snprintf(result_string, sizeof(result_string), "0x%02x", result.active_profile_id); ocs_mgmt_emit_string(textbuf, MGMT_MODE_RW, "active_profile", result_string); } else { ocs_log_test(ocs, "getting active profile status 0x%x\n", result.status); @@ -2225,7 +2226,8 @@ get_nv_wwpn(ocs_t *ocs, char *name, ocs_textbuf_t *textbuf) } if (result.status == 0) { /* Success. Copy wwpn from result struct to result string */ - sprintf(result_string, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", + ocs_snprintf(result_string, sizeof(result_string), + "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", result.wwpn[0], result.wwpn[1], result.wwpn[2], result.wwpn[3], result.wwpn[4], result.wwpn[5], result.wwpn[6], result.wwpn[7]);