From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E2581FB4 for ; Fri, 3 Feb 2023 10:19:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 868FAC4339B; Fri, 3 Feb 2023 10:19:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675419575; bh=/NGu3Yi8Kh/SzcCLvM40A0UwCroSA2kULjzok+8Fmlk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UHDlAxKmNQMCsxIOdDIJ5MsT9wLt2iEoFsYm2mdBGFlQqREGB06+JE/SUU4aKpUJn RH5Ivk707p+BXeGmlGdVvhtbg1W0Pdx3e5EMOXU2Vwnhtn3kpyuTEJPnwZBNQ2TPfF fwJsEWGoU7aC6rvybjH3tvrpeAzTzBsAbSinRBRQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Pietro Borrello , Jiri Kosina , Sasha Levin Subject: [PATCH 4.19 18/80] HID: check empty report_list in hid_validate_values() Date: Fri, 3 Feb 2023 11:12:12 +0100 Message-Id: <20230203101015.975059012@linuxfoundation.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230203101015.263854890@linuxfoundation.org> References: <20230203101015.263854890@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Pietro Borrello [ Upstream commit b12fece4c64857e5fab4290bf01b2e0317a88456 ] 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 Signed-off-by: Jiri Kosina Signed-off-by: Sasha Levin --- 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 62656636d30c..8cc79d0d11fb 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -980,8 +980,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]; -- 2.39.0