From patchwork Tue Apr 17 03:28:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengguang Xu X-Patchwork-Id: 10344267 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7C57160542 for ; Tue, 17 Apr 2018 03:29:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6426A28745 for ; Tue, 17 Apr 2018 03:29:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 58DCA287BF; Tue, 17 Apr 2018 03:29:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE3D828745 for ; Tue, 17 Apr 2018 03:29:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751840AbeDQD3B (ORCPT ); Mon, 16 Apr 2018 23:29:01 -0400 Received: from mout.gmx.net ([212.227.17.22]:37265 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751793AbeDQD3A (ORCPT ); Mon, 16 Apr 2018 23:29:00 -0400 Received: from localhost.localdomain ([122.225.81.134]) by mail.gmx.com (mrgmx102 [212.227.17.174]) with ESMTPSA (Nemesis) id 0LoKHN-1eWkYC05Mn-00gK2N; Tue, 17 Apr 2018 05:28:57 +0200 From: Chengguang Xu To: nab@linux-iscsi.org Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, Chengguang Xu Subject: [PATCH] target: fix potential memory leak in option parsing Date: Tue, 17 Apr 2018 11:28:44 +0800 Message-Id: <1523935724-6991-1-git-send-email-cgxu519@gmx.com> X-Mailer: git-send-email 1.8.3.1 X-Provags-ID: V03:K1:95cvDIgtwhqFR2eJgaiXslar/xgN7KoQbuZ/ajhJxbWoSMFGuue 5iGtGqJZwJtmQvCfMswri0dn/wBU7kbxXtFd3GpxGV8Txwyq9ZlpAAVR2O0QdnBH7hRnoTi R8VH6ENaFexuiMU9x+K23cmQgunTdwE6eGP2pTE1jNcMZB8+TSa+9hpXmEg5KFCkhK7hl4k SeXKkGLKOf/F+ekETea8A== X-UI-Out-Filterresults: notjunk:1; V01:K0:HHzjHfpqDJ0=:02vPKayakww5slgQL7otyv AD2P0zApSqz0/AI5Okxszns+o22Iwr7CzRQvUWuDmSJgOdIKHNo2vC47rY9VNPGm5YPZiJCVL gzprAMLQyvAaqULvRZOGZ3bWpYZdLUe5hfJrcLkveLgk8gP5279BFAjsxReNciT7q7+VFoD3U t2ZnYxPE6jP+ZyXijvlpfahVQXlqnMseTVbMbwjBNYVTZD/mqmadmnQLuSlSeLGHNlQWrPKnL X1MQr1Lp+a0bLyQwKS3Nn33Q0UnS2baMRDGSM9lbpXCq52oeQ4mTTFfaT+oncQlhBvSt924AA b75q1SHQLPSEZo8OrbejK0MF2Q1XuDKiAjDW96YPXCKeb+KcxDFq8t/FMWxn6bU0YRHHXKRBL B6vxH20j/p2+5u6u6T4l15S+eN1/0o0cLRvUjgE7yECTa6x/OUkOWdKGk6ALiqq1gG4UQpNfF ShKLRF4NjUMy1yJjLMgVcDCsxuqqWMWvUtqsn/4pEHpTnzD2cUMUT323pPeUOuBdNPLnuJ9VV o6Qe5+2fasbDasQkQ43CKm2N0ekwxo/YVUPDvkZZOVwkVkfzW+GQR4spUxaVJsxbsUVUAzVKq zdya4iBPHcp2LDmSOJdCVJkTvcW9wrg+XzgpbeMg4OY/pig4GNS8j/5xchg06DckAJ4RoJ5ty 0RyPaUvkomEXr8sdFt8rj96AdZ7SlmD2LCubxgfZ54z/BZQRuwhEF+Q4WKVIGnuANGHtP6DuK 7Q1bx2VDCzNJbO061Yiyoj6Pb/C6hZE4VIllKfprsXnJaA6sfplnKjd3yerccTeCp9N3z082W 552dkfMe7y/9RgbZDhvef0Au+oLOQ== Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When specifying same string type option several times, current option parsing will cause memory leak. Hence, call kfree for previous one in this case. Signed-off-by: Chengguang Xu --- drivers/target/target_core_configfs.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c index 3f4bf12..ee1a3a8 100644 --- a/drivers/target/target_core_configfs.c +++ b/drivers/target/target_core_configfs.c @@ -1659,6 +1659,7 @@ static ssize_t target_pr_res_aptpl_metadata_store(struct config_item *item, token = match_token(ptr, tokens, args); switch (token) { case Opt_initiator_fabric: + kfree(i_fabric); i_fabric = match_strdup(args); if (!i_fabric) { ret = -ENOMEM; @@ -1666,6 +1667,7 @@ static ssize_t target_pr_res_aptpl_metadata_store(struct config_item *item, } break; case Opt_initiator_node: + kfree(i_port); i_port = match_strdup(args); if (!i_port) { ret = -ENOMEM; @@ -1680,6 +1682,7 @@ static ssize_t target_pr_res_aptpl_metadata_store(struct config_item *item, } break; case Opt_initiator_sid: + kfree(isid); isid = match_strdup(args); if (!isid) { ret = -ENOMEM; @@ -1737,6 +1740,7 @@ static ssize_t target_pr_res_aptpl_metadata_store(struct config_item *item, * PR APTPL Metadata for Target Port */ case Opt_target_fabric: + kfree(t_fabric); t_fabric = match_strdup(args); if (!t_fabric) { ret = -ENOMEM; @@ -1744,6 +1748,7 @@ static ssize_t target_pr_res_aptpl_metadata_store(struct config_item *item, } break; case Opt_target_node: + kfree(t_port); t_port = match_strdup(args); if (!t_port) { ret = -ENOMEM;