Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3016195pxb; Mon, 18 Oct 2021 06:40:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZMWtzUb2pk5C/y4gj8F9NaAWPoK/VKz2LPb8HA/83P13VqoeHFWs6HJh9Hzqozy/gL7wp X-Received: by 2002:a63:35c6:: with SMTP id c189mr16787257pga.22.1634564399900; Mon, 18 Oct 2021 06:39:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634564399; cv=none; d=google.com; s=arc-20160816; b=h5CKwYsKC0t9LATrJ7caZS9CicX8sw8pXfI2kisJ+g4TvA6OnNslMNtfUMqkgAR8cb 2avLpvTlc7KfJU/XCxQCtBoFp8SiliPi/nw246F+rlQdz/YlBCQ8ehp50C/wd7mSsX86 LHWQc3+u9LBtdfxWo4sCgQ0cAeOEIGueN1q5gwMwEBP2ewJUmdtX5uZxHzYxl9pO1OEq P4nuut0QMzRZT909obwDoHlG9vNwpICjh13L8jQT9Rulv0bcuC66bpv1vTZ8NTuCMVhv 0S+ltRdoCzTaF+WILOG902ymGG3h6ReYR6YKGi8Ce6MsynUa4lvn5vGfED1QKXRywaTJ wAPw== 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=OC8lB7hpwXPSC7oZ33bsm1EIfWV+2jO0Uju46d7m+HtAgQ7m1dWKPA+J3wYOAYG/Lh 3LXRfAqrJkmMIwTZxUs5S6O6CR964B6twyksspOMdG5T9PPW2qywtqiPzcWxbmoWj80S 7+Sqs6UES/Mx5UeU0m/bAmeYoSiOlIhfzrURVqaMwawZ4RZb+iUDLLinz9s9Egvh12BQ yiNDSdW48ycYJOYibKqje+BpSMFDcWd6OV3WxoavpnI1zIyZBs0QmeUBNJt4lovSI7A1 nURpQPa5QCa9u8RwBAR3BSuVKoqFiQJqPdtExfLKS44yQRkwjstM+6CWOy+Oq0bkLcy3 BR6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wB8+zHR3; 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 n15si16891215plc.80.2021.10.18.06.39.46; Mon, 18 Oct 2021 06:39: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=wB8+zHR3; 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 S233631AbhJRNkt (ORCPT + 99 others); Mon, 18 Oct 2021 09:40:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:56376 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233677AbhJRNih (ORCPT ); Mon, 18 Oct 2021 09:38:37 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E61F661212; Mon, 18 Oct 2021 13:32:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634563935; bh=F6/j8CSR2cmasNkSLypwl3nDj6yUpxbHCMsipKhXnyU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wB8+zHR3EoAiMaDczb7HxFldrCw66cMmGh6bPvsP8dkMiAzPftDNyvnV8b7/5rRbi eACK5RN/jrfHZRJtYtuEEn73898yDeM0Ezty2xBHaRJ5Gm5GwC/qwf8+XJt50xCvVg acDenDJg+s4evVPHoy7xHltEUvtXmNDC5cbR96/g= 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.4 54/69] NFC: digital: fix possible memory leak in digital_tg_listen_mdaa() Date: Mon, 18 Oct 2021 15:24:52 +0200 Message-Id: <20211018132331.272978635@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211018132329.453964125@linuxfoundation.org> References: <20211018132329.453964125@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)