Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3706600pxb; Mon, 24 Jan 2022 15:56:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJwZtyPxbEKcea9ovgfcr6/pihzgqzPSrGiF2HSKODKlwqpgvgcAmdHArIuXkHdljt7KA9ol X-Received: by 2002:a17:902:b687:b0:149:90e2:8687 with SMTP id c7-20020a170902b68700b0014990e28687mr16578579pls.131.1643068470606; Mon, 24 Jan 2022 15:54:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643068470; cv=none; d=google.com; s=arc-20160816; b=PAeOlxYFihEyAUx3dZKSlWa7GeaEBmE7sPpY12nQQVCDdAS2+kyEcQ1qgbZ5DeuNiL 3bJKO30J7b8wWiz66MXYSupWCVXzsFveYKBAfuSFgT1Qy7SU0UFzCYNTo4FpmnCu09xS oeo1uzvivZci7Ka7Y88+sMlEHhSP3nLk4BweCQQMszX1gRSldt4H8lFINJFt4LpfhObi dlyBL5vt821wPHedTe/Fbs9DRT1YjzACI1xnjuVlMVVUeWEUkJ0jrBh8J4A9ZHpqLO7b l/KoceKzywR3vf01BiGkuETxqilIWNitqSZ7AhBmixaaXT9E6M2InawITvQxzo5KhMug 1cfw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4SzE13jmT6MI5cMu+8WCinsJVl+uWAS4K2BtB2qZ//c=; b=A1KRaynIP7CcOTnNT8G4KqGoNOjgxB7JvEIUfCSJFVOnIutSvNAVqCW4Wb4njRRnRd 5ra1OJn0+mLNSImXszvYkn14hNpIRagPIgcDV8+vAs/cSy+OFl0+bBbmT4xI6vuqTqen t7CxA2K6WpbLOri9mYe+22r8d5NeCyx/yphH/UfSGjHAb5UHi0TK/YazyK7ogoa5efoN X9ODk+mpKQGxFjXqcHtzLfGz3VipN5g0z6qaXskOlXjLOPSESSBd1DqaL5FJluAGf7Qm H7PbbqVLtfr8utXYSQGPnQ6CGGiKRfjTj5CKfM7Y4HN1gnTaWX+3MvDgcuXnwX//GlpN CazA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=A0LnkABh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 125si16081810pgi.278.2022.01.24.15.54.18; Mon, 24 Jan 2022 15:54:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=A0LnkABh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2362047AbiAXXl3 (ORCPT + 99 others); Mon, 24 Jan 2022 18:41:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383742AbiAXW6B (ORCPT ); Mon, 24 Jan 2022 17:58:01 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3B9FC08E877; Mon, 24 Jan 2022 13:12:44 -0800 (PST) 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 6B3CAB81243; Mon, 24 Jan 2022 21:12:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 878E7C340E5; Mon, 24 Jan 2022 21:12:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643058763; bh=anTBheG/cQTrGNr9zNDhDMuwJYqOQuxzSHzVVM1jvHM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A0LnkABhV7JA/vE59syLzc7bFfbUBSj1bBG58XdJaGZCRgOaar6748BsLYec1rkwq +B7QJJsqgTLrbwFUMALuful7dk+zqdKYCM1SGJtQRQwx0h1vOxnEmMFphdAquFnJEE IvoBQzMyx+SPNiWk246pWvTZuFQwknnx7LsCrieI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= , Jiri Kosina , Sasha Levin Subject: [PATCH 5.16 0394/1039] HID: hid-uclogic-params: Invalid parameter check in uclogic_params_init Date: Mon, 24 Jan 2022 19:36:23 +0100 Message-Id: <20220124184138.566261375@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: José Expósito [ Upstream commit f364c571a5c77e96de2d32062ff019d6b8d2e2bc ] The function performs a check on its input parameters, however, the hdev parameter is used before the check. Initialize the stack variables after checking the input parameters to avoid a possible NULL pointer dereference. Fixes: 9614219e9310e ("HID: uclogic: Extract tablet parameter discovery into a module") Addresses-Coverity-ID: 1443831 ("Null pointer dereference") Signed-off-by: José Expósito Signed-off-by: Jiri Kosina Signed-off-by: Sasha Levin --- drivers/hid/hid-uclogic-params.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/hid/hid-uclogic-params.c b/drivers/hid/hid-uclogic-params.c index adff1bd68d9f8..3c10b858cf74c 100644 --- a/drivers/hid/hid-uclogic-params.c +++ b/drivers/hid/hid-uclogic-params.c @@ -834,10 +834,10 @@ int uclogic_params_init(struct uclogic_params *params, struct hid_device *hdev) { int rc; - struct usb_device *udev = hid_to_usb_dev(hdev); - __u8 bNumInterfaces = udev->config->desc.bNumInterfaces; - struct usb_interface *iface = to_usb_interface(hdev->dev.parent); - __u8 bInterfaceNumber = iface->cur_altsetting->desc.bInterfaceNumber; + struct usb_device *udev; + __u8 bNumInterfaces; + struct usb_interface *iface; + __u8 bInterfaceNumber; bool found; /* The resulting parameters (noop) */ struct uclogic_params p = {0, }; @@ -848,6 +848,11 @@ int uclogic_params_init(struct uclogic_params *params, goto cleanup; } + udev = hid_to_usb_dev(hdev); + bNumInterfaces = udev->config->desc.bNumInterfaces; + iface = to_usb_interface(hdev->dev.parent); + bInterfaceNumber = iface->cur_altsetting->desc.bInterfaceNumber; + /* * Set replacement report descriptor if the original matches the * specified size. Otherwise keep interface unchanged. -- 2.34.1