From nobody Tue Jan 02 01:13:09 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 4T3vx20Zg2z562tR; Tue, 2 Jan 2024 01:13:10 +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 4T3vx16JBDz3b1n; Tue, 2 Jan 2024 01:13:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704157989; 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=YUY5EZaTFU9/+OGDYxNLL23Qb9b20LlAnP2WzqH5ywA=; b=tlfhW1sLrgdYuRa491wsfbVop3P4gSaMxsjokI4oAeI2rClxxNGrn0LZ+7F0eRAA/rnYZ7 RLa73FLKppvA21Ypo9gbuSyeMqTw+WFaoStUGKyyLqWPQF+lH9jBEprkdR3l1e2KDfEPbT D57wa6uvH4h3okbKCnRdH6+ipCFV64RvYHUBZOOhIpfCOvXrGjQZwbXx/Yp11uitLLfudF P9X/y5fftJ/xIWup+SWuu422udvuNxy8hhNFMukOX0qw41VwjN5PAvXiZorksxEGp5ILCD hwJ4VcjqKAX8uMlfxmYJ1BL2ucTcolw1cdya+s4US+Vw1Lmy3oCqGEcL1bio8Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1704157989; a=rsa-sha256; cv=none; b=M/HvRuMfllC1puO4yRbujRtScRQFd8uy4A2Letj0tsW3mYhYuO38DpL/JY2HIybUWf4E6N rzFvVeS6BdeElAt3dXJhO6MtD61ds6Ji1gqSge/hu/nqeeSQIR+A+8d9w8bu/V/tdnZruY 5SIcaliFwFjp3zq8HP+wCbHzMpECKoNGGeFN1GmVzsJe4HmQ9n8nPKp/IUoN1JUfVfF29x oUBd9A5s1DylmBrVbWPa4OXx1VBz2JJnHn/MTyadgIcs8k1rUj9jYGZN+4Qbn+audgjgtc 4WBUY03/4YC2PER7e1MwA3ohQKE1O2yEDsCUnsV0DFdG5YwDGL3O/gQFUqiI/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=1704157989; 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=YUY5EZaTFU9/+OGDYxNLL23Qb9b20LlAnP2WzqH5ywA=; b=GZVMeam3RiCR3ZL3dHm+eUCNp9b2AnrAgimMtLH4ri51FUNwJe+kTmwc9mQnUfe99qMx/Z qMMf44+9reGhuRPR2IBNIqXwnS3PMtEPK1WgAgkPvKbCfCB84yZIQBAPkGNG8tu1l+z+VI ihwP2/uUvmm6c5j/kTPiMJd7GIS61JgQjEo/GbR9D25hdMCjHWuCn79S49y1FXArjxx8c1 Z5AJcu1d9NDDIvBsbmTX3tgYYG8DX/qaLH3oAQmrJNqxhFE3wn3B2d5Ow3aFOdDLGURTOQ 44WlhLOC8sOBYG4msM7qghpVb1x8VSM0YPBuiGxJIdY1sA+OvXmNtzTzELClug== 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 4T3vx15NtMzgRF; Tue, 2 Jan 2024 01:13:09 +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 4021D9xd055236; Tue, 2 Jan 2024 01:13:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 4021D9ul055233; Tue, 2 Jan 2024 01:13:09 GMT (envelope-from git) Date: Tue, 2 Jan 2024 01:13:09 GMT Message-Id: <202401020113.4021D9ul055233@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: f01b5e418745 - stable/13 - 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/stable/13 X-Git-Reftype: branch X-Git-Commit: f01b5e41874584ffe3547e79bd80c2b20e557176 Auto-Submitted: auto-generated The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=f01b5e41874584ffe3547e79bd80c2b20e557176 commit f01b5e41874584ffe3547e79bd80c2b20e557176 Author: Mark Johnston AuthorDate: 2023-12-26 01:42:33 +0000 Commit: Mark Johnston CommitDate: 2024-01-02 01:12:45 +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 (cherry picked from commit bcf4a7c7ace21a01d10003de9c7692f0887526c1) --- 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 49dc0f05619c..48c2809eadff 100644 --- a/sys/dev/mps/mps_user.c +++ b/sys/dev/mps/mps_user.c @@ -727,9 +727,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: @@ -859,7 +859,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; @@ -869,8 +869,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); @@ -1013,7 +1016,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; @@ -1023,12 +1026,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 = @@ -1036,9 +1043,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__); } } }