Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3036057pxb; Mon, 18 Oct 2021 07:03:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7+zr2EWyydNUE5FBNHtb+GpQWfiERqN4nMlwk/PysV02sjN2aCKAHpBdxY5X3evjLwLqj X-Received: by 2002:a63:5902:: with SMTP id n2mr24013217pgb.305.1634565820408; Mon, 18 Oct 2021 07:03:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634565820; cv=none; d=google.com; s=arc-20160816; b=bBO5vA3jtq8WXyqOKvTtv8181zBr3GYAcDoptT1apyJ35op0h6VYVdip4PuByINWKu 1lCHQRLvPwd4TJoCrhidNUNV2CEIx5SNnZXAZ+OrfLjdmaffLs1+sI131MDIixL4Avde B7GRdeNv7pcH7QsRzGM6YVoR+v09i1H3G26QEObJhN5/nahicz8jMwTePJ6mkt49Ijne eyw+K/TGuZun6BeJdDVEthrxAj4yGHCnbs+kOZmUa27oRUw593ID4nTpe3CDJTFrfDm8 0wziZPm6jRXLH7bz9h0jTvn+oga5HbvDkfuu3PlKAawnqtcGEoCTDMHVZ90JLepLb+Ix MQ6w== 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=29ORYWxsJV0qeX/GPyYIqt57Gao7OeoN4j6pJPaXww4=; b=Jdu0cCFCPcug7jbeMODrdSwuqDH1Pj6hz9cgqpaGnW1rZYdNkQ405nfgfLYWNRFYVT huP91F/09kO5krBZCuaAnVVppQxSv9bg3kG5Y+ky/0mA2F8jq+oiaGmgmAtLvnryU8w+ UtoVSfUSxm+rqUQ9FAzaQo38K4x9Ntfu+u4MFt8sjvF1gTDKaeqI9Gey+MZzdq3zDc0J FmrWNoZx20Jk3TK8UEDKclE4oLqDWt7bR6JSLIQW6aF7guO6Wu31D7AORsGJiURp3tlN mYNcGrSQ7aPuHjDSkJLu87074XHtUyAFs1wUoxlbqBSZYsAlgVgMYtE07TaN16WSTB+z oNhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Hh9BBjM8; 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 l4si1144916pls.88.2021.10.18.07.03.27; Mon, 18 Oct 2021 07:03:40 -0700 (PDT) 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=Hh9BBjM8; 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 S233149AbhJROB2 (ORCPT + 99 others); Mon, 18 Oct 2021 10:01:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:39834 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233993AbhJRN7X (ORCPT ); Mon, 18 Oct 2021 09:59:23 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1872761A3D; Mon, 18 Oct 2021 13:41:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634564507; bh=F6/j8CSR2cmasNkSLypwl3nDj6yUpxbHCMsipKhXnyU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hh9BBjM8MWs1nm8iwhqj0pEUVfbWEViZKmPD5tFZk4A/QArO2kSZH+oDYla5elvB/ d8A4hmb/BXomkQgElfZ3oto4n9UYvQLQ3H97faP637BVdv1dbaC8NviQEnMkFnrEqN YbmPv6mABnWmXpcba9CnWCqpl0sCCjtW6HyFZrLg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ziyang Xuan , Krzysztof Kozlowski , Jakub Kicinski Subject: [PATCH 5.14 116/151] NFC: digital: fix possible memory leak in digital_tg_listen_mdaa() Date: Mon, 18 Oct 2021 15:24:55 +0200 Message-Id: <20211018132344.445992371@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211018132340.682786018@linuxfoundation.org> References: <20211018132340.682786018@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: Ziyang Xuan commit 58e7dcc9ca29c14e44267a4d0ea61e3229124907 upstream. 'params' is allocated in digital_tg_listen_mdaa(), but not free when digital_send_cmd() failed, which will cause memory leak. Fix it by freeing 'params' if digital_send_cmd() return failed. Fixes: 1c7a4c24fbfd ("NFC Digital: Add target NFC-DEP support") Signed-off-by: Ziyang Xuan Reviewed-by: Krzysztof Kozlowski Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/nfc/digital_core.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) --- a/net/nfc/digital_core.c +++ b/net/nfc/digital_core.c @@ -277,6 +277,7 @@ int digital_tg_configure_hw(struct nfc_d static int digital_tg_listen_mdaa(struct nfc_digital_dev *ddev, u8 rf_tech) { struct digital_tg_mdaa_params *params; + int rc; params = kzalloc(sizeof(*params), GFP_KERNEL); if (!params) @@ -291,8 +292,12 @@ static int digital_tg_listen_mdaa(struct get_random_bytes(params->nfcid2 + 2, NFC_NFCID2_MAXSIZE - 2); params->sc = DIGITAL_SENSF_FELICA_SC; - return digital_send_cmd(ddev, DIGITAL_CMD_TG_LISTEN_MDAA, NULL, params, - 500, digital_tg_recv_atr_req, NULL); + rc = digital_send_cmd(ddev, DIGITAL_CMD_TG_LISTEN_MDAA, NULL, params, + 500, digital_tg_recv_atr_req, NULL); + if (rc) + kfree(params); + + return rc; } static int digital_tg_listen_md(struct nfc_digital_dev *ddev, u8 rf_tech)