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 5839228EB for ; Mon, 30 Jan 2023 14:12:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7F3DC433EF; Mon, 30 Jan 2023 14:12:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675087933; bh=8p/xeOIoapy+wEU9yglndDAsvBh0eaGTdbj5+Yohxgw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WVECyNbSYJzOilwKsttMR8/tVCtao67LO85zLJ4z5v/dAQ3hfApW8LfNzjSlxsCc1 4GBLV0e4clP/soEIWBB/v0hAq9S3HcYjIxcpUHrHQGfOy+xjcT/TeFvO/D/T4nJYxf stH9k4MxhdBfd4sH4IKwkRGf8OxuSpv5kzab/HjY= 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 5.15 058/204] HID: check empty report_list in hid_validate_values() Date: Mon, 30 Jan 2023 14:50:23 +0100 Message-Id: <20230130134318.867399178@linuxfoundation.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230130134316.327556078@linuxfoundation.org> References: <20230130134316.327556078@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 ef9c799fa371..2e475bd426b8 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -988,8 +988,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