From nobody Tue Dec 26 02:04:28 2023 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 4SzdPT2tkTz55Kcf; Tue, 26 Dec 2023 02:04:29 +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 4SzdPS5TtGz4Kfb; Tue, 26 Dec 2023 02:04:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703556268; 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=V30Af93dkxM/tk6VkzEm5NRSgnz6V1wGl/d+ZISwXdA=; b=OShv7Y984FW5gZL2/S5ITiy+YMg3gkiNlyw/1RVt3NgyyOGhwBF2Rf7yhhcp7usIvf+V5g L2XaKnaQ+Ip2hBQFvNpV/UUj+uLLf9uYDihJsXnBHHbBoHspA5hyQgLWgCRDPW79Zv0+kD 5fwCu0+erAICXqQ3UiH7AMI2eR8g42SZZ/PSA71Y86dPanv7GMvwbViJM5dBnULIf7HIwk WforG/kzzXof8DTQu1zBqDgvI6fG5DdyKlrer6cACrC8OoEk5cWkYRtC4XU5KIMtI5O1pU uIz6Oa21RP2yHQSleECcT4rlSAZbDf7RbQ5AD5dPOT0nOlHSKBOwQ1sygODdqA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1703556268; a=rsa-sha256; cv=none; b=marArcnbpWNfeVwVmvlTa34xsTj2/yANubOIuai1R3Eu432mJ8kgMvbpFNOC+KCXDBRrKO WXLz7uhP34H+NtP7m6IiU8NPQfdOaWVD2jSrCOGMRXMzH6ysd0WMXOYEp2JjOcEDrEa3L8 QHWZ1FesVK8UWOB4oM0AaNGkg4x97isUYinplRSxv4jsuOPy5XEcxpOgRMlTwDq4XtCdwF JsgeJWFelWmCyj1sn/FS7GXtFQpPD/keAE43yWgMYQ53PJRaLMP0lRwzu+DN+LEETeXFuS qKIvWCBclAU3trdksd1vPpvQf3u4Zt4oCt71buxtOEz81eH00pqaipvYPO2m0w== 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=1703556268; 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=V30Af93dkxM/tk6VkzEm5NRSgnz6V1wGl/d+ZISwXdA=; b=CVrbuRNtoiWgLUrP0IkD8GQS3UKa5CifDYj//21IJKPP2idH9fCHhVnFIES5SW0cAIujsH P05FPVxx4dTm2FahbSIJTPQespdAxi5JeV42+ecqsV9wLEQrUlVQ2fW5rpFTbdqDUbOGCZ A33gLZUjM9Q3tiiZNkjZwyhAoizEYsXe/RMfgMegwr2UHkdx7BrdxWZCNhK/AbYL3I+GqP iTiqkS7sFYgPSvyFYWONAGpHPbFxhCBR8Pej5kWCsX/QDsPWo8hhiUAlGmMB0XEiSZY6zh l+vKPXEe5xEer+yuHkGTTotEarHhGmZILr4HEUrwC5THkH3B7P8Z/SGAWejbWA== 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 4SzdPS4DBxzbhC; Tue, 26 Dec 2023 02:04:28 +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 3BQ24SJY003401; Tue, 26 Dec 2023 02:04:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BQ24SqI003398; Tue, 26 Dec 2023 02:04:28 GMT (envelope-from git) Date: Tue, 26 Dec 2023 02:04:28 GMT Message-Id: <202312260204.3BQ24SqI003398@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: bcf4a7c7ace2 - main - mps: Handle errors from copyout() in ioctl handlers 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/main X-Git-Reftype: branch X-Git-Commit: bcf4a7c7ace21a01d10003de9c7692f0887526c1 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=bcf4a7c7ace21a01d10003de9c7692f0887526c1 commit bcf4a7c7ace21a01d10003de9c7692f0887526c1 Author: Mark Johnston AuthorDate: 2023-12-26 01:42:33 +0000 Commit: Mark Johnston CommitDate: 2023-12-26 02:04:01 +0000 mps: Handle errors from copyout() in ioctl handlers In preparation for adding a __result_use_check annotation to copyin() and related functions, start checking for errors from copyout() in the mps(4) user command handler. This should make it easier to catch bugs. Reviewed by: imp, asomers MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D43176 --- sys/dev/mps/mps_user.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/sys/dev/mps/mps_user.c b/sys/dev/mps/mps_user.c index 3d1b478d81b1..01edcbed2609 100644 --- a/sys/dev/mps/mps_user.c +++ b/sys/dev/mps/mps_user.c @@ -715,9 +715,9 @@ mps_user_command(struct mps_softc *sc, struct mps_usr_command *cmd) } mps_unlock(sc); - copyout(rpl, cmd->rpl, sz); - if (buf != NULL) - copyout(buf, cmd->buf, cmd->len); + err = copyout(rpl, cmd->rpl, sz); + if (buf != NULL && err == 0) + err = copyout(buf, cmd->buf, cmd->len); mps_dprint(sc, MPS_USER, "%s: reply size %d\n", __func__, sz); RetFreeUnlocked: @@ -847,7 +847,7 @@ mps_user_pass_thru(struct mps_softc *sc, mps_pass_thru_t *data) /* * Copy the reply data and sense data to user space. */ - if ((cm != NULL) && (cm->cm_reply != NULL)) { + if (err == 0 && cm != NULL && cm->cm_reply != NULL) { rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply; sz = rpl->MsgLength * 4; @@ -857,8 +857,11 @@ mps_user_pass_thru(struct mps_softc *sc, mps_pass_thru_t *data) __func__, data->ReplySize, sz); } mps_unlock(sc); - copyout(cm->cm_reply, PTRIN(data->PtrReply), + err = copyout(cm->cm_reply, PTRIN(data->PtrReply), MIN(sz, data->ReplySize)); + if (err != 0) + mps_dprint(sc, MPS_FAULT, + "%s: copyout failed\n", __func__); mps_lock(sc); } mpssas_free_tm(sc, cm); @@ -1001,7 +1004,7 @@ mps_user_pass_thru(struct mps_softc *sc, mps_pass_thru_t *data) /* * Copy the reply data and sense data to user space. */ - if (cm->cm_reply != NULL) { + if (err == 0 && cm->cm_reply != NULL) { rpl = (MPI2_DEFAULT_REPLY *)cm->cm_reply; sz = rpl->MsgLength * 4; @@ -1011,12 +1014,16 @@ mps_user_pass_thru(struct mps_softc *sc, mps_pass_thru_t *data) data->ReplySize, sz); } mps_unlock(sc); - copyout(cm->cm_reply, PTRIN(data->PtrReply), + err = copyout(cm->cm_reply, PTRIN(data->PtrReply), MIN(sz, data->ReplySize)); mps_lock(sc); + if (err != 0) + mps_dprint(sc, MPS_FAULT, "%s: failed to copy " + "IOCTL data to user space\n", __func__); - if ((function == MPI2_FUNCTION_SCSI_IO_REQUEST) || - (function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) { + if (err == 0 && + (function == MPI2_FUNCTION_SCSI_IO_REQUEST || + function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) { if (((MPI2_SCSI_IO_REPLY *)rpl)->SCSIState & MPI2_SCSI_STATE_AUTOSENSE_VALID) { sense_len = @@ -1024,9 +1031,13 @@ mps_user_pass_thru(struct mps_softc *sc, mps_pass_thru_t *data) SenseCount)), sizeof(struct scsi_sense_data)); mps_unlock(sc); - copyout(cm->cm_sense, (PTRIN(data->PtrReply + + err = copyout(cm->cm_sense, (PTRIN(data->PtrReply + sizeof(MPI2_SCSI_IO_REPLY))), sense_len); mps_lock(sc); + if (err != 0) + mps_dprint(sc, MPS_FAULT, + "%s: failed to copy IOCTL data to " + "user space\n", __func__); } } }