All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Nicholas A. Bellinger" <nab@linux-iscsi.org>
To: linux-scsi <linux-scsi@vger.kernel.org>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>,
	Nicholas Bellinger <nab@linux-iscsi.org>
Subject: [PATCH 08/24] target: Fix memory leaks in target_core_dev_pr_store_attr_res_aptpl_metadata
Date: Sat, 29 Jan 2011 10:36:08 -0800	[thread overview]
Message-ID: <1296326184-16664-9-git-send-email-nab@linux-iscsi.org> (raw)
In-Reply-To: <1296326184-16664-1-git-send-email-nab@linux-iscsi.org>

From: Nicholas Bellinger <nab@linux-iscsi.org>

This patch adds missing kfree()'s for match_strdup() allocations for
Opt_initiator_fabric, Opt_initiator_node, Opt_initiator_sid, Opt_sa_res_key,
Opt_target_fabric, and Opt_target_node for the Persistent Reservations
Activate Persistence across Target Power Loss (APTPL=1) token parsing.

Reported-off-by: Jesper Juhl <jj@chaosbits.net>
Signed-off-by: Nicholas A. Bellinger <nab@linux-iscsi.org>
(cherry picked from commit e26e844313a2cf996f78ba7378cab42078e200a2)
---
 drivers/target/target_core_configfs.c |   33 +++++++++++++++++++++++++++++++--
 1 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c
index 2764510..656c4fa 100644
--- a/drivers/target/target_core_configfs.c
+++ b/drivers/target/target_core_configfs.c
@@ -1452,8 +1452,8 @@ static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata(
 	size_t count)
 {
 	struct se_device *dev;
-	unsigned char *i_fabric, *t_fabric, *i_port = NULL, *t_port = NULL;
-	unsigned char *isid = NULL;
+	unsigned char *i_fabric = NULL, *i_port = NULL, *isid = NULL;
+	unsigned char *t_fabric = NULL, *t_port = NULL;
 	char *orig, *ptr, *arg_p, *opts;
 	substring_t args[MAX_OPT_ARGS];
 	unsigned long long tmp_ll;
@@ -1489,9 +1489,17 @@ static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata(
 		switch (token) {
 		case Opt_initiator_fabric:
 			i_fabric = match_strdup(&args[0]);
+			if (!i_fabric) {
+				ret = -ENOMEM;
+				goto out;
+			}
 			break;
 		case Opt_initiator_node:
 			i_port = match_strdup(&args[0]);
+			if (!i_port) {
+				ret = -ENOMEM;
+				goto out;
+			}
 			if (strlen(i_port) > PR_APTPL_MAX_IPORT_LEN) {
 				printk(KERN_ERR "APTPL metadata initiator_node="
 					" exceeds PR_APTPL_MAX_IPORT_LEN: %d\n",
@@ -1502,6 +1510,10 @@ static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata(
 			break;
 		case Opt_initiator_sid:
 			isid = match_strdup(&args[0]);
+			if (!isid) {
+				ret = -ENOMEM;
+				goto out;
+			}
 			if (strlen(isid) > PR_REG_ISID_LEN) {
 				printk(KERN_ERR "APTPL metadata initiator_isid"
 					"= exceeds PR_REG_ISID_LEN: %d\n",
@@ -1512,6 +1524,10 @@ static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata(
 			break;
 		case Opt_sa_res_key:
 			arg_p = match_strdup(&args[0]);
+			if (!arg_p) {
+				ret = -ENOMEM;
+				goto out;
+			}
 			ret = strict_strtoull(arg_p, 0, &tmp_ll);
 			if (ret < 0) {
 				printk(KERN_ERR "strict_strtoull() failed for"
@@ -1548,9 +1564,17 @@ static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata(
 		 */
 		case Opt_target_fabric:
 			t_fabric = match_strdup(&args[0]);
+			if (!t_fabric) {
+				ret = -ENOMEM;
+				goto out;
+			}
 			break;
 		case Opt_target_node:
 			t_port = match_strdup(&args[0]);
+			if (!t_port) {
+				ret = -ENOMEM;
+				goto out;
+			}
 			if (strlen(t_port) > PR_APTPL_MAX_TPORT_LEN) {
 				printk(KERN_ERR "APTPL metadata target_node="
 					" exceeds PR_APTPL_MAX_TPORT_LEN: %d\n",
@@ -1593,6 +1617,11 @@ static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata(
 			i_port, isid, mapped_lun, t_port, tpgt, target_lun,
 			res_holder, all_tg_pt, type);
 out:
+	kfree(i_fabric);
+	kfree(i_port);
+	kfree(isid);
+	kfree(t_fabric);
+	kfree(t_port);
 	kfree(orig);
 	return (ret == 0) ? count : ret;
 }
-- 
1.7.3.5


  parent reply	other threads:[~2011-01-29 18:36 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-29 18:36 [PATCH 00/24] target updates for .38-rc3 (v2) Nicholas A. Bellinger
2011-01-29 18:36 ` [PATCH 01/24] target: iblock/pscsi claim checking for NULL instead of IS_ERR Nicholas A. Bellinger
2011-01-29 18:36 ` [PATCH 02/24] target: fix dubious one-bit signed bitfield Nicholas A. Bellinger
2011-01-29 18:36 ` [PATCH 03/24] target/iblock: Fix failed bd claim NULL pointer dereference Nicholas A. Bellinger
2011-01-29 18:36 ` [PATCH 04/24] target: Fix memory leak on error path Nicholas A. Bellinger
2011-01-29 18:36 ` [PATCH 05/24] target: Remove unneeded test of se_cmd Nicholas A. Bellinger
2011-01-29 18:36 ` [PATCH 06/24] target/file: Fix memory leak in fd_set_configfs_dev_params() Nicholas A. Bellinger
2011-01-29 18:36 ` [PATCH 07/24] target/iblock: Fix memory leak in iblock_set_configfs_dev_params Nicholas A. Bellinger
2011-01-29 18:36 ` Nicholas A. Bellinger [this message]
2011-01-29 18:36 ` [PATCH 09/24] target: Fix demo-mode MappedLUN shutdown UA/PR breakage Nicholas A. Bellinger
2011-01-29 18:36 ` [PATCH 10/24] target: Release left-over demo-mode NodeACLs w/ tfo->tpg_check_demo_mode_cache()=1 Nicholas A. Bellinger
2011-01-29 18:36 ` [PATCH 11/24] target: tcm_mod_builder.py generated Makefile cleanups Nicholas A. Bellinger
2011-01-29 18:36 ` [PATCH 12/24] target: do not include target_core_mib.h under include/target Nicholas A. Bellinger
2011-01-29 18:36 ` [PATCH 13/24] target: remove EXTRA_CFLAGS Nicholas A. Bellinger
2011-01-29 18:36 ` [PATCH 14/24] target: Call proc_mkdir + remove_proc_entry with NULL parameter Nicholas A. Bellinger
2011-01-29 20:18   ` James Bottomley
2011-01-29 20:43     ` Nicholas A. Bellinger
2011-01-29 18:36 ` [PATCH 15/24] target: Convert backend ->create_virtdevice() call to return ERR_PTR Nicholas A. Bellinger
2011-01-29 18:36 ` [PATCH 16/24] target: Drop nacl->device_list_lock on core_update_device_list_for_node failure Nicholas A. Bellinger
2011-01-29 18:36 ` [PATCH 17/24] target: Remove unnecessary hba_dev_list walk + release from core_delete_hba Nicholas A. Bellinger
2011-01-29 18:36 ` [PATCH 18/24] target: Remove unnecessary se_clear_dev_ports legacy code Nicholas A. Bellinger
2011-01-29 18:36 ` [PATCH 19/24] target: Minor sparse warning fixes and annotations Nicholas A. Bellinger
2011-01-29 18:36 ` [PATCH 20/24] target: Remove spurious double cast from structure macro accessors Nicholas A. Bellinger
2011-01-29 18:36 ` [PATCH 21/24] target: Convert rd_build_device_space() to use errno Nicholas A. Bellinger
2011-01-29 18:36 ` [PATCH 22/24] target: Remove unnecessary container_of() pointer check Nicholas A. Bellinger
2011-01-29 18:36 ` [PATCH 23/24] target: Convert TMR REQ/RSP definitions to target namespace Nicholas A. Bellinger
2011-01-29 18:36 ` [PATCH 24/24] target core v4.0.0-rc7 Nicholas A. Bellinger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1296326184-16664-9-git-send-email-nab@linux-iscsi.org \
    --to=nab@linux-iscsi.org \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=linux-scsi@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.