Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3631255pxb; Mon, 24 Jan 2022 13:59:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJziJyhQhM5upkizpCtOxBmrihup0Dm8KDTxc7+q5uocMxw/tA0WMRYYmdlj72vzOz0O5uL6 X-Received: by 2002:a05:6a00:24d6:b0:4ca:c762:71b9 with SMTP id d22-20020a056a0024d600b004cac76271b9mr139107pfv.40.1643061543939; Mon, 24 Jan 2022 13:59:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643061543; cv=none; d=google.com; s=arc-20160816; b=tdTeBhJ6J2g4rxyzgGTg+vNEdQY9mp3BT8kY6CaNnBVTRgEaHZbWwtbnepKBUnRKDP SxAEzJZPxN3R7A7KwOmIER8xw7epdiq5Xe57JHXeRg1KgsP1RaAlKm1EdkWOW7on0FZL JVU8TGR9aDeKfYCRsQiiV5royMUCz2sZ3iAbetCd1F7KvrbjU9JEkMkxHw4M9VjsGrXW uzj+TfESn9TUscZE6N3gl/zv7/D8lYbUJmzA+BHT3NpWBxCM1kPL8QPUngGkPgHI8rAv h1lZHexvVZopi/sD9+N6O0L5j9YWRsoNO4bzoUPLoAlIwYi/V699zRDE0yqhM6RpcNG1 4rOA== 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=pH5Rlt9hqwn6Wl2EDsrJ8TcaNhtPaLvL6Yv+mQvvgfI=; b=kzESUa1pfpUFJb5WfiPhfr+5tougsFJVAW9pDdUsOgwOSYoLpPbAcyH/FpDSFM9rk7 xJPDoraeJ/T93vACkhKFW2V51OpD0kJV2hZ8iNZeS1lt/eu/an3aOqwwL//q+7odPQAs 5cNNrah5qIH5fd/0/pea/zW+S+sEodL7EKUBXDgcbkqP0BmC96cZ47Zex3ZpVueKktri yoKTs+d/3e/DMJibvXUpzxevnQ8kdejNJthB4IrKCih9Pee+G8fq7/QnahJjIzHrAJYt z1diewym47aM88/KVprTGXLdwFV/s+tzRPH/zczCGBu/HOMkLzXNjOWSBoQHmS06M77G kIIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KTuvbW9a; 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 d17si14573611pgj.369.2022.01.24.13.58.48; Mon, 24 Jan 2022 13:59:03 -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=KTuvbW9a; 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 S1574182AbiAXVsA (ORCPT + 99 others); Mon, 24 Jan 2022 16:48:00 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:35772 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377730AbiAXVMv (ORCPT ); Mon, 24 Jan 2022 16:12:51 -0500 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 9ED32611C8; Mon, 24 Jan 2022 21:12:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E8F0C340E5; Mon, 24 Jan 2022 21:12:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643058769; bh=7n7G5SKrA1dBR0fD9xutzkUVLmfgbdkxbUUx2QGunBg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KTuvbW9aY2GG7ms8oLJg8na2L5YSTXdKmjnWYoRiMo3rtQf0HKBXJJuyUHv6RzzhS OILEv9kEGIhfZv2nge3KbdH7JIlvIf3F+/GT6mLcA097teTz3x1lltEyVUPkCtO9ow yLzvihesLzJ1gs/mnoaf+AmhAFhlQDsJBrEX8fqQ= 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 0396/1039] HID: hid-uclogic-params: Invalid parameter check in uclogic_params_huion_init Date: Mon, 24 Jan 2022 19:36:25 +0100 Message-Id: <20220124184138.631040334@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 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 3a83e2c39b4fb..4136837e4d158 100644 --- a/drivers/hid/hid-uclogic-params.c +++ b/drivers/hid/hid-uclogic-params.c @@ -709,9 +709,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, }; @@ -725,6 +725,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