Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3701250pxb; Mon, 24 Jan 2022 15:46:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJzb1U8OY0OJ9HRg7WvfmiCo+YpZ3fADfBXlmLht16p/aAFKmJL4J+sQnWK9uspAmbpxlrqC X-Received: by 2002:a05:6a00:1a4f:b0:4c9:e7b7:d84b with SMTP id h15-20020a056a001a4f00b004c9e7b7d84bmr4712787pfv.61.1643067979593; Mon, 24 Jan 2022 15:46:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643067979; cv=none; d=google.com; s=arc-20160816; b=x6CpcgtGgSbNSFbKI6lYYdMwTFdW9u+Rp7MRoA5qJ4znt7Gv9fFpU5adOFbmd/aDhX U9+cem4kzKoO/HFkyoJvvtPdcR/5kIb9fIWUg091Eejbkt13IxR5pfCG+v6EEplIi8Vn PiphfoqKZkdATkgZbZODzKXIPDGRpx4Q7V6bCIr/U6KtnTdZ0zSf01mGeSqnGiDjp7mG lHwT1UHBXn4pcqjVzN32//RcnaIK+D9E+1xoz+yRjSTlPJG3KPSQDCAlfe+Tq2cDLLet X5FCJPBpHXOQX0U/irth5zVZw6Y3M/JK4SLUP8jo0pg6xlpUt/m8pqDsGj9Pcg9bt0oi ibww== 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=5IlhQR8M1FIWjQPIiky66WCaBizJcZ+zGFuuNccAwxk=; b=KKL/9ZpPdOGTM5Jco0PNk0g+q5A8KVyLaLCH/BpGOS2F/KdVPKSZVdch+VdoPzkWMy RSFLVCA8MreSusS/1qV5ui5fW+bMpdJHMXyd71kmVT/dlsDek52nPcXCzqQfwFMrA0iY 0tPU2Rm4XvCqjR1nCzA/YwqJLzWQBD+tcs8hQAOcJ5sl51sBeJOx+DEoercFopw+R/dD CutIXpjnBUHniQPOGws4sNEXZ2Ovk2kAD9119yzKIr4DD7vOIdSdns35tZgYzTkLpG7j up0AGsSDuv4lyN28u07abDIgdbcO3ozb3IsqbFM1Te5eLCjztZ625dHARvf8mePXbwVU fPGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=w+NG9JvN; 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 o3si5900867plg.446.2022.01.24.15.46.04; Mon, 24 Jan 2022 15:46:19 -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=w+NG9JvN; 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 S2361201AbiAXXjV (ORCPT + 99 others); Mon, 24 Jan 2022 18:39:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1841214AbiAXW6B (ORCPT ); Mon, 24 Jan 2022 17:58:01 -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 1AC2EC08E87F; Mon, 24 Jan 2022 13:12:47 -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 AB80D611C8; Mon, 24 Jan 2022 21:12:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 909BCC340E5; Mon, 24 Jan 2022 21:12:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643058766; bh=VCWqXz36B9QGd4a08A2VpVo1EMBQYp8qx7VMIPbcbn0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=w+NG9JvNkMbYWrgLL+FCYvl21ia8IT7fqfGZewyFwxd4WgqtsCs1v5gr2cbcgq1nY HUGiEBXJscXeRsWvbkrEI5Qw/bjGYCnOqQXPFoz4b+Dtq4ajXMr098Kf4J+aySW/Vi LnOgYfEtSEOXqB6a5+L5xCOiiR4WhyV4rP5DfQH0= 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 0395/1039] HID: hid-uclogic-params: Invalid parameter check in uclogic_params_get_str_desc Date: Mon, 24 Jan 2022 19:36:24 +0100 Message-Id: <20220124184138.598227098@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 0a94131d6920916ccb6a357037c535533af08819 ] The function performs a check on the hdev input parameters, however, it is used before the check. Initialize the udev variable after the sanity check to avoid a possible NULL pointer dereference. Fixes: 9614219e9310e ("HID: uclogic: Extract tablet parameter discovery into a module") Addresses-Coverity-ID: 1443827 ("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 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/hid/hid-uclogic-params.c b/drivers/hid/hid-uclogic-params.c index 3c10b858cf74c..3a83e2c39b4fb 100644 --- a/drivers/hid/hid-uclogic-params.c +++ b/drivers/hid/hid-uclogic-params.c @@ -66,7 +66,7 @@ static int uclogic_params_get_str_desc(__u8 **pbuf, struct hid_device *hdev, __u8 idx, size_t len) { int rc; - struct usb_device *udev = hid_to_usb_dev(hdev); + struct usb_device *udev; __u8 *buf = NULL; /* Check arguments */ @@ -75,6 +75,8 @@ static int uclogic_params_get_str_desc(__u8 **pbuf, struct hid_device *hdev, goto cleanup; } + udev = hid_to_usb_dev(hdev); + buf = kmalloc(len, GFP_KERNEL); if (buf == NULL) { rc = -ENOMEM; -- 2.34.1