Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3206401pxb; Wed, 13 Oct 2021 00:53:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwK3/j40aavkCailWHOZORlMSsjjbnhZJC7KEiK/gqTsdr5GUSd6zxrfN8DcjCApgrbJDfw X-Received: by 2002:aa7:c38b:: with SMTP id k11mr7397661edq.79.1634111618822; Wed, 13 Oct 2021 00:53:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634111618; cv=none; d=google.com; s=arc-20160816; b=jfBZz4mVRW5zdm7KqWGhk9mK+SJFtZAPeZu00VFi+FgCp2FYg15xE3t1nj5tyKctNW /bJoo69C0u+ArBTyQuhxDrTJHJmnHVali0yVlp+PDkIrus+hIUB6ki4Au4Y0H3R6Inzv FBB6VjOYRC83HDW9hYB2ArMERs7C/Wf/sKKrHd4ybdJIhGH/HWiPYnObGT+JxVOl24Mq qwnQHORAQPaMwKSzXeCqz5i5O6qGaBnnEo43WE4TR2KVhGBPqS2du6O+T2K1e+Lj3P6O nx00g7iIySrDwveomozXSJ2NpGxhtdK73WNVfuilx0vN6x0avORcWWQieokPDFzr55ak FaDg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=J6lx/Re43GbNeV926WrsjQ3Nwd4IckT5IMF/ohPdHTM=; b=RrTF9cHUIM1BixrhCgq5bxEAUoW6qQXdT7LFrAmE5/KwkQqCxKfnm7glhr+qG1HSeB UJuEejSlC8Ghs6lF0GS3ICZQuR3ZThUjBE8cB0OPtTwwRmaNcisBaPTv/kuSQnsemeY4 AkMznafk9CHXnXYFXHh+3t4AZyPkj1P2AgjEnMD6INS5U4Tfbo1tw/wR9uRHdQDNRHZ3 3tCh6sR7qEQGsBU3RWFZHA20+FyEqwHBOhGR7dMuzI89CzFkTtvySoKShPzxQzyqI15J OmelI84/yok4A+Qts1vNLU9Hlu/QWs/NRJO3kYK6emwnexMr6KUgOav0DXV+rraJ3Yp2 J9ZA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bq14si17574104edb.57.2021.10.13.00.53.15; Wed, 13 Oct 2021 00:53:38 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238722AbhJMHxS (ORCPT + 99 others); Wed, 13 Oct 2021 03:53:18 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:14342 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238696AbhJMHxP (ORCPT ); Wed, 13 Oct 2021 03:53:15 -0400 Received: from dggeml757-chm.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4HTl305nnJz90DD; Wed, 13 Oct 2021 15:46:20 +0800 (CST) Received: from localhost.localdomain (10.175.104.82) by dggeml757-chm.china.huawei.com (10.1.199.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.8; Wed, 13 Oct 2021 15:51:10 +0800 From: Ziyang Xuan To: CC: , , , Subject: [PATCH net 1/2] NFC: digital: fix possible memory leak in digital_tg_listen_mdaa() Date: Wed, 13 Oct 2021 15:50:12 +0800 Message-ID: <4e3578352a4548feb1d3087c7ec38fedab18292d.1634111083.git.william.xuanziyang@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.104.82] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggeml757-chm.china.huawei.com (10.1.199.137) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org '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 --- net/nfc/digital_core.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/net/nfc/digital_core.c b/net/nfc/digital_core.c index fefc03674f4f..d63d2e5dc60c 100644 --- a/net/nfc/digital_core.c +++ b/net/nfc/digital_core.c @@ -277,6 +277,7 @@ int digital_tg_configure_hw(struct nfc_digital_dev *ddev, int type, int param) 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 nfc_digital_dev *ddev, u8 rf_tech) 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) -- 2.25.1