mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/5] SCSI: aacraid, fix memory leak
@ 2009-09-23 14:15 Jiri Slaby
  2009-09-23 14:15 ` [PATCH 2/5] SCSI: remove unnecessary NULL test Jiri Slaby
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Jiri Slaby @ 2009-09-23 14:15 UTC (permalink / raw)
  To: James.Bottomley; +Cc: linux-scsi, linux-kernel, Jiri Slaby

Stanse found a memory leak on one fail path in aac_send_raw_srb. Add kfree
there.

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
Cc: James E.J. Bottomley <James.Bottomley@suse.de>
---
 drivers/scsi/aacraid/commctrl.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/drivers/scsi/aacraid/commctrl.c b/drivers/scsi/aacraid/commctrl.c
index 0391d75..5c9a8be 100644
--- a/drivers/scsi/aacraid/commctrl.c
+++ b/drivers/scsi/aacraid/commctrl.c
@@ -649,6 +649,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 				     AAC_OPT_NEW_COMM) ?
 				      (dev->scsi_host_ptr->max_sectors << 9) :
 				      65536) {
+					kfree (usg);
 					rcode = -EINVAL;
 					goto cleanup;
 				}
-- 
1.6.4.2


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

* [PATCH 2/5] SCSI: remove unnecessary NULL test
  2009-09-23 14:15 [PATCH 1/5] SCSI: aacraid, fix memory leak Jiri Slaby
@ 2009-09-23 14:15 ` Jiri Slaby
  2009-09-23 14:15 ` [PATCH 3/5] SCSI: lpfc, fix memory leak Jiri Slaby
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Jiri Slaby @ 2009-09-23 14:15 UTC (permalink / raw)
  To: James.Bottomley; +Cc: linux-scsi, linux-kernel, Jiri Slaby

Stanse found that c3cn is poked many times around in
cxgb3i_conn_pdu_ready, there is no need to check if it is NULL.

Remove the test.

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
Cc: James E.J. Bottomley <James.Bottomley@suse.de>
---
 drivers/scsi/cxgb3i/cxgb3i_pdu.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/cxgb3i/cxgb3i_pdu.c b/drivers/scsi/cxgb3i/cxgb3i_pdu.c
index 7091050..64bbc28 100644
--- a/drivers/scsi/cxgb3i/cxgb3i_pdu.c
+++ b/drivers/scsi/cxgb3i/cxgb3i_pdu.c
@@ -461,10 +461,8 @@ void cxgb3i_conn_pdu_ready(struct s3_conn *c3cn)
 		skb = skb_peek(&c3cn->receive_queue);
 	}
 	read_unlock(&c3cn->callback_lock);
-	if (c3cn) {
-		c3cn->copied_seq += read;
-		cxgb3i_c3cn_rx_credits(c3cn, read);
-	}
+	c3cn->copied_seq += read;
+	cxgb3i_c3cn_rx_credits(c3cn, read);
 	conn->rxdata_octets += read;
 
 	if (err) {
-- 
1.6.4.2


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

* [PATCH 3/5] SCSI: lpfc, fix memory leak
  2009-09-23 14:15 [PATCH 1/5] SCSI: aacraid, fix memory leak Jiri Slaby
  2009-09-23 14:15 ` [PATCH 2/5] SCSI: remove unnecessary NULL test Jiri Slaby
@ 2009-09-23 14:15 ` Jiri Slaby
  2009-09-23 14:15 ` [PATCH 4/5] SCSI: qla2xxx, fix NULL-ptr dereference Jiri Slaby
  2009-09-23 14:15 ` [PATCH 5/5] SCSI: scsi_lib, fix potential NULL dereference Jiri Slaby
  3 siblings, 0 replies; 6+ messages in thread
From: Jiri Slaby @ 2009-09-23 14:15 UTC (permalink / raw)
  To: James.Bottomley; +Cc: linux-scsi, linux-kernel, Jiri Slaby, James Smart

Stanse found a memory leak on one fail path in lpfc_sli4_read_rev.

Add there kfree.

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
Cc: James Smart <james.smart@emulex.com>
Cc: James E.J. Bottomley <James.Bottomley@suse.de>
---
 drivers/scsi/lpfc/lpfc_sli.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index 43cbe33..7750868 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -4211,6 +4211,7 @@ lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
 	if (rc) {
 		dma_free_coherent(&phba->pcidev->dev, dma_size,
 				  dmabuf->virt, dmabuf->phys);
+		kfree(dmabuf);
 		return -EIO;
 	}
 
-- 
1.6.4.2


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

* [PATCH 4/5] SCSI: qla2xxx, fix NULL-ptr dereference
  2009-09-23 14:15 [PATCH 1/5] SCSI: aacraid, fix memory leak Jiri Slaby
  2009-09-23 14:15 ` [PATCH 2/5] SCSI: remove unnecessary NULL test Jiri Slaby
  2009-09-23 14:15 ` [PATCH 3/5] SCSI: lpfc, fix memory leak Jiri Slaby
@ 2009-09-23 14:15 ` Jiri Slaby
  2009-09-25  7:36   ` Anirban Chakraborty
  2009-09-23 14:15 ` [PATCH 5/5] SCSI: scsi_lib, fix potential NULL dereference Jiri Slaby
  3 siblings, 1 reply; 6+ messages in thread
From: Jiri Slaby @ 2009-09-23 14:15 UTC (permalink / raw)
  To: James.Bottomley; +Cc: linux-scsi, linux-kernel, Jiri Slaby, Andrew Vasquez

Stanse found a NULL-ptr dereference on one fail path in
qla25xx_create_rsp_que. It jumps to que_failed label and
qla25xx_free_rsp_que there dereferences rsp which is NULL.

Return with ENOMEM directly instead.

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
Cc: Andrew Vasquez <andrew.vasquez@qlogic.com>
Cc: James E.J. Bottomley <James.Bottomley@suse.de>
---
 drivers/scsi/qla2xxx/qla_mid.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_mid.c b/drivers/scsi/qla2xxx/qla_mid.c
index 42b799a..8b4e723 100644
--- a/drivers/scsi/qla2xxx/qla_mid.c
+++ b/drivers/scsi/qla2xxx/qla_mid.c
@@ -659,7 +659,7 @@ qla25xx_create_rsp_que(struct qla_hw_data *ha, uint16_t options,
 	if (rsp == NULL) {
 		qla_printk(KERN_WARNING, ha, "could not allocate memory for"
 				" response que\n");
-		goto que_failed;
+		return -ENOMEM;
 	}
 
 	rsp->length = RESPONSE_ENTRY_CNT_MQ;
-- 
1.6.4.2


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

* [PATCH 5/5] SCSI: scsi_lib, fix potential NULL dereference
  2009-09-23 14:15 [PATCH 1/5] SCSI: aacraid, fix memory leak Jiri Slaby
                   ` (2 preceding siblings ...)
  2009-09-23 14:15 ` [PATCH 4/5] SCSI: qla2xxx, fix NULL-ptr dereference Jiri Slaby
@ 2009-09-23 14:15 ` Jiri Slaby
  3 siblings, 0 replies; 6+ messages in thread
From: Jiri Slaby @ 2009-09-23 14:15 UTC (permalink / raw)
  To: James.Bottomley; +Cc: linux-scsi, linux-kernel, Jiri Slaby

Stanse found a potential NULL dereference in scsi_kill_request.

Instead of triggering BUG() in 'if (unlikely(cmd == NULL))' branch,
the kernel will Oops earlier on cmd dereference.

Move the dereferences after the if.

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
Cc: James E.J. Bottomley <James.Bottomley@suse.de>
---
 drivers/scsi/scsi_lib.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 5987da8..98f601a 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -1359,9 +1359,9 @@ static int scsi_lld_busy(struct request_queue *q)
 static void scsi_kill_request(struct request *req, struct request_queue *q)
 {
 	struct scsi_cmnd *cmd = req->special;
-	struct scsi_device *sdev = cmd->device;
-	struct scsi_target *starget = scsi_target(sdev);
-	struct Scsi_Host *shost = sdev->host;
+	struct scsi_device *sdev;
+	struct scsi_target *starget;
+	struct Scsi_Host *shost;
 
 	blk_start_request(req);
 
@@ -1371,6 +1371,9 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
 		BUG();
 	}
 
+	sdev = cmd->device;
+	starget = scsi_target(sdev);
+	shost = sdev->host;
 	scsi_init_cmd_errh(cmd);
 	cmd->result = DID_NO_CONNECT << 16;
 	atomic_inc(&cmd->device->iorequest_cnt);
-- 
1.6.4.2


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

* Re: [PATCH 4/5] SCSI: qla2xxx, fix NULL-ptr dereference
  2009-09-23 14:15 ` [PATCH 4/5] SCSI: qla2xxx, fix NULL-ptr dereference Jiri Slaby
@ 2009-09-25  7:36   ` Anirban Chakraborty
  0 siblings, 0 replies; 6+ messages in thread
From: Anirban Chakraborty @ 2009-09-25  7:36 UTC (permalink / raw)
  To: Jiri Slaby
  Cc: James.Bottomley, linux-scsi@vger.kernel.org Mailing List,
	linux-kernel, Andrew Vasquez


On Sep 23, 2009, at 7:15 AM, Jiri Slaby wrote:

> Stanse found a NULL-ptr dereference on one fail path in
> qla25xx_create_rsp_que. It jumps to que_failed label and
> qla25xx_free_rsp_que there dereferences rsp which is NULL.
>
> Return with ENOMEM directly instead.
>
Thanks for pointing it out. There is another code path (create_req_que)
where the same bug exists. I will send a patch that takes care of the  
both.

-Anirban

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

end of thread, other threads:[~2009-09-25  7:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-23 14:15 [PATCH 1/5] SCSI: aacraid, fix memory leak Jiri Slaby
2009-09-23 14:15 ` [PATCH 2/5] SCSI: remove unnecessary NULL test Jiri Slaby
2009-09-23 14:15 ` [PATCH 3/5] SCSI: lpfc, fix memory leak Jiri Slaby
2009-09-23 14:15 ` [PATCH 4/5] SCSI: qla2xxx, fix NULL-ptr dereference Jiri Slaby
2009-09-25  7:36   ` Anirban Chakraborty
2009-09-23 14:15 ` [PATCH 5/5] SCSI: scsi_lib, fix potential NULL dereference Jiri Slaby

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®