Skip to contentSkip to conversation

scsi: lpfc: Fix a use after free in lpfc_nvme_unsol_ls_handler()

PATCH Superseded Dan Carpenter 4 participants 14 messages May 12, 2020 – May 20, 2020

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

PATCH 1/1 scsi: lpfc: Fix a use after free in lpfc_nvme_unsol_ls_handler()

The "axchg" pointer is dereferenced when we call the lpfc_nvme_unsol_ls_issue_abort() function. It can't be either freed or NULL.

Fixes 3a8070c567aa ("lpfc: Refactor NVME LS receive handling")
---
 drivers/scsi/lpfc/lpfc_sli.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/scsi/lpfc/lpfc_sli.c +3 -3
index 38889cb6e1996..fcf51b4192d66 100644
@@ -2895,14 +2895,14 @@ lpfc_nvme_unsol_ls_handler(struct lpfc_hba *phba, struct lpfc_iocbq *piocb)
 			(phba->nvmet_support) ? "T" : "I", ret);
 
 out_fail:
-	kfree(axchg);
-
 	/* recycle receive buffer */
 	lpfc_in_buf_free(phba, &nvmebuf->dbuf);
 
 	/* If start of new exchange, abort it */
-	if (fctl & FC_FC_FIRST_SEQ && !(fctl & FC_FC_EX_CTX))
+	if (axchg && (fctl & FC_FC_FIRST_SEQ) && !(fctl & FC_FC_EX_CTX))
 		lpfc_nvme_unsol_ls_issue_abort(phba, axchg, sid, oxid);
+
+	kfree(axchg);
 }
 
 /**
Signature · 1 line
2.26.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 22 lines · Dan Carpenter

The "axchg" pointer is dereferenced when we call the lpfc_nvme_unsol_ls_issue_abort() function. It can't be either freed or NULL.

Fixes 3a8070c567aa ("lpfc: Refactor NVME LS receive handling")
---
  drivers/scsi/lpfc/lpfc_sli.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/scsi/lpfc/lpfc_sli.c +0 -2
index 38889cb6e1996..fcf51b4192d66 100644
@@ -2895,14 +2895,14 @@ lpfc_nvme_unsol_ls_handler(struct lpfc_hba *phba, struct lpfc_iocbq *piocb)
  			(phba->nvmet_support) ? "T" : "I", ret);
 
  out_fail:
-	kfree(axchg);
-
  	/* recycle receive buffer */
  	lpfc_in_buf_free(phba, &nvmebuf->dbuf);

drivers/scsi/lpfc/lpfc_sli.c lpfc_nvme_unsol_ls_handler(struct lpfc_hba *phba, struct lpfc_iocbq *piocb) · line 2908

Quoted 10 lines
drivers/scsi/lpfc/lpfc_sli.c +3 -1
 
  	/* If start of new exchange, abort it */
-	if (fctl & FC_FC_FIRST_SEQ && !(fctl & FC_FC_EX_CTX))
+	if (axchg && (fctl & FC_FC_FIRST_SEQ) && !(fctl & FC_FC_EX_CTX))
  		lpfc_nvme_unsol_ls_issue_abort(phba, axchg, sid, oxid);
+
+	kfree(axchg);
  }
 
  /**

Thank You

-- james

#2 lore raw
In reply to Dan Carpenter

Dan,

Quoted 5 lines

The "axchg" pointer is dereferenced when we call the lpfc_nvme_unsol_ls_issue_abort() function. It can't be either freed or NULL.

Fixes 3a8070c567aa ("lpfc: Refactor NVME LS receive handling")

This fix needs to go through the NVMe tree.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#3 lore raw

PATCH RESEND 1/1 scsi: lpfc: Fix a use after free in lpfc_nvme_unsol_ls_handler()

The "axchg" pointer is dereferenced when we call the lpfc_nvme_unsol_ls_issue_abort() function. It can't be either freed or NULL.

Fixes 3a8070c567aa ("lpfc: Refactor NVME LS receive handling")

---
Resending to the NVMe list. Added James' R-b.

Is there a way we could update MAINTAINERS so that ./get_maintainer.pl send these to the correct list?

 drivers/scsi/lpfc/lpfc_sli.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/scsi/lpfc/lpfc_sli.c +3 -3
index 38889cb6e1996..fcf51b4192d66 100644
@@ -2895,14 +2895,14 @@ lpfc_nvme_unsol_ls_handler(struct lpfc_hba *phba, struct lpfc_iocbq *piocb)
 			(phba->nvmet_support) ? "T" : "I", ret);
 
 out_fail:
-	kfree(axchg);
-
 	/* recycle receive buffer */
 	lpfc_in_buf_free(phba, &nvmebuf->dbuf);
 
 	/* If start of new exchange, abort it */
-	if (fctl & FC_FC_FIRST_SEQ && !(fctl & FC_FC_EX_CTX))
+	if (axchg && (fctl & FC_FC_FIRST_SEQ) && !(fctl & FC_FC_EX_CTX))
 		lpfc_nvme_unsol_ls_issue_abort(phba, axchg, sid, oxid);
+
+	kfree(axchg);
 }
 
 /**
Signature · 1 line
2.26.2
#5 lore raw
Quoted 1 line · Christoph Hellwig

James, can you review this patch?

He already reviewed it in a different thread. I copied his R-b tag.

regards,
dan carpenter

#6 lore raw
Quoted 4 lines · Dan Carpenter
Quoted 1 line · Christoph Hellwig

James, can you review this patch?

He already reviewed it in a different thread. I copied his R-b tag.

James, should this go into the nvme or scsi tree?

#7 lore raw

Christoph,

Quoted 7 lines · Dan Carpenter
Quoted 4 lines · Christoph Hellwig
Quoted 1 line

James, can you review this patch?

He already reviewed it in a different thread. I copied his R-b tag.

James, should this go into the nvme or scsi tree?

The offending patch is in the nvme tree so I think you should take it. Otherwise I'll pick it up in 5.8/scsi-fixes.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#8 lore raw
Quoted 5 lines · Martin K. Petersen

Christoph,

Quoted 2 lines · Dan Carpenter
Quoted 1 line · Christoph Hellwig
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

James, can you review this patch?

He already reviewed it in a different thread. I copied his R-b tag.

James, should this go into the nvme or scsi tree?

The offending patch is in the nvme tree so I think you should take it. Otherwise I'll pick it up in 5.8/scsi-fixes.

I'll pick it up. Can you give me an ACK for it to show Jens you are ok with that?

#11 lore raw
Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · Martin K. Petersen

Christoph,

Quoted 2 lines

I'll pick it up. Can you give me an ACK for it to show Jens you are ok with that?

Thanks,

applied to nvme-5.8.

Guess you didn't see Dan's response - we had replied, and Dick rejected it. Dick has created a new patch that I'll be posting shortly.

-- james

#12 lore raw
Quoted 6 lines · James Smart
Quoted 5 lines · Christoph Hellwig
Quoted 4 lines · Martin K. Petersen

Christoph,

Quoted 2 lines

I'll pick it up. Can you give me an ACK for it to show Jens you are ok with that?

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Thanks,

applied to nvme-5.8.

Guess you didn't see Dan's response - we had replied, and Dick rejected it. Dick has created a new patch that I'll be posting shortly.

Oh well, I'll pull it again then.

#13 lore raw
In reply to James Smart
Quoted 6 lines · James Smart
Quoted 5 lines · Christoph Hellwig
Quoted 4 lines · Martin K. Petersen

Christoph,

Quoted 2 lines

I'll pick it up. Can you give me an ACK for it to show Jens you are ok with that?

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Thanks,

applied to nvme-5.8.

Guess you didn't see Dan's response - we had replied, and Dick rejected it. Dick has created a new patch that I'll be posting shortly.

Gar.... I'm sorry I have two mail boxes, one for kernel-janitors and one for my own email address. I guess his email never made it to the lists. I did get it on my other email box though.

regards,
dan carpenter