Skip to contentSkip to conversation

IB/iser: Fix some error handling in iser_fast_reg_fmr()

PATCH In review Dan Carpenter 3 participants 5 messages Feb 20, 2019 – Feb 26, 2019

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

PATCH 1/1 IB/iser: Fix some error handling in iser_fast_reg_fmr()

The ib_sg_to_pages() function can return negative error codes. The problem with the error handling is that mem->dma_nents is a u32 so the comparison is type promoted to unsigned int. A negative error code thus becomes a large positive value and is treated as valid.

Fixes 57b26497fabe ("IB/iser: Pass the correct number of entries for dma mapped SGL ")
---
 drivers/infiniband/ulp/iser/iser_memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/ulp/iser/iser_memory.c +1 -1
index 2ba70729d7b0..04a9b8f118df 100644
@@ -240,7 +240,7 @@ int iser_fast_reg_fmr(struct iscsi_iser_task *iser_task,
 	page_vec->fake_mr.page_size = SIZE_4K;
 	plen = ib_sg_to_pages(&page_vec->fake_mr, mem->sg,
 			      mem->dma_nents, NULL, iser_set_page);
-	if (unlikely(plen < mem->dma_nents)) {
+	if (plen < 0 || plen < mem->dma_nents) {
 		iser_err("page vec too short to hold this SG\n");
 		iser_data_buf_dump(mem, device->ib_device);
 		iser_dump_page_vec(page_vec);
Signature · 1 line
2.17.1
#2 lore raw
In reply to Dan Carpenter
Quoted 16 lines · Dan Carpenter

The ib_sg_to_pages() function can return negative error codes. The problem with the error handling is that mem->dma_nents is a u32 so the comparison is type promoted to unsigned int. A negative error code thus becomes a large positive value and is treated as valid.

Fixes 57b26497fabe ("IB/iser: Pass the correct number of entries for dma mapped SGL ")
---
  drivers/infiniband/ulp/iser/iser_memory.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/ulp/iser/iser_memory.c +0 -0
index 2ba70729d7b0..04a9b8f118df 100644

drivers/infiniband/ulp/iser/iser_memory.c int iser_fast_reg_fmr(struct iscsi_iser_task *iser_task, · line 246

Quoted 8 lines
drivers/infiniband/ulp/iser/iser_memory.c +1 -1
@@ -240,7 +240,7 @@ int iser_fast_reg_fmr(struct iscsi_iser_task *iser_task,
  	page_vec->fake_mr.page_size = SIZE_4K;
  	plen = ib_sg_to_pages(&page_vec->fake_mr, mem->sg,
  			      mem->dma_nents, NULL, iser_set_page);
-	if (unlikely(plen < mem->dma_nents)) {
+	if (plen < 0 || plen < mem->dma_nents) {
  		iser_err("page vec too short to hold this SG\n");
  		iser_data_buf_dump(mem, device->ib_device);
  		iser_dump_page_vec(page_vec);

Was the "unlikely" removed in purpose ?

I'm ok with that since Sagi has patches that will remove FMR usage in iSER.

but the below fix is the correct one for future code as well (ib_dma_map_sg returns int and not unsigned int):

(quoted diff) +0 -0

b/drivers/infiniband/ulp/iser/iscsi_iser.h
index 0bf8512..def8cfe 100644

drivers/infiniband/ulp/iser/iscsi_iser.h +1 -1
@@ -205,7 +205,7 @@ struct iser_data_buf {
     struct scatterlist *sg;
     int                size;
     unsigned long      data_len;
-   unsigned int       dma_nents;
+   int                dma_nents;
  };
 
 

thoughts ?

maintainer
#3 lore raw
In reply to Dan Carpenter
Quoted 18 lines

but the below fix is the correct one for future code as well (ib_dma_map_sg returns int and not unsigned int):

drivers/infiniband/ulp/iser/iscsi_iser.h +1 -1
index 0bf8512..def8cfe 100644
@@ -205,7 +205,7 @@ struct iser_data_buf {
     struct scatterlist *sg;
     int                size;
     unsigned long      data_len;
-   unsigned int       dma_nents;
+   int                dma_nents;
  };
 
 
Quoted 1 line

thoughts ?

That's fine as well, care to send a patch?

#4 lore raw
In reply to Dan Carpenter
Quoted 18 lines · Sagi Grimberg
Quoted 18 lines

but the below fix is the correct one for future code as well (ib_dma_map_sg returns int and not unsigned int):

drivers/infiniband/ulp/iser/iscsi_iser.h +1 -1
index 0bf8512..def8cfe 100644
@@ -205,7 +205,7 @@ struct iser_data_buf {
      struct scatterlist *sg;
      int                size;
      unsigned long      data_len;
-   unsigned int       dma_nents;
+   int                dma_nents;
   };
 
 
Quoted 3 lines
Quoted 1 line

thoughts ?

That's fine as well, care to send a patch?

Done, please see it in the mailing list.