Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp224615imm; Tue, 12 Jun 2018 22:30:12 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJoRG2XDdhYEQIBOqA8I6sOF6qjPN//jVsKzc4TXb//P9TlU+rxR8jV4EmybQxebMrROK2T X-Received: by 2002:a62:a30e:: with SMTP id s14-v6mr3471370pfe.168.1528867811957; Tue, 12 Jun 2018 22:30:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528867811; cv=none; d=google.com; s=arc-20160816; b=oAWVULm1o9KROvfO6K6xufHHb0UTl97EHFkiA4O+4IzagJnPlVzmrXfhe1r+ms8qx9 OUlmjClmt4u0bHFHgzValUkCcoLgfBsS4vDxubXucSHI+HMX5RdJ1R5VfczBlE/1S+Vx xxb9ddwFbCm5JOeB1vwQ/v/Kk8RwWG69uoCcxhxv4rhWkXmOwM4PbF73RzEbPgpv8ufU uD6xoYY71H9BR1BD4fQuryyqlK/lmcUXBNIPASQhgu+VnXvAs2MO4GOtNXurfMNvwcHr wF7OufICtL35FEU3jGtmW0t2GDMfk/brjwJQkwYTp3DEJfk8XDfnT3JpvlpOtNh+L5YS 8m7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Z0ZVa7535PgcN0wbafRbcO8JROdq98DOOpNzs2CdgjI=; b=gVq3RZu8ubOJQilSE3Z6mBsMBsEc8D0Nqv10yNo+q+JSd9ihgwmUE+iWHZpbucpQJb P3kS37uWzHz9Muu/rOL9D9rX7ktiSJ/wVGr8FcPvSe+UQGK99Mk2IFdWcDsNs6YS8mmw FnRuStgkG1p3EZkw07tMyPZgrsDKz3xyi3rPkBo7lyh5AJm9qq2RXKVWtflnr+oPPkRl qYgqQ5iT9LToDl+64joeaPsev7NaDYus8+7AUlqiLzbfV2oNJJgG1E24RLe3j86Qhr1k L3DlbiLHEP4ZXqfbEN/V/H2KtRIdG4nF4FADcSx/xuhwgWZ3YqRngOFlahz+f7lt0UW3 RgIA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a34-v6si1971316pld.281.2018.06.12.22.29.57; Tue, 12 Jun 2018 22:30:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934322AbeFMF2I (ORCPT + 99 others); Wed, 13 Jun 2018 01:28:08 -0400 Received: from mout.gmx.net ([212.227.17.20]:55117 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934063AbeFMF2G (ORCPT ); Wed, 13 Jun 2018 01:28:06 -0400 Received: from juanniu018037.ss.mogujie.org ([122.225.81.134]) by mail.gmx.com (mrgmx103 [212.227.17.174]) with ESMTPSA (Nemesis) id 0MEo4s-1fRIIV3ptq-00G2aY; Wed, 13 Jun 2018 07:28:02 +0200 From: Chengguang Xu To: nab@linux-iscsi.org Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux-kernel@vger.kernel.org, Chengguang Xu Subject: [RESEND PATCH] target: fix potential memory leak in option parsing Date: Wed, 13 Jun 2018 13:27:26 +0800 Message-Id: <1528867646-138322-1-git-send-email-cgxu519@gmx.com> X-Mailer: git-send-email 1.8.3.1 X-Provags-ID: V03:K1:hhFkXKB5Tn7ZcqvC5gl0clmvEyCmJr4KIRqWlLvbuf0jslWdlpX tvQLhQbbkS3zcws5/9nXaOheD0eyZwg9Un0KCM057qoL8WL++RnOjxsfp9nJeKR//Y6EdY+ 15zQaNth/woB3LqEkJEgoPQ/r7IGjyOAGJyDbDPdKoi4UtUb54zNDSTJBRkRhy1+P0TO3nc u6YN7z4dcjPsR9UgvWC8w== X-UI-Out-Filterresults: notjunk:1;V01:K0:UD3YdJwDfGs=:NgqFWqllkokeCGWlgY+0IH 2ahvL4dwHcAoQGU76vZ6N+30iHSFRTnJedh7PjIci0cA+fARZFd7iakm/igD6CHPYYdA71m1Z AQ/85PHahBjKMBuKwmvsmzVJUbmsiBJb4rJMrLmo3xUrrOyjdcCHIR8C5EZ0fVihs+FP+16BR K+sP8+pz1UsgszMo96jAb4n26rL+SHMZKmN0ajPd7FoKuDuWAFMLSpVkjQkCGO+qlECmrFKe2 DQDkQvluRIyV7qGJkC9bidR/rVukpXjdl0QLdyBTmCW8iVeRUXXgvEJ9wPANN50AFDDS4/RUC DoERAG/qbI1d6OXWPOwfQplrqhmMuRGIwrdPCkHba+J/b7/LvYN16e6ueN7cXeAGegnFblxiU /0+NPTxbfTKw9uYy8n05B4tZrARnWOrIHbhvOqYYzDNl/lEEVHi4pS1XxZTrFlJFvDIBSwMCi 0RGlxJgmfh15DkKuInWr90BWrVcqPWISVuKKslWP1x0/k3+t3WdVyQo4KUS2az9qei5JoFuqI 3RRlmO+dhCWPnDodA5XvLc6Y+Iarty0Q7jeoW14dMEiKhWWYtEnAOjCBFl5W/v+3rey56DjfH GiUGzKhYmBd2BwMaqr/b/otT6JpU581alDf78MmhI3vAFEb3cbeAaDxNfrgqYbPeyJgErelKl HqV3a5EJ7I0TyhLU3Qgmqm6DuusJs4QsYwCDEk8xrBaq3nxQixoqwYY2N0X3sv4y6DSa4EOjN xKYFBFkOv+bPKpwYBdiF5ZrfYx4ZK4UEBoo7cRlt0qRS17BVQ8hWCM849LQ= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 5ccef7d..5512432 100644 --- a/drivers/target/target_core_configfs.c +++ b/drivers/target/target_core_configfs.c @@ -1661,6 +1661,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; @@ -1668,6 +1669,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; @@ -1682,6 +1684,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; @@ -1739,6 +1742,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; @@ -1746,6 +1750,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; -- 1.8.3.1