From patchwork Wed Aug 3 11:18:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 595972 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB6E7C19F28 for ; Wed, 3 Aug 2022 11:18:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235910AbiHCLSr (ORCPT ); Wed, 3 Aug 2022 07:18:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236025AbiHCLSp (ORCPT ); Wed, 3 Aug 2022 07:18:45 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B2B31EAE4; Wed, 3 Aug 2022 04:18:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 3F9BCB8218C; Wed, 3 Aug 2022 11:18:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F571C433B5; Wed, 3 Aug 2022 11:18:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659525519; bh=KTd8fRP47mLP0UrLpy2lvoBm0eFfO+elRoExboH/uuo=; h=From:To:Cc:Subject:Date:From; b=E/G8zxf+sWaO+j0AtxpttUACqdmTZi+1wZQyKFfEaoaR8NwthAI2uNKTh4pJEW4Hj LO2x9JZrVhgsBa5XDzoR2JGVhnm77Zb94tIVMgnTUU4584tbDOfNYmPCCq3FegxNce okPwgsYp1TMGO34yFjrRwWDLk5iJ/9r89Y9WzhV+XSQ9YKesSiu0Kw3PYobszvVG4x ssHZ5icHaNlj0qg+RvkEmdK9VuhTyITxb3xsE0pzCXNjP7maXcvA0y/qMRMtLZhWF/ CMT5djWK7M5LbpOr37gHmEqneCXJE+N4P5pj7DQNBPVd8J4WtsAmI/7/Fqeg+uhhZe wi/hJtBYJmRIA== From: Lee Jones To: lee@kernel.org Cc: linux-kernel@vger.kernel.org, Jiri Kosina , Benjamin Tissoires , linux-input@vger.kernel.org Subject: [RESEND] HID: steam: Prevent NULL pointer dereference in steam_{recv,send}_report Date: Wed, 3 Aug 2022 12:18:31 +0100 Message-Id: <20220803111831.387506-1-lee@kernel.org> X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org It is possible for a malicious device to forgo submitting a Feature Report. The HID Steam driver presently makes no prevision for this and de-references the 'struct hid_report' pointer obtained from the HID devices without first checking its validity. Let's change that. Cc: Jiri Kosina Cc: Benjamin Tissoires Cc: linux-input@vger.kernel.org Fixes: c164d6abf3841 ("HID: add driver for Valve Steam Controller") Signed-off-by: Lee Jones --- drivers/hid/hid-steam.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/hid/hid-steam.c b/drivers/hid/hid-steam.c index a3b151b29bd71..fc616db4231bb 100644 --- a/drivers/hid/hid-steam.c +++ b/drivers/hid/hid-steam.c @@ -134,6 +134,11 @@ static int steam_recv_report(struct steam_device *steam, int ret; r = steam->hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0]; + if (!r) { + hid_err(steam->hdev, "No HID_FEATURE_REPORT submitted - nothing to read\n"); + return -EINVAL; + } + if (hid_report_len(r) < 64) return -EINVAL; @@ -165,6 +170,11 @@ static int steam_send_report(struct steam_device *steam, int ret; r = steam->hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0]; + if (!r) { + hid_err(steam->hdev, "No HID_FEATURE_REPORT submitted - nothing to read\n"); + return -EINVAL; + } + if (hid_report_len(r) < 64) return -EINVAL;