Skip to contentSkip to conversation

b2iscsi: Fix memory leak in mgmt_set_ip()

PATCH In review Maurizio Lombardi 3 participants 6 messages Jun 27, 2014 – Jul 7, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 b2iscsi: Fix memory leak in mgmt_set_ip()

The if_info pointer is not released by the mgmt_set_ip() function

---
 drivers/scsi/be2iscsi/be_mgmt.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
drivers/scsi/be2iscsi/be_mgmt.c +11 -9
index 07934b0..a3e5648 100644
@@ -1015,7 +1015,7 @@ int mgmt_set_ip(struct beiscsi_hba *phba,
 		if (if_info->dhcp_state) {
 			beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
 				    "BG_%d : DHCP Already Enabled\n");
-			return 0;
+			goto exit;
 		}
 		/* The ip_param->len is 1 in DHCP case. Setting
 		   proper IP len as this it is used while
@@ -1033,7 +1033,7 @@ int mgmt_set_ip(struct beiscsi_hba *phba,
 				sizeof(*reldhcp));
 
 			if (rc)
-				return rc;
+				goto exit;
 
 			reldhcp = nonemb_cmd.va;
 			reldhcp->interface_hndl = phba->interface_handle;
@@ -1044,7 +1044,7 @@ int mgmt_set_ip(struct beiscsi_hba *phba,
 				beiscsi_log(phba, KERN_WARNING,
 					    BEISCSI_LOG_CONFIG,
 					    "BG_%d : Failed to Delete existing dhcp\n");
-				return rc;
+				goto exit;
 			}
 		}
 	}
@@ -1054,7 +1054,7 @@ int mgmt_set_ip(struct beiscsi_hba *phba,
 		rc = mgmt_static_ip_modify(phba, if_info, ip_param, NULL,
 					   IP_ACTION_DEL);
 		if (rc)
-			return rc;
+			goto exit;
 	}
 
 	/* Delete the Gateway settings if mode change is to DHCP */
@@ -1064,7 +1064,7 @@ int mgmt_set_ip(struct beiscsi_hba *phba,
 		if (rc) {
 			beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
 				    "BG_%d : Failed to Get Gateway Addr\n");
-			return rc;
+			goto exit;
 		}
 
 		if (gtway_addr_set.ip_addr.addr[0]) {
@@ -1076,7 +1076,7 @@ int mgmt_set_ip(struct beiscsi_hba *phba,
 				beiscsi_log(phba, KERN_WARNING,
 					    BEISCSI_LOG_CONFIG,
 					    "BG_%d : Failed to clear Gateway Addr Set\n");
-				return rc;
+				goto exit;
 			}
 		}
 	}
@@ -1087,7 +1087,7 @@ int mgmt_set_ip(struct beiscsi_hba *phba,
 			OPCODE_COMMON_ISCSI_NTWK_CONFIG_STATELESS_IP_ADDR,
 			sizeof(*dhcpreq));
 		if (rc)
-			return rc;
+			goto exit;
 
 		dhcpreq = nonemb_cmd.va;
 		dhcpreq->flags = BLOCKING;
@@ -1095,12 +1095,14 @@ int mgmt_set_ip(struct beiscsi_hba *phba,
 		dhcpreq->interface_hndl = phba->interface_handle;
 		dhcpreq->ip_type = BE2_DHCP_V4;
 
-		return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
+		rc = mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
 	} else {
-		return mgmt_static_ip_modify(phba, if_info, ip_param,
+		rc = mgmt_static_ip_modify(phba, if_info, ip_param,
 					     subnet_param, IP_ACTION_ADD);
 	}
 
+exit:
+	kfree(if_info);
 	return rc;
 }
 
Signature · 1 line
Maurizio Lombardi
#1 lore raw
Quoted 12 lines · Maurizio Lombardi

The if_info pointer is not released by the mgmt_set_ip() function

---
 drivers/scsi/be2iscsi/be_mgmt.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
drivers/scsi/be2iscsi/be_mgmt.c +0 -0
index 07934b0..a3e5648 100644

drivers/scsi/be2iscsi/be_mgmt.c int mgmt_set_ip(struct beiscsi_hba *phba, · line 1018

Quoted 5 lines
drivers/scsi/be2iscsi/be_mgmt.c +1 -1
@@ -1015,7 +1015,7 @@ int mgmt_set_ip(struct beiscsi_hba *phba,
 		if (if_info->dhcp_state) {
 			beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
 				    "BG_%d : DHCP Already Enabled\n");
-			return 0;
+			goto exit;

rc should be initialised - so this needs to be added to your patch Cheers, Tomas
@@ -955,7 +955,7 @@ int mgmt_set_ip(struct beiscsi_hba *phba,
struct be_dma_mem nonemb_cmd;
uint8_t *gtway_addr;
uint32_t ip_type;
- int rc;
+ int rc = 0;

if (mgmt_get_all_if_id(phba))
return -EIO;

Quoted 74 lines
drivers/scsi/be2iscsi/be_mgmt.c +10 -8
 		}
 		/* The ip_param->len is 1 in DHCP case. Setting
 		   proper IP len as this it is used while
@@ -1033,7 +1033,7 @@ int mgmt_set_ip(struct beiscsi_hba *phba,
 				sizeof(*reldhcp));
 
 			if (rc)
-				return rc;
+				goto exit;
 
 			reldhcp = nonemb_cmd.va;
 			reldhcp->interface_hndl = phba->interface_handle;
@@ -1044,7 +1044,7 @@ int mgmt_set_ip(struct beiscsi_hba *phba,
 				beiscsi_log(phba, KERN_WARNING,
 					    BEISCSI_LOG_CONFIG,
 					    "BG_%d : Failed to Delete existing dhcp\n");
-				return rc;
+				goto exit;
 			}
 		}
 	}
@@ -1054,7 +1054,7 @@ int mgmt_set_ip(struct beiscsi_hba *phba,
 		rc = mgmt_static_ip_modify(phba, if_info, ip_param, NULL,
 					   IP_ACTION_DEL);
 		if (rc)
-			return rc;
+			goto exit;
 	}
 
 	/* Delete the Gateway settings if mode change is to DHCP */
@@ -1064,7 +1064,7 @@ int mgmt_set_ip(struct beiscsi_hba *phba,
 		if (rc) {
 			beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
 				    "BG_%d : Failed to Get Gateway Addr\n");
-			return rc;
+			goto exit;
 		}
 
 		if (gtway_addr_set.ip_addr.addr[0]) {
@@ -1076,7 +1076,7 @@ int mgmt_set_ip(struct beiscsi_hba *phba,
 				beiscsi_log(phba, KERN_WARNING,
 					    BEISCSI_LOG_CONFIG,
 					    "BG_%d : Failed to clear Gateway Addr Set\n");
-				return rc;
+				goto exit;
 			}
 		}
 	}
@@ -1087,7 +1087,7 @@ int mgmt_set_ip(struct beiscsi_hba *phba,
 			OPCODE_COMMON_ISCSI_NTWK_CONFIG_STATELESS_IP_ADDR,
 			sizeof(*dhcpreq));
 		if (rc)
-			return rc;
+			goto exit;
 
 		dhcpreq = nonemb_cmd.va;
 		dhcpreq->flags = BLOCKING;
@@ -1095,12 +1095,14 @@ int mgmt_set_ip(struct beiscsi_hba *phba,
 		dhcpreq->interface_hndl = phba->interface_handle;
 		dhcpreq->ip_type = BE2_DHCP_V4;
 
-		return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
+		rc = mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
 	} else {
-		return mgmt_static_ip_modify(phba, if_info, ip_param,
+		rc = mgmt_static_ip_modify(phba, if_info, ip_param,
 					     subnet_param, IP_ACTION_ADD);
 	}
 
+exit:
+	kfree(if_info);
 	return rc;
 }
 
#2 lore raw
Quoted 14 lines

drivers/scsi/be2iscsi/be_mgmt.c int mgmt_set_ip(struct beiscsi_hba *phba, · line 1018

Quoted 12 lines
drivers/scsi/be2iscsi/be_mgmt.c +1 -1
index 07934b0..a3e5648 100644
@@ -1015,7 +1015,7 @@ int mgmt_set_ip(struct beiscsi_hba *phba,
 		if (if_info->dhcp_state) {
 			beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
 				    "BG_%d : DHCP Already Enabled\n");
-			return 0;
+			goto exit;

rc should be initialised - so this needs to be added to your patch

It is initialized at the beginning of the function, and it must contain zero when the "goto exit" is executed.

int mgmt_set_ip(struct beiscsi_hba *phba,
struct iscsi_iface_param_info *ip_param, struct iscsi_iface_param_info *subnet_param, uint32_t boot_proto)

{
        struct be_cmd_get_def_gateway_resp gtway_addr_set;
        struct be_cmd_get_if_info_resp *if_info;
        struct be_cmd_set_dhcp_req *dhcpreq;
        struct be_cmd_rel_dhcp_req *reldhcp;
        struct be_dma_mem nonemb_cmd;
        uint8_t *gtway_addr;
        uint32_t ip_type;
        int rc;

        if (mgmt_get_all_if_id(phba))
                return -EIO;

        ip_type = (ip_param->param == ISCSI_NET_PARAM_IPV6_ADDR) ?
                BE2_IPV6 : BE2_IPV4 ;

        rc = mgmt_get_if_info(phba, ip_type, &if_info); <-------------- here
        if (rc)
                return rc;

        if (boot_proto == ISCSI_BOOTPROTO_DHCP) {
                if (if_info->dhcp_state) {
                        beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
                                    "BG_%d : DHCP Already Enabled\n");
                        goto exit;
                }

Regards,
Maurizio Lombardi

#3 lore raw
Quoted 12 lines · Maurizio Lombardi
Quoted 12 lines

drivers/scsi/be2iscsi/be_mgmt.c int mgmt_set_ip(struct beiscsi_hba *phba, · line 1018

Quoted 11 lines
drivers/scsi/be2iscsi/be_mgmt.c +1 -1
index 07934b0..a3e5648 100644
@@ -1015,7 +1015,7 @@ int mgmt_set_ip(struct beiscsi_hba *phba,
 		if (if_info->dhcp_state) {
 			beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
 				    "BG_%d : DHCP Already Enabled\n");
-			return 0;
+			goto exit;

rc should be initialised - so this needs to be added to your patch

Quoted 1 line

It is initialized at the beginning of the function, and it must contain zero when the "goto exit" is executed.

Correct, I haven't noticed the initialisation, sorry for the confusion. --tm

Quoted 38 lines

int mgmt_set_ip(struct beiscsi_hba *phba,
struct iscsi_iface_param_info *ip_param, struct iscsi_iface_param_info *subnet_param, uint32_t boot_proto)

{
        struct be_cmd_get_def_gateway_resp gtway_addr_set;
        struct be_cmd_get_if_info_resp *if_info;
        struct be_cmd_set_dhcp_req *dhcpreq;
        struct be_cmd_rel_dhcp_req *reldhcp;
        struct be_dma_mem nonemb_cmd;
        uint8_t *gtway_addr;
        uint32_t ip_type;
        int rc;

        if (mgmt_get_all_if_id(phba))
                return -EIO;

        ip_type = (ip_param->param == ISCSI_NET_PARAM_IPV6_ADDR) ?
                BE2_IPV6 : BE2_IPV4 ;

        rc = mgmt_get_if_info(phba, ip_type, &if_info); <-------------- here
        if (rc)
                return rc;

        if (boot_proto == ISCSI_BOOTPROTO_DHCP) {
                if (if_info->dhcp_state) {
                        beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
                                    "BG_%d : DHCP Already Enabled\n");
                        goto exit;
                }

Regards,
Maurizio Lombardi
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
Quoted 13 lines · Tomas Henzl
Quoted 12 lines · Maurizio Lombardi
Quoted 12 lines

drivers/scsi/be2iscsi/be_mgmt.c int mgmt_set_ip(struct beiscsi_hba *phba, · line 1018

Quoted 11 lines
drivers/scsi/be2iscsi/be_mgmt.c +1 -1
index 07934b0..a3e5648 100644
@@ -1015,7 +1015,7 @@ int mgmt_set_ip(struct beiscsi_hba *phba,
 		if (if_info->dhcp_state) {
 			beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
 				    "BG_%d : DHCP Already Enabled\n");
-			return 0;
+			goto exit;

rc should be initialised - so this needs to be added to your patch

Quoted 3 lines
Quoted 1 line

It is initialized at the beginning of the function, and it must contain zero when the "goto exit" is executed.

Correct, I haven't noticed the initialisation, sorry for the confusion.

Is this a formal review from you?

Reviewed-by
#5 lore raw
Quoted 13 lines · Christoph Hellwig
Quoted 12 lines · Tomas Henzl
Quoted 11 lines · Maurizio Lombardi
Quoted 11 lines

drivers/scsi/be2iscsi/be_mgmt.c int mgmt_set_ip(struct beiscsi_hba *phba, · line 1018

Quoted 10 lines
drivers/scsi/be2iscsi/be_mgmt.c +1 -1
index 07934b0..a3e5648 100644
@@ -1015,7 +1015,7 @@ int mgmt_set_ip(struct beiscsi_hba *phba,
 		if (if_info->dhcp_state) {
 			beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
 				    "BG_%d : DHCP Already Enabled\n");
-			return 0;
+			goto exit;

rc should be initialised - so this needs to be added to your patch

Quoted 3 lines
Quoted 2 lines
Quoted 1 line

It is initialized at the beginning of the function, and it must contain zero when the "goto exit" is executed.

Correct, I haven't noticed the initialisation, sorry for the confusion.

Is this a formal review from you?

I was under time pressure so I just wanted to remove my previous negative comment, but now -