target-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RESEND PATCH] target: fix potential memory leak in option parsing
@ 2018-06-13  5:27 Chengguang Xu
  2018-06-13 16:10 ` Mike Christie
  0 siblings, 1 reply; 2+ messages in thread
From: Chengguang Xu @ 2018-06-13  5:27 UTC (permalink / raw)
  To: nab; +Cc: linux-scsi, target-devel, linux-kernel, Chengguang Xu

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 <cgxu519@gmx.com>
---
 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [RESEND PATCH] target: fix potential memory leak in option parsing
  2018-06-13  5:27 [RESEND PATCH] target: fix potential memory leak in option parsing Chengguang Xu
@ 2018-06-13 16:10 ` Mike Christie
  0 siblings, 0 replies; 2+ messages in thread
From: Mike Christie @ 2018-06-13 16:10 UTC (permalink / raw)
  To: Chengguang Xu, nab; +Cc: linux-scsi, target-devel, linux-kernel

On 06/13/2018 12:27 AM, Chengguang Xu wrote:
> 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 <cgxu519@gmx.com>
> ---
>  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);

You can probably just change this one and t_fabric so we do not even do
a match_strdup since they are not used. Just let them hit the default in
the switch so if apps are still passing them in then we maintain the
same behavior from their perspective.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-06-13 16:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-13  5:27 [RESEND PATCH] target: fix potential memory leak in option parsing Chengguang Xu
2018-06-13 16:10 ` Mike Christie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).