From nobody Tue Jan 02 01:12:58 2024 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 4T3vwp4Yjsz56354; Tue, 2 Jan 2024 01:12:58 +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 4T3vwp3BCfz3ZZ6; Tue, 2 Jan 2024 01:12:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704157978; 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=AAlrxEcyBR7S0WdSiTbmNo7QBY+vQEzTk5PD0PVZSwI=; b=St6FPq3XSYntdF+FiZOovB7hGg1c/GgphoPt60xDNpXJXo7QVVY3q+osyp7t0qhzED9iqv uMUY4EV1QvK4V21/QawS1t+2CdURTpUNWxvEChWwH7tKMlFJ7DLiACNCtuo6lo3QevbRnp iEdJT3pO996latjs6ZZ5/gL31wYDKMFcUeFcsmhl7LxeQOAt/oTY+wBOjkogGMg1qzFiNs Um3xjVMJHkD0THZjcnYw2qnh0w1DVK7XGv05cukSwCrF05F461vVPPcGPi5VN3m8LHtut8 zHCAmJ1lTg8KciVfPIgOaVvaHNMmUC5Rdjw51kDyP+g9FZqKMyk0u5y6YAu1GQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1704157978; a=rsa-sha256; cv=none; b=PvKRAr1ymPW5PI8wZfcILSLUaetuCzq9LnwTCWTpbavLc72n4+Mk8dFXD6LbUOP+js3LL4 DWP82yVQYYPf0/DRLKp7n8RYPnNMzPIUP3IOilq2ETDB5kTZZ/rHmGaoc6bdx6q8j08UUV kt872L3EqE3ryHHvnI64cKeFIZW1JWiTEf+EEenIZsLEYMC5kjh/6qK6Z5oN1eMhEQ7mOr vJXBXfVNo0A46e6y88we6GgaiVcabeny4QfMH56GukMZdtNgBDZlemUzu3ljG/ckj+O/Y3 07Qv9ItwsTpxaLK+gSfQO5MYgs4T1U38QxfVWaJJ/s1xxMYqiUAYDUparAfn/w== 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=1704157978; 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=AAlrxEcyBR7S0WdSiTbmNo7QBY+vQEzTk5PD0PVZSwI=; b=s0O/25UeijbYbjs5mBOkwsVINOGW9wuQsJicnzz4jeviJqJHIASyF3RdFmN6Qrlqe0qRfi M14aOVRRNIbH8BaI8in7k2ULrgol1Si5ab1iqAtzV2CugZyVowC2N4loKMiNKiwFd/BQN2 PPmGVKHhdiJ2cEjXqzT5jjnrBkseSsj7FOtqgS/w7iPK2m16X06q4lg981mBn8zUTRlyT2 RQEdVWC9APKP+ncSNrmD8zlSoGbCk6Yr2S/oexiAaXG3lqVcRqnid6jfoSME2/J8MHXuGU 3cuyDf3nPs26C3Af4imKoIP/EiPRyQIWkmgDjWS08bvJRvdIYl7LkBrgLN00QQ== 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 4T3vwp2CKdzgRD; Tue, 2 Jan 2024 01:12:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 4021Cw9B054734; Tue, 2 Jan 2024 01:12:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 4021CwAB054731; Tue, 2 Jan 2024 01:12:58 GMT (envelope-from git) Date: Tue, 2 Jan 2024 01:12:58 GMT Message-Id: <202401020112.4021CwAB054731@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: f5a139a03767 - stable/13 - ocs: Check for copyin errors in the ioctl handler List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/stable/13 X-Git-Reftype: branch X-Git-Commit: f5a139a0376740aa3a80e2c626846020e7643c14 Auto-Submitted: auto-generated The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=f5a139a0376740aa3a80e2c626846020e7643c14 commit f5a139a0376740aa3a80e2c626846020e7643c14 Author: Mark Johnston AuthorDate: 2023-12-26 01:38:57 +0000 Commit: Mark Johnston CommitDate: 2024-01-02 01:12:44 +0000 ocs: Check for copyin errors in the ioctl handler If copyin() fails, the driver will blindly proceed with whatever had been in the uninitialized DMA buffer. This is not what we want. Check for copyin failures. This is in preparation for annotating copyin() and related functions with __result_use_check. Reviewed by: ram MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D43097 (cherry picked from commit a01ff11cb73d7a1988f6241f63d141371ff23717) --- sys/dev/ocs_fc/ocs_ioctl.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/sys/dev/ocs_fc/ocs_ioctl.c b/sys/dev/ocs_fc/ocs_ioctl.c index 75afdb218333..5b794cccbf7f 100644 --- a/sys/dev/ocs_fc/ocs_ioctl.c +++ b/sys/dev/ocs_fc/ocs_ioctl.c @@ -86,6 +86,7 @@ static int ocs_process_sli_config (ocs_t *ocs, ocs_ioctl_elxu_mbox_t *mcmd, ocs_dma_t *dma) { sli4_cmd_sli_config_t *sli_config = (sli4_cmd_sli_config_t *)mcmd->payload; + int error; if (sli_config->emb) { sli4_req_hdr_t *req = (sli4_req_hdr_t *)sli_config->payload.embed; @@ -127,7 +128,13 @@ ocs_process_sli_config (ocs_t *ocs, ocs_ioctl_elxu_mbox_t *mcmd, ocs_dma_t *dma) wrobj->host_buffer_descriptor[0].u.data.buffer_address_high = ocs_addr32_hi(dma->phys); /* copy the data into the DMA buffer */ - copyin((void *)(uintptr_t)mcmd->in_addr, dma->virt, mcmd->in_bytes); + error = copyin((void *)(uintptr_t)mcmd->in_addr, dma->virt, mcmd->in_bytes); + if (error != 0) { + device_printf(ocs->dev, "%s: COMMON_WRITE_OBJECT - copyin failed: %d\n", + __func__, error); + ocs_dma_free(ocs, dma); + return error; + } } break; case SLI4_OPC_COMMON_DELETE_OBJECT: @@ -170,7 +177,13 @@ ocs_process_sli_config (ocs_t *ocs, ocs_ioctl_elxu_mbox_t *mcmd, ocs_dma_t *dma) return ENXIO; } - copyin((void *)(uintptr_t)mcmd->in_addr, dma->virt, mcmd->in_bytes); + error = copyin((void *)(uintptr_t)mcmd->in_addr, dma->virt, mcmd->in_bytes); + if (error != 0) { + device_printf(ocs->dev, "%s: non-embedded - copyin failed: %d\n", + __func__, error); + ocs_dma_free(ocs, dma); + return error; + } sli_config->payload.mem.address_low = ocs_addr32_lo(dma->phys); sli_config->payload.mem.address_high = ocs_addr32_hi(dma->phys); @@ -184,6 +197,9 @@ static int ocs_process_mbx_ioctl(ocs_t *ocs, ocs_ioctl_elxu_mbox_t *mcmd) { ocs_dma_t dma = { 0 }; + int error; + + error = 0; if ((ELXU_BSD_MAGIC != mcmd->magic) || (sizeof(ocs_ioctl_elxu_mbox_t) != mcmd->size)) { @@ -238,13 +254,13 @@ ocs_process_mbx_ioctl(ocs_t *ocs, ocs_ioctl_elxu_mbox_t *mcmd) if( SLI4_MBOX_COMMAND_SLI_CONFIG == ((sli4_mbox_command_header_t *)mcmd->payload)->command && mcmd->out_bytes && dma.virt) { - copyout(dma.virt, (void *)(uintptr_t)mcmd->out_addr, mcmd->out_bytes); + error = copyout(dma.virt, (void *)(uintptr_t)mcmd->out_addr, mcmd->out_bytes); } no_support: ocs_dma_free(ocs, &dma); - return 0; + return error; } /**