From nobody Tue Jan 02 00:37:13 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 4T3v7Y5f8rz55yTS; Tue, 2 Jan 2024 00:37:13 +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 4T3v7Y4Ch8z3HXf; Tue, 2 Jan 2024 00:37:13 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704155833; 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=hixTeZQHZ/99fhZ53AXUBgUaBsDq2TdF8baanLDspfo=; b=hUv6vo+Aa+Laxxu94ixnQ2tRwzcWVOd0gBEYlBO6E75rg0hMb+JEuFsWVd1bs148buzxQy PTvPexQAPZnVCphIW+Fwd0Y8PmcUURGZe4KnAjT0FgU4XMl8ZFrwpNkL1dDf8Db0swQQev khvULhPAMSotDySykDxOu/0ErZLe0nrlSmW/+eAn8EvFSTTRrCzC5r+o2IcuGPs4j1Nxy5 TdqF/e8mwMcrMN+KlZzk4dyBkbRsrKiEj+r0lCobbE9dJ0DK6zzDcTk9awTNFzkKaRIeSL S5Lk/3vxnwT6zMMb12jKKPay6OISJGjnrPPq67zIqGWzNp5Om960zHMvxGW3EQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1704155833; a=rsa-sha256; cv=none; b=PuqKhnL42wII5OXNKftqUJtc741BARp1EFLqaSbRe8c07wLdEcu30ON/LjBCt+M3805PTq +O1Sa0ec6y7XMhQKC2TRzmsrLFUqnCSx/dacsgNft/2hRsVpH4C6FfkgrqAHBhYJ9zxkBU k5CzYkzEUOvRnDfnzoIaCJWgN6r5HvFpmLp94G7Y2HOqAocWulhVWOvsOpMVnAbhKWD8ut n1Jw+Y43QkMJN1PHgzLf6ExaGu8W1dVoEUAAfxM2hnswxA2Icw+zGW52vELIU9OLis6apT //eC23zmfr6vrzdV958bxPCe4ZJ8xNEvE2YB8uNG5518FXqURAIWPG92Guvgyg== 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=1704155833; 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=hixTeZQHZ/99fhZ53AXUBgUaBsDq2TdF8baanLDspfo=; b=sq+Ur8Kge8S9FN4OWpAw8OXrl7aKb2G8IL+ZeMwHQoEjVhxc21tFsVvU/x+kZxTT/w0KVd Dn66YpXAD4SqdXq8aQWy1rIcQUblBUmE2oYTMp6J2CvB2JJG6ZmnHmbkNJM0R+yyzEFU36 iQQBjHyUtflu2m5NWleCGLWF8qTZaZVaVleVh72QjERogmCUxkLVe43YVHId8nFlWSk0A/ bCISFBYkjV+SuF9B13JWrfCTKLFo/NeHlAcKDFCgsY3jgIiEyQ5N2TF61iHtHuRmTbOCri dz2l22Qkw5t3Eo4UQwo5C+Q5CTgokFoP7YV2rHa2wh1krbz6X6KRqunhOOg/5A== 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 4T3v7Y2pzqzfGw; Tue, 2 Jan 2024 00:37:13 +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 4020bDZl084966; Tue, 2 Jan 2024 00:37:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 4020bD9M084963; Tue, 2 Jan 2024 00:37:13 GMT (envelope-from git) Date: Tue, 2 Jan 2024 00:37:13 GMT Message-Id: <202401020037.4020bD9M084963@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: 4f1e5e94d4ac - stable/14 - hid: Handle errors from copyin() 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/14 X-Git-Reftype: branch X-Git-Commit: 4f1e5e94d4ace6e8c253faa80b462bf0370990e0 Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=4f1e5e94d4ace6e8c253faa80b462bf0370990e0 commit 4f1e5e94d4ace6e8c253faa80b462bf0370990e0 Author: Mark Johnston AuthorDate: 2023-12-26 01:37:49 +0000 Commit: Mark Johnston CommitDate: 2024-01-02 00:29:43 +0000 hid: Handle errors from copyin() in ioctl handlers If copyin() fails, the driver will proceed blindly with a zeroed buffer, which is not what we want. In preparation for annotating copyin() with __result_use_check, start checking for errors. Reviewed by: wulf MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D43102 (cherry picked from commit e452fa70d50761b5fe5f19c3c93c107be116728c) --- sys/dev/hid/hidraw.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/sys/dev/hid/hidraw.c b/sys/dev/hid/hidraw.c index fbc75aaa4e79..6a05b633cfc8 100644 --- a/sys/dev/hid/hidraw.c +++ b/sys/dev/hid/hidraw.c @@ -674,13 +674,16 @@ hidraw_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, sc->sc_state.quiet = true; mtx_unlock(&sc->sc_mtx); if (error != 0) - return(error); + return (error); buf = HIDRAW_LOCAL_ALLOC(local_buf, hgd->hgd_maxlen); - copyin(hgd->hgd_data, buf, hgd->hgd_maxlen); - bus_topo_lock(); - error = hid_set_report_descr(sc->sc_dev, buf, hgd->hgd_maxlen); - bus_topo_unlock(); + error = copyin(hgd->hgd_data, buf, hgd->hgd_maxlen); + if (error == 0) { + bus_topo_lock(); + error = hid_set_report_descr(sc->sc_dev, buf, + hgd->hgd_maxlen); + bus_topo_unlock(); + } HIDRAW_LOCAL_FREE(local_buf, buf); /* Realloc hidraw input queue */ @@ -737,8 +740,11 @@ hidraw_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, default: return (EINVAL); } - if (id != 0) - copyin(hgd->hgd_data, &id, 1); + if (id != 0) { + error = copyin(hgd->hgd_data, &id, 1); + if (error != 0) + return (error); + } size = MIN(hgd->hgd_maxlen, size); buf = HIDRAW_LOCAL_ALLOC(local_buf, size); error = hid_get_report(sc->sc_dev, buf, size, NULL, @@ -775,11 +781,13 @@ hidraw_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, } size = MIN(hgd->hgd_maxlen, size); buf = HIDRAW_LOCAL_ALLOC(local_buf, size); - copyin(hgd->hgd_data, buf, size); - if (id != 0) - id = *(uint8_t *)buf; - error = hid_set_report(sc->sc_dev, buf, size, - hgd->hgd_report_type, id); + error = copyin(hgd->hgd_data, buf, size); + if (error == 0) { + if (id != 0) + id = *(uint8_t *)buf; + error = hid_set_report(sc->sc_dev, buf, size, + hgd->hgd_report_type, id); + } HIDRAW_LOCAL_FREE(local_buf, buf); return (error);