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 0A20D2528ED; Mon, 31 Mar 2025 14:57:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743433056; cv=none; b=A1/DmOWZcbcQntDQmkwRC0Y2sY43MXiZAGCo2Y3wn6LQmVYoRdpG2+4EdAd+iuK1FYyCrmRovVCZ6Xk4mQhXwDJ0vVfwGA0+Y25GJw7iEcmPhPokbKplnPCOnSh+SUk/EXtn5I4SW7N/iNi1NCQxQLI/jzAsJpgdq//5oFv89/E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743433056; c=relaxed/simple; bh=NVLozsaYedadfSYx5D/Ah92WhepsYqoR1n2WxLWQlQY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=j49bKVopdRTTJLCIBdEwQPqRN0vPer6rxJUxB/4lTk4qe0F3Cg7CBhfgcq/EZUGhnJSy6WCbwZhU6TRSnrwItLACdi+gOlN/bDuNhm6fe76/zaIBe3WlFbPDjZiuNh/Z4pOZDU/UjOtyTgO0gcvKGa57ztlcTtyjQPaaeQtnDsI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sedjpUf5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="sedjpUf5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4477C4CEE3; Mon, 31 Mar 2025 14:57:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743433055; bh=NVLozsaYedadfSYx5D/Ah92WhepsYqoR1n2WxLWQlQY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sedjpUf5lAz2smOE2l46Lokc4Jy46HnawmAZ0a8Ti4X6UPx254jfpZvFDcIsBvnP9 Bz/59q6NdDIblYMQpdWmqCXqSX806QRdSTeRfzaYL6xKNTyWWyjUtEJkbSlOhbPzNG hIaCiVtg0dGbD8u3AbpJI+Ge5WPvAnVlLXLNjzC1+ITABU6aa93OnI4DioI0scVh4b yhy2pzVPNYq1mzP7BBgW/ot6SUA6au7P9o6Tm0c7QZux+tqHvACUY87frhu/foC5iu xxYAZVn2kyD7jl/f2cdlExc3bphd7ZxAB1aKgTxkyMWZ9swWrSNbMD4EsDxIBTSFWs GVUTEUINpzHbg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: =?UTF-8?q?Tomasz=20Paku=C5=82a?= , Nolan Nicholson , =?UTF-8?q?Tomasz=20Paku=C5=82a?= , =?UTF-8?q?Micha=C5=82=20Kope=C4=87?= , Paul Dino Jones , =?UTF-8?q?Crist=C3=B3ferson=20Bueno?= , Pablo Cisneros , Jiri Kosina , Sasha Levin , jikos@kernel.org, bentiss@kernel.org, linux-usb@vger.kernel.org, linux-input@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 3/5] HID: pidff: Fix null pointer dereference in pidff_find_fields Date: Mon, 31 Mar 2025 10:57:26 -0400 Message-Id: <20250331145728.1706329-3-sashal@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250331145728.1706329-1-sashal@kernel.org> References: <20250331145728.1706329-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 5.4.291 Content-Transfer-Encoding: 8bit From: Tomasz Pakuła [ Upstream commit 22a05462c3d0eee15154faf8d13c49e6295270a5 ] This function triggered a null pointer dereference if used to search for a report that isn't implemented on the device. This happened both for optional and required reports alike. The same logic was applied to pidff_find_special_field and although pidff_init_fields should return an error earlier if one of the required reports is missing, future modifications could change this logic and resurface this possible null pointer dereference again. LKML bug report: https://lore.kernel.org/all/CAL-gK7f5=R0nrrQdPtaZZr1fd-cdAMbDMuZ_NLA8vM0SX+nGSw@mail.gmail.com Reported-by: Nolan Nicholson Signed-off-by: Tomasz Pakuła Reviewed-by: Michał Kopeć Reviewed-by: Paul Dino Jones Tested-by: Paul Dino Jones Tested-by: Cristóferson Bueno Tested-by: Pablo Cisneros Signed-off-by: Jiri Kosina Signed-off-by: Sasha Levin --- drivers/hid/usbhid/hid-pidff.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c index ba0d7cb15377e..7801294fe086d 100644 --- a/drivers/hid/usbhid/hid-pidff.c +++ b/drivers/hid/usbhid/hid-pidff.c @@ -770,6 +770,11 @@ static void pidff_set_autocenter(struct input_dev *dev, u16 magnitude) static int pidff_find_fields(struct pidff_usage *usage, const u8 *table, struct hid_report *report, int count, int strict) { + if (!report) { + pr_debug("pidff_find_fields, null report\n"); + return -1; + } + int i, j, k, found; for (k = 0; k < count; k++) { @@ -883,6 +888,11 @@ static int pidff_reports_ok(struct pidff_device *pidff) static struct hid_field *pidff_find_special_field(struct hid_report *report, int usage, int enforce_min) { + if (!report) { + pr_debug("pidff_find_special_field, null report\n"); + return NULL; + } + int i; for (i = 0; i < report->maxfield; i++) { -- 2.39.5