Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp307616imn; Wed, 3 Aug 2022 04:50:00 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uhJonQAEgkh1yk01jopUvuE1kBLk7punDdBIX1MegFD1bRImx0dDqWZId/qrsgOmNpCAEj X-Received: by 2002:a62:3086:0:b0:52b:fd6c:a49d with SMTP id w128-20020a623086000000b0052bfd6ca49dmr24824350pfw.26.1659527399472; Wed, 03 Aug 2022 04:49:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659527399; cv=none; d=google.com; s=arc-20160816; b=McayOAWO+WHxfhcmHNZR77O41DtCn1kbb4UdYhhDfHW7TuSkG0OcwYUd80fP186Ffo 6A8uGUJgi5qj5XXpAnNto6rD37xqyu4Su2KcfkRcCRHuU4WOFk5R1EHckdSnHbxrCJMv 1UEtTGWYBTfWTgrKAIk5XHv9XT34fBz693PKucbAHNcxMMGyPYnxq3qYIxee6CP5wXxt CNSEALLRmaoeFfaqkSK0y67MBCc7Hh1wE2eQPI708U1wYzfpzfP0BiqO9QXpjTqIK2Wq wgp3xRNWGOAVW2mjlU5SHdvmVbCR+DaOoqgnpfzSOQUod/nqLTvc/sLo78x/Q7IsTb6P Uhaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=KPQenKUNZXdxE/rI3e+ThRk8MKujq5yHgarN1POVL5g=; b=uSG6l1qN36KXjUoQYyyBm8IdOadjPIxN4QwovWoaLYvffXIOj5LfZNh4Ik/1D0B0yQ XHUyMObg7F1X+Dxi4I2jLWXm6XQYmI9GS0OznYSUv9+eGu7IRxj4t1sUYvxwasEDeewJ LDb4VPqUHqcES4Wp7IS3QJDlVTXwDGfDTWJlYFfvmbldolsSKJx3Xc6tYXr/4Qh7fedd ik4D9j9ZOwdAnioDfFAIKucP0zu2jKWf5VjL+ELe0c+zJi28uTE1PoPgoxCqswFi04L2 3yWrw+MVGzVqCAJuZVb6LYBifApBm3+jsTrb8f/p5yUXUdDh/Bq3LrT2Zqh1wsiurB41 mAug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="E/G8zxf+"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y125-20020a633283000000b00415d7f01122si16801590pgy.273.2022.08.03.04.49.43; Wed, 03 Aug 2022 04:49:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="E/G8zxf+"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236040AbiHCLSv (ORCPT + 99 others); Wed, 3 Aug 2022 07:18:51 -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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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; -- 2.37.1.455.g008518b4e5-goog