From nobody Tue Jan 02 01:12:55 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 4T3vwm2vkDz563FX; Tue, 2 Jan 2024 01:12:56 +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 4T3vwm100Kz3ZhV; Tue, 2 Jan 2024 01:12:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704157976; 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=xQ68K076c8dr/GCNQwgHuuL7EzUJ4cz7R35hILXM81E=; b=do6R3E8SpKqGfg0mrBjc3kSY8j930Co3KRl9tHNoSUb/hiegXaTfPLaclnMXFi19FWZohY 8weTlBTxF/B1D9kE1e9dyguS8J9JOmaoEFLD49hRNuq+K9tIjzqJn5s4Zja9CuQQCBDubZ Zb5d4r6TAwar6jgtLY/dykB0vxC4m7+1uJ0xPc05AnYi6WRCVFsM7DneTgSfy+UnhYh8Y9 kvP+OdOFDJ7qIg1OYxGxjT9rIAPFlE0pymbb9EPgp7jFFeivqAYmNVn1rHOrF0JMEw4nE8 NhjIXzU/38aMkSgwbHqGNyBiciWMSX1YKWtoPlceac+RZ6FaNvqxnL1zCZWiDg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1704157976; a=rsa-sha256; cv=none; b=ApAVhC06YWAmQSUEZCF1BFhj1WiKIWGe4e1b0hE3iYtYVRnEh0YC33y2B0oOIzF06YwK10 2ZzFAyzak3X7Zo6Lyuj6XkjzaBx+hyEI/v/Fiqj3MBpOX8+Ytr6bzCGozz2FIK1Tqh4/td TJUmhPcERqgDdeZIWzvqrUQqIEAeWy4PBV5liitdREd7DBOm92a2pUDoEFcE6jdSAr/hEt LABEZi42dktFzJZI+fUO+Empdi9Fsi7U/EgjnArOkUFaQsURm/V3vWmye25GnE3iA1b06R oFrjDggVCGl3LhGnHx5Q5O53X2AM3RbnopqKyRmX2A/BVfm3dM6LK3EdQvTY6Q== 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=1704157976; 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=xQ68K076c8dr/GCNQwgHuuL7EzUJ4cz7R35hILXM81E=; b=nDDrXGSmhbS5OF6UtsrCp0a8TjDH1u9ijov4K/Sf0+AxYUqwFwOyRk0BNI56ma+8CyTtBd U4pfsbOqTJEezfH5jBXxbOS0IlK4htJdUNt8t0loacDoit24uYIsXbc6X8AkhuQIy4fVOF qBP9c7o0TqE6xi2cBw3RIxLXjERHsr6CJh+c0/25ksydOROqn5TB0LK2n3Ztx+Bzg5VqmJ /kETxc/e/cXdFJvFVmrKClZqs7988sfXOYFpqUEXeF5BaYqiwcucxfYVNOV9fsncrMeyR/ w/tLg26WdUX8zL5GxGQFF6cHtiGdbBRYmVIcPKdij8j9tDDxt5B6ezgB2wsFvg== 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 4T3vwm05XWzgc1; Tue, 2 Jan 2024 01:12:56 +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 4021Ctvh054617; Tue, 2 Jan 2024 01:12:55 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 4021Ctlq054614; Tue, 2 Jan 2024 01:12:55 GMT (envelope-from git) Date: Tue, 2 Jan 2024 01:12:55 GMT Message-Id: <202401020112.4021Ctlq054614@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: 7db5449ec5b1 - stable/13 - 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/13 X-Git-Reftype: branch X-Git-Commit: 7db5449ec5b176036b28c9b91a91ea2d09f37566 Auto-Submitted: auto-generated The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=7db5449ec5b176036b28c9b91a91ea2d09f37566 commit 7db5449ec5b176036b28c9b91a91ea2d09f37566 Author: Mark Johnston AuthorDate: 2023-12-26 01:37:49 +0000 Commit: Mark Johnston CommitDate: 2024-01-02 01:12:44 +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 | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/sys/dev/hid/hidraw.c b/sys/dev/hid/hidraw.c index 103f73bb3750..c47a1445f7af 100644 --- a/sys/dev/hid/hidraw.c +++ b/sys/dev/hid/hidraw.c @@ -673,14 +673,17 @@ 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); - /* Lock newbus around set_report_descr call */ - mtx_lock(&Giant); - error = hid_set_report_descr(sc->sc_dev, buf, hgd->hgd_maxlen); - mtx_unlock(&Giant); + error = copyin(hgd->hgd_data, buf, hgd->hgd_maxlen); + if (error == 0) { + /* Lock newbus around set_report_descr call */ + mtx_lock(&Giant); + error = hid_set_report_descr(sc->sc_dev, buf, + hgd->hgd_maxlen); + mtx_unlock(&Giant); + } 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);