From nobody Tue Dec 26 02:04:13 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 4SzdPB0ffBz55Kg5; Tue, 26 Dec 2023 02:04:14 +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 4SzdP96B5Yz4K6c; Tue, 26 Dec 2023 02:04:13 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703556253; 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=BHEWpWycritAvUTbrXunq+0Dokcx6AiIGPcAk7gUxsA=; b=kNI6xSDid1nGYpZO2piwR0hvputa+a9wAUKalDl+Mcy1kEBreMtdmZNO2Vnv0Mz5+zpwq4 AkIPT2vrNz3yAqtcUR6CMSqCFn3n3VHbFO4zY+0N2FlwFwEpnw+6c06bIWeSX84eSYDTFA f3iozXJ4OK2ucnpWZ0zq2onvVxiLmyrbxkYFpJKW++4Au78UxUKduPzZkUhZGCB9HmlJQv DDap0hkLYlRbhiZlIf4aZkSwtzAUKQpnkQfEEu/7OIDkRz09FsCK9LWwq9mDXoXT6zrlo0 ZPeuNfVRAysMLWChhVLB97O9kJtAGeroNZWb3eTr5ttN1rCNJ3LFhHUNcAJb5Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1703556253; a=rsa-sha256; cv=none; b=sLwqWAxayNVjrG4BYHxRWY7G1yZQpqNn97avrJfx16qm5xMTK4meJuXuqAMpHd06Kj++mH gT6R6w9Q8A35FuQtu0M0yIil8FI06JxZbB618/KCYRXi4PZHzgbhHjh31aQo7EFesNgAPt 2g6FEbMoBj41vhyMuoivVO3w+6F+3e2Y3EYyw20nDj4dOaOMXc0aeIF9nxYF6H1cgtkOY/ NNlqDZp5etBSJaJaEyAe4J3WpKSQUYp7RqZC8gG+D3ycZHiJOs8Hd2PUegSrvXcaShEqbD sVjcAqXBwbTPXMOW3cr8wOm5qTTyvCXU2CCf9gumlyvmVn9663a84CJkVxf/QA== 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=1703556253; 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=BHEWpWycritAvUTbrXunq+0Dokcx6AiIGPcAk7gUxsA=; b=kzrp0xfICPHTQJ5Ax4h3IcxN2e2TDoQ+5neZ/QGpcn6Xv8FD6J4ENKrK5avX8YoBU/Mnsm tEoWd8k8pG/E0JjC8csMBYTrpMZfL/kj0LUfkRkmSZkKv3aoKe1HHIyBOty6PVTq3Mh8Ut jOKfFZRl2nRIaW7ZHzmMGlLYN6kjS230MBPAZaWC7lJzgHd3jYHyTvrALcibbaDtmE5War wz6XoKr30J8qtwVHkWbDhsm6Svsswc9z3rsPy1gLTimB6lOccAbd9xQ6HuhJS0M+Ol2RIQ dM/K174EENTRMmhAvM7ojG37gTyf0+26n1XflLnVs9y85ZY3Ze4lhZ1Bz8nVrA== 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 4SzdP95Gzczc76; Tue, 26 Dec 2023 02:04: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 3BQ24Dl6002734; Tue, 26 Dec 2023 02:04:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BQ24D4X002731; Tue, 26 Dec 2023 02:04:13 GMT (envelope-from git) Date: Tue, 26 Dec 2023 02:04:13 GMT Message-Id: <202312260204.3BQ24D4X002731@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: e452fa70d507 - main - 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/main X-Git-Reftype: branch X-Git-Commit: e452fa70d50761b5fe5f19c3c93c107be116728c Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=e452fa70d50761b5fe5f19c3c93c107be116728c commit e452fa70d50761b5fe5f19c3c93c107be116728c Author: Mark Johnston AuthorDate: 2023-12-26 01:37:49 +0000 Commit: Mark Johnston CommitDate: 2023-12-26 02:04:00 +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 --- 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);