From patchwork Mon Jan 16 11:11:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pietro Borrello X-Patchwork-Id: 13102916 X-Patchwork-Delegate: jikos@jikos.cz 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 28D12C46467 for ; Mon, 16 Jan 2023 11:12:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229531AbjAPLMG (ORCPT ); Mon, 16 Jan 2023 06:12:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229706AbjAPLME (ORCPT ); Mon, 16 Jan 2023 06:12:04 -0500 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69D1386A7 for ; Mon, 16 Jan 2023 03:12:02 -0800 (PST) Received: by mail-ed1-x529.google.com with SMTP id z11so40271107ede.1 for ; Mon, 16 Jan 2023 03:12:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=diag.uniroma1.it; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=OTrwWvqf/cRj16lBWCPzPOJDd8vRArGRQ3nxDRY36BM=; b=FeV4C76oPMHwPkqAKitzAGRxcwdsIdeIsI30Tuv05Q4IgMwrOK6YPHgoT2xX2JA43g N1RRB2mTfRN8LFTHj7JwlLHR250+ARiKjprLGBiXP0CvlEXCwlSFiYlv0Z74OzS/WE1t +0pu4a4gd7Qrmfr/Rp0UHdWaTGHXGWT7VoGvo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OTrwWvqf/cRj16lBWCPzPOJDd8vRArGRQ3nxDRY36BM=; b=GdF738wt4J33sJTKT0nj2hkX4/cGVZoSv1byUO/uLZWHchG6SWYVBFUKPYJ1bpy6e/ Al2lGYzTompoS34B6Z57vMhJb1Qfo4MjGJMKmigTz+igvwSerGxtT6tpvTudBYmRbMi6 28Zf2vhHAUtOggchlHMyU7uc6Hvy6ogHi8e6dJEuxii++I+LXwigBfeRH/7gpbtNbvLn HCjrLnnClVRqQSLAj1A0eUfEFo4OGrgfYonolREfprFow43SaBR6Sf5MicGpBgbkN66r N0O21CjRpWSym7oxp+BC+C5u61nikCTtfTCdhSlbyw45fe815TiZBPuzzEFnUFNOe4Pt B+/g== X-Gm-Message-State: AFqh2ko7NMovKAM+X7YVS+a5yCYQmI90d1rmEFNMgdT2mOUIutu4UxfE HawsgXiJSkQPnZg3JVARnYWSug== X-Google-Smtp-Source: AMrXdXtrB2AvCCe5ljQEIoSQlRC1Hoi6lqHsGHrUDSpKjSdJUD4tpHCC9jx42+tVPCQ+9iIMEwwS/g== X-Received: by 2002:aa7:cb42:0:b0:496:f517:d30d with SMTP id w2-20020aa7cb42000000b00496f517d30dmr32959917edt.38.1673867520946; Mon, 16 Jan 2023 03:12:00 -0800 (PST) Received: from [192.168.17.2] (wolkje-127.labs.vu.nl. [130.37.198.127]) by smtp.gmail.com with ESMTPSA id dk1-20020a0564021d8100b0049be07c9ff5sm4116903edb.4.2023.01.16.03.12.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jan 2023 03:12:00 -0800 (PST) From: Pietro Borrello Date: Mon, 16 Jan 2023 11:11:24 +0000 Subject: [PATCH 1/2] HID: check empty report_list in hid_validate_values() MIME-Version: 1.0 Message-Id: <20230114-hid-fix-emmpty-report-list-v1-1-e4d02fad3ba5@diag.uniroma1.it> References: <20230114-hid-fix-emmpty-report-list-v1-0-e4d02fad3ba5@diag.uniroma1.it> In-Reply-To: <20230114-hid-fix-emmpty-report-list-v1-0-e4d02fad3ba5@diag.uniroma1.it> To: Jiri Kosina , Benjamin Tissoires , Kees Cook , Hanno Zulla Cc: Cristiano Giuffrida , "Bos, H.J." , Jakob Koschel , Jiri Kosina , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Pietro Borrello X-Mailer: b4 0.11.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1673867519; l=1184; i=borrello@diag.uniroma1.it; s=20221223; h=from:subject:message-id; bh=lt3do0cht6iOkduDwABvx2MxZ4GcPzw6T54suUgL54M=; b=D3EiqPP7uMKKmpKLJr7Zf6V5hG96SLdJWn+3FwR3uTqwjfK+hlIpfSI6dO3BZ3Io7YVXWw37E29d ssVUXB95AYjJfF27QCNsq7yJw/LVCZ4AnhgNYkTRjBbn286Z1Pxv X-Developer-Key: i=borrello@diag.uniroma1.it; a=ed25519; pk=4xRQbiJKehl7dFvrG33o2HpveMrwQiUPKtIlObzKmdY= Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Add a check for empty report_list in hid_validate_values(). The missing check causes a type confusion when issuing a list_entry() on an empty report_list. The problem is caused by the assumption that the device must have valid report_list. While this will be true for all normal HID devices, a suitably malicious device can violate the assumption. Fixes: 1b15d2e5b807 ("HID: core: fix validation of report id 0") Signed-off-by: Pietro Borrello --- drivers/hid/hid-core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index bd47628da6be..3e1803592bd4 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -993,8 +993,8 @@ struct hid_report *hid_validate_values(struct hid_device *hid, * Validating on id 0 means we should examine the first * report in the list. */ - report = list_entry( - hid->report_enum[type].report_list.next, + report = list_first_entry_or_null( + &hid->report_enum[type].report_list, struct hid_report, list); } else { report = hid->report_enum[type].report_id_hash[id]; From patchwork Mon Jan 16 11:11:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pietro Borrello X-Patchwork-Id: 13102918 X-Patchwork-Delegate: jikos@jikos.cz 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 3663BC677F1 for ; Mon, 16 Jan 2023 11:12:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229464AbjAPLMI (ORCPT ); Mon, 16 Jan 2023 06:12:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229535AbjAPLME (ORCPT ); Mon, 16 Jan 2023 06:12:04 -0500 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2908AB747 for ; Mon, 16 Jan 2023 03:12:03 -0800 (PST) Received: by mail-ed1-x52d.google.com with SMTP id v10so39032000edi.8 for ; Mon, 16 Jan 2023 03:12:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=diag.uniroma1.it; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=e8iSePi43/1oa+PXasTdV2oiRmbbh0AS7xFey01UdB8=; b=t8hg+KGoh84kOMTcYtqVrn1jGjAAjFWqVQBvdYr/1UStUvSAZ6BXvorlTMxYWjNhhb sAIFjy5UUMwTnsKwwySnFEbhRHN56bE951JfTuKyNKQO1toWG++AOhk6CmIhqWJ7r9Hj IZjZO581rCqEOLCtqw5TSP9gm40EgzxbmMnzA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=e8iSePi43/1oa+PXasTdV2oiRmbbh0AS7xFey01UdB8=; b=noHGbVamAaERuePQyBr6bsuaktP2pELXkOOIfI7rFmE2KQJI+czz0/3gKA5pya+Rxt pq1c8/pKnICOceMErT2woOcQtdXm8pJaur/EEYQpeE557suZlp0nK5rHmNlLmGE7TiE0 cH8FYB+Zy5Fm0S3hCGl540eYKGqDFZQ8Z4DNL/X7R1PCn+xKTaydPAgSBk+lpnNyhwgT 0mdky885fTi0RD4QLbqXo0QKShPOclapeBQ/vzYfnlpqPMGseHIwwPB3Nd8WN1D45sGx 9P8AzbcY95rW59gmMtewKpjImv8WWL7Cw6c8qcEiZU4olTD7Cgr98gpEjpE+UJAubzc1 yZdw== X-Gm-Message-State: AFqh2kq4+sO+YvHWkvK2xI9HlSb9stpc2SWJ/e0/b9fBTNzFuugMs9yR efw/t/GBBWX2Fha4TUY97iQWMg== X-Google-Smtp-Source: AMrXdXv6TFEdiWntsO1tjHxNabDcEcoLUwHotCmNHH/iJGi1E2185mgAXI+YWrRTMFa7kC5MiZeVUQ== X-Received: by 2002:a05:6402:e0f:b0:468:58d4:a0f2 with SMTP id h15-20020a0564020e0f00b0046858d4a0f2mr87788527edh.23.1673867521686; Mon, 16 Jan 2023 03:12:01 -0800 (PST) Received: from [192.168.17.2] (wolkje-127.labs.vu.nl. [130.37.198.127]) by smtp.gmail.com with ESMTPSA id dk1-20020a0564021d8100b0049be07c9ff5sm4116903edb.4.2023.01.16.03.12.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jan 2023 03:12:01 -0800 (PST) From: Pietro Borrello Date: Mon, 16 Jan 2023 11:11:25 +0000 Subject: [PATCH 2/2] HID: check empty report_list in bigben_probe() MIME-Version: 1.0 Message-Id: <20230114-hid-fix-emmpty-report-list-v1-2-e4d02fad3ba5@diag.uniroma1.it> References: <20230114-hid-fix-emmpty-report-list-v1-0-e4d02fad3ba5@diag.uniroma1.it> In-Reply-To: <20230114-hid-fix-emmpty-report-list-v1-0-e4d02fad3ba5@diag.uniroma1.it> To: Jiri Kosina , Benjamin Tissoires , Kees Cook , Hanno Zulla Cc: Cristiano Giuffrida , "Bos, H.J." , Jakob Koschel , Jiri Kosina , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Pietro Borrello X-Mailer: b4 0.11.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1673867519; l=1136; i=borrello@diag.uniroma1.it; s=20221223; h=from:subject:message-id; bh=XYXrgNLtkM9f60Vo/ecJS9HAYWzb6NUELifPUuIruDU=; b=vLu1y0BiQa9KA1E8lDi8s2talWDgpEgLlLaAXA2rWuFanZp7a0Pv/AQhZQdS8easf6PqMc60XpAV FBCnpj0dAM2Ll3mOUTLNfobbFBjv/3U6c/IVbN7nxAuj+ACK81Uy X-Developer-Key: i=borrello@diag.uniroma1.it; a=ed25519; pk=4xRQbiJKehl7dFvrG33o2HpveMrwQiUPKtIlObzKmdY= Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Add a check for empty report_list in bigben_probe(). The missing check causes a type confusion when issuing a list_entry() on an empty report_list. The problem is caused by the assumption that the device must have valid report_list. While this will be true for all normal HID devices, a suitably malicious device can violate the assumption. Fixes: 256a90ed9e46 ("HID: hid-bigbenff: driver for BigBen Interactive PS3OFMINIPAD gamepad") Signed-off-by: Pietro Borrello --- drivers/hid/hid-bigbenff.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/hid/hid-bigbenff.c b/drivers/hid/hid-bigbenff.c index e8c5e3ac9fff..e8b16665860d 100644 --- a/drivers/hid/hid-bigbenff.c +++ b/drivers/hid/hid-bigbenff.c @@ -344,6 +344,11 @@ static int bigben_probe(struct hid_device *hid, } report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; + if (list_empty(report_list)) { + hid_err(hid, "no output report found\n"); + error = -ENODEV; + goto error_hw_stop; + } bigben->report = list_entry(report_list->next, struct hid_report, list);