Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3660522pxb; Mon, 24 Jan 2022 14:42:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJyQq6ih5ukjaoQkm+21i4DGDtxvfzivTr7sR1CqSH6Kn9IGt/aCG2vAz7S6mG43ZxPpTnOi X-Received: by 2002:a63:f201:: with SMTP id v1mr4772303pgh.250.1643064168961; Mon, 24 Jan 2022 14:42:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643064168; cv=none; d=google.com; s=arc-20160816; b=Uk+d99A68Hfy+5khVpGaqSVwbZ+m0Pe5fbWu3B3XR5An7GNmXPkSC+AllK6ymx7an3 yd+Mx4VgDT4I/3b7KyEkBUX2uKuRmNrJNfqiqWHYgJtzVSxGDOnKo3uj4dexpuiIHNFi i9BuHGdGSGitUAM3Hs7DoXHgvj8GS3x7cm3qLPUlBiImqRw0D40OT3HYD5ea/BcHcEWt mBgNGsoDvCegNeuEYYtwlusSWd20yzT3rS8QTbDFDcptdwvub7cCE/jPdnEU09THKeqX 5u2fzShlFBq89Z9gRH5V2wWUR+wAW44zwOFNAhVfuC52Qk83LD0yScXwED2G0JRRuZTp PcCA== 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=OCoAvTR4AbeV8bMnLMpO4RIXVMkm4O2Yit8M8juZv2o7H4gtcYCqNvR0t3j04xs0NY k/cgvryo9Ttjma/bQIxatcMDS6KydzHIyIKDI2RBgZe1p5GdEOolh15MvoP+cuYdQWFK D15VLd67qmgMD195Ctcpy1vy2Xb4MUpY1DgM9fH0JkxwyBhterk/7+n37yoJAr/C3qjG gZc0C8uJn3yKXjTJ/rZtUrPWhK0WVc9NsZMPRZJpUz6l5AmnPLL16VtWY0YuNpV98edu 8Dl2ovJFD+O9zjeRcajljp6iVnnnt3ndlQUCpG34xxqqhwEdiLHBB6Fz5joiaGwVGTGy qEQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jejG87W9; 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 o6si3282826plg.356.2022.01.24.14.42.37; Mon, 24 Jan 2022 14:42:48 -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=jejG87W9; 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 S1835678AbiAXWhK (ORCPT + 99 others); Mon, 24 Jan 2022 17:37:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1457288AbiAXVlW (ORCPT ); Mon, 24 Jan 2022 16:41:22 -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 D8618C07E313; Mon, 24 Jan 2022 12:27:37 -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 A0CACB8122D; Mon, 24 Jan 2022 20:27:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C63C4C340E5; Mon, 24 Jan 2022 20:27:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643056055; bh=anTBheG/cQTrGNr9zNDhDMuwJYqOQuxzSHzVVM1jvHM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jejG87W9F0cIZpnjSW2hWmG8tUx94yFLDh89T0xj4usW0nfo50zU3aDfUAL1cHf5b g77y4rwZcMC5SAK9r+oGT4evNuXYNXFouTwRYy9j5foNIZ7T1BXwHZNoRSnX7GA5SS Yl/grQ5EkfACoCNe/kSJKFysX1PzOeZcokI/eiCo= 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.15 328/846] HID: hid-uclogic-params: Invalid parameter check in uclogic_params_init Date: Mon, 24 Jan 2022 19:37:25 +0100 Message-Id: <20220124184112.216495020@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@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