Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3592763pxb; Mon, 24 Jan 2022 13:03:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJyRe93Kb0kxvhSqvODRoriTRKms55gluwKkR0ek8f3yvUU1AwNpwvxHmMONSMQ2xjlwdIub X-Received: by 2002:a17:90a:aa95:: with SMTP id l21mr146568pjq.207.1643058197286; Mon, 24 Jan 2022 13:03:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643058197; cv=none; d=google.com; s=arc-20160816; b=02TTIT+R4TkLWE3nXBDyeHBddhSgYU2E6aOR/J8orpx0Q0E5yBWuJsqmMBx74zVtEt FLh1waHp+T6rnS+cJ68aRt/D7Jifs+SUxzi08cMKmvLx1rto9V0Z4hg4csc9K2M97teK pE7TgF03YRUdmcVPJhDK+tRviUQ+5PIHDtFbQodIiAoKIGO3DI7OLQGkd1NN5p7sB1H1 Y5nEpFgz8pQU5HDDwyIaetJM7Rbt0PzBltvhLefz9h/hLhElmhXTECl/argTvEis0x9Q 2NlenhNtTbnVKAzQ3mI8hwzOsuHG1d6WLKLk1YMfDXKsMIyAVOSfscB+6yirIV9dON4m ThiQ== 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=yP0/JT8Zf6rkegbTWStU/RBl/CwQUodsCOhJHVpy9Xs=; b=vOUQ2RQit41Nl2P6uBMk9l78C9GFzAxUoohkcT+HDMuNILLR/nQbvZl2PZL1FvstYZ Xa5wBEEqYltM2b7zwnSRrFvdtvCwUbsqmb/Mb333APa3+iuU8cSoVLrTf9TisWnH96Uc g7SfE/Lar5g1+YA1KMrKeoGJvPGPnLOdDdskEr8YPwmz/Rn71kb07GEoaxS14bFikILH qs4egO1mPvvOb3VZ17RoWPn5Qs2ZAKVqyX5vah/KyFGaIzGiQQdito4TbunsxMgIFnhj /4a69xr3Z+snQzQHZ7D4ovDM7FMse2cZrF42JxbCh/Be6E82jhOcIbDD70h66HS8MdlO bBbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qm9sQoGN; 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 4si12932199pfh.155.2022.01.24.13.03.03; Mon, 24 Jan 2022 13:03:17 -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=qm9sQoGN; 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 S1382497AbiAXUZt (ORCPT + 99 others); Mon, 24 Jan 2022 15:25:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352283AbiAXUDd (ORCPT ); Mon, 24 Jan 2022 15:03:33 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5B66C02B87E; Mon, 24 Jan 2022 11:29:50 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 52DC16148B; Mon, 24 Jan 2022 19:29:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A3DEC340E5; Mon, 24 Jan 2022 19:29:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643052589; bh=Qyt+cjc79L+3v4LC0sQJwm5VCbZP3ks6OIZ5fJEIcQM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qm9sQoGNAA+qyElgYPwKy8qjLWpbOvdCtssHS7sIticpifSfhMzmwRQy/+bNi5q9m Trrsz1jkpTm/atdi2QP2GRFIdsZkdAry+S1gwWUZLPGY3j//xmdstVolP0SGcXChUo 2LVFKwVT3brQrwNhRKA5fkyKtYWoMKAuLQeSzQ+E= 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.4 110/320] HID: hid-uclogic-params: Invalid parameter check in uclogic_params_huion_init Date: Mon, 24 Jan 2022 19:41:34 +0100 Message-Id: <20220124183957.463099825@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183953.750177707@linuxfoundation.org> References: <20220124183953.750177707@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 ff6b548afe4d9d1ff3a0f6ef79e8cbca25d8f905 ] 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: 1443804 ("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 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/hid/hid-uclogic-params.c b/drivers/hid/hid-uclogic-params.c index 1f3ea6c93ef44..0fdac91c5f510 100644 --- a/drivers/hid/hid-uclogic-params.c +++ b/drivers/hid/hid-uclogic-params.c @@ -707,9 +707,9 @@ static int uclogic_params_huion_init(struct uclogic_params *params, struct hid_device *hdev) { int rc; - struct usb_device *udev = hid_to_usb_dev(hdev); - struct usb_interface *iface = to_usb_interface(hdev->dev.parent); - __u8 bInterfaceNumber = iface->cur_altsetting->desc.bInterfaceNumber; + struct usb_device *udev; + struct usb_interface *iface; + __u8 bInterfaceNumber; bool found; /* The resulting parameters (noop) */ struct uclogic_params p = {0, }; @@ -723,6 +723,10 @@ static int uclogic_params_huion_init(struct uclogic_params *params, goto cleanup; } + udev = hid_to_usb_dev(hdev); + iface = to_usb_interface(hdev->dev.parent); + bInterfaceNumber = iface->cur_altsetting->desc.bInterfaceNumber; + /* If it's not a pen interface */ if (bInterfaceNumber != 0) { /* TODO: Consider marking the interface invalid */ -- 2.34.1