Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3009335pxb; Mon, 18 Oct 2021 06:31:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJOF66AZvWh5MWs8CO88PzmOOcvr2QEb4Va/01IqFSB5RD/TTvba3RxXjmPFL4dbmvkdYl X-Received: by 2002:a17:90b:4d82:: with SMTP id oj2mr16963158pjb.232.1634563919357; Mon, 18 Oct 2021 06:31:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634563919; cv=none; d=google.com; s=arc-20160816; b=iJz7x5usA2rOF55hRbYzcVZR2KnG3+S7OmYQEtDIh681bnO4HJfclJ2I9txRDBT7r4 se3TQKovcZLM6NFANaSMiH9tsxbj3gMUmPrb5a2pl6CNJbIyudi2MJbsxPJQ6pGANIjf cYcrR/O8PEimN1JK5GhqmvU+RI/WI6oLbKst09WrfwNH2/1Oq2BjVxPQWNFnQ9kY9tmT J9fIh+DC2kuNuYdAlVt+wj2gLSGpDt/I56fv/j+u2iUvcvbssBeO0wwUfw+JcHCPxsRA 955WjXsKF3grCJpKpJ7rvk4kKqaRnrVM8NP2AO1D6a/yknumpvhR4iBM9OIwzT70MbkF /q0Q== 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=yv8PQGyU0JduzivqUB2n3dok3nGt2y6XlVD+WF7J2XI=; b=w6fmHin2Q+sNUGmnQMvTjk5K3aE7nA0wAPcrFLdTH4lbP48SznfmViznlUyvCD7jdW 8IfM84pHjzeK7rawq+HiQLNaGgs+vr9delLodMnHuzfJ4gbc8CrE/WXHZmzAK4MQctYx Pw2UYntR7tv2bYApoVU7cXYSm9aqHng2JfqRHZl5ZJ+RIyBzPPlrr8EbNC18ies26iF0 BPPv7rxQyMSE3p6ZaEZyfF+d+9AtQ0xguDEpLJa9yZM/ickegcsdMiVXZYk2VHYHkT7D oIZth9i8FZgHm3FfPg4CANs0bh/B1ieCqeYUgry7gf3JV0RpymRypW60rOWvIAw93Z/2 aNyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TtVfL3ha; 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 ge11si619285pjb.159.2021.10.18.06.31.46; Mon, 18 Oct 2021 06:31:59 -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=TtVfL3ha; 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 S232880AbhJRNdA (ORCPT + 99 others); Mon, 18 Oct 2021 09:33:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:42144 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231814AbhJRNbD (ORCPT ); Mon, 18 Oct 2021 09:31:03 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7AB336135A; Mon, 18 Oct 2021 13:28:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634563722; bh=BwV6JUfUV0XNuNYtl6MUBSVDD3+tMVqifVU/2j3WBRs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TtVfL3haXNlelFqR/HwgZ3g/kPQnhtZ4bERr3JQsa8FhAeP3o1NtfpXHw0Kd8gv33 HIzmG8DxLiiIHI4lRY1U1BYjzFGLGHlSyoUBDLQKk7y6UnwBYptsqLeQQ4OhNHGEn6 1vsJrAUNnEJMHMedJjIht+aXyOvD1Jo6blt/TxbQ= 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 4.19 39/50] NFC: digital: fix possible memory leak in digital_tg_listen_mdaa() Date: Mon, 18 Oct 2021 15:24:46 +0200 Message-Id: <20211018132327.816386184@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211018132326.529486647@linuxfoundation.org> References: <20211018132326.529486647@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 @@ -286,6 +286,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) @@ -300,8 +301,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)