Skip to contentSkip to conversation

IB/hfi1: Prevent a NULL dereference

PATCH Superseded Dan Carpenter 4 participants 7 messages Jan 9, 2018 – Jan 10, 2018 1 message not in the archive

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

PATCH 1/1 IB/hfi1: Prevent a NULL dereference

In the original code, we set "fd->uctxt" to NULL and then dereference it which will cause an Oops.

Fixes f2a3bc00a03c ("IB/hfi1: Protect context array set/clear with spinlock")
drivers/infiniband/hw/hfi1/file_ops.c +1 -1
index 82086241aac3..3de1ac94bb85 100644
@@ -763,10 +763,10 @@ static int complete_subctxt(struct hfi1_filedata *fd)
 	}
 
 	if (ret) {
+		__clear_bit(fd->subctxt, fd->uctxt->in_use_ctxts);
 		hfi1_rcd_put(fd->uctxt);
 		fd->uctxt = NULL;
 		spin_lock_irqsave(&fd->dd->uctxt_lock, flags);
-		__clear_bit(fd->subctxt, fd->uctxt->in_use_ctxts);
 		spin_unlock_irqrestore(&fd->dd->uctxt_lock, flags);
 	}
 
Acked-by on v1 1/1
#1 lore raw
Quoted 13 lines · Dan Carpenter

In the original code, we set "fd->uctxt" to NULL and then dereference it which will cause an Oops.

Fixes f2a3bc00a03c ("IB/hfi1: Protect context array set/clear with spinlock")
drivers/infiniband/hw/hfi1/file_ops.c +0 -0
index 82086241aac3..3de1ac94bb85 100644
@@ -763,10 +763,10 @@ static int complete_subctxt(struct hfi1_filedata *fd)
  	}

drivers/infiniband/hw/hfi1/file_ops.c static int complete_subctxt(struct hfi1_filedata *fd) · line 772

Quoted 10 lines
drivers/infiniband/hw/hfi1/file_ops.c +1 -1
 
  	if (ret) {
+		__clear_bit(fd->subctxt, fd->uctxt->in_use_ctxts);
  		hfi1_rcd_put(fd->uctxt);
  		fd->uctxt = NULL;
  		spin_lock_irqsave(&fd->dd->uctxt_lock, flags);
-		__clear_bit(fd->subctxt, fd->uctxt->in_use_ctxts);
  		spin_unlock_irqrestore(&fd->dd->uctxt_lock, flags);
  	}
 

Thanks!

#2 lore raw
In reply to Dan Carpenter
Quoted 23 lines

-----Original Message-----
From: Dan Carpenter [mailto:[email protected]]
Sent: Tuesday, January 9, 2018 4:27 AM
To: Marciniszyn, Mike <[email protected]>; Ruhl, Michael J <[email protected]>
Cc: Dalessandro, Dennis <[email protected]>; Doug Ledford <[email protected]>; Jason Gunthorpe <[email protected]>; linux- [email protected]; [email protected]
Subject: [PATCH] IB/hfi1: Prevent a NULL dereference

In the original code, we set "fd->uctxt" to NULL and then dereference it which will cause an Oops.

Fixes f2a3bc00a03c ("IB/hfi1: Protect context array set/clear with spinlock")
drivers/infiniband/hw/hfi1/file_ops.c +0 -0
index 82086241aac3..3de1ac94bb85 100644
@@ -763,10 +763,10 @@ static int complete_subctxt(struct hfi1_filedata *fd)
 	}

drivers/infiniband/hw/hfi1/file_ops.c static int complete_subctxt(struct hfi1_filedata *fd) · line 772

Quoted 10 lines
drivers/infiniband/hw/hfi1/file_ops.c +1 -1
 
 	if (ret) {
+		__clear_bit(fd->subctxt, fd->uctxt->in_use_ctxts);
 		hfi1_rcd_put(fd->uctxt);
 		fd->uctxt = NULL;
 		spin_lock_irqsave(&fd->dd->uctxt_lock, flags);
-		__clear_bit(fd->subctxt, fd->uctxt->in_use_ctxts);
 		spin_unlock_irqrestore(&fd->dd->uctxt_lock, flags);
 	}
 

Hi Dan,

Thanks for catching this.

However, the patch is not quite correct.

The __clear_bit() spin_lock_irqsave/restore need stay together. The patch should be:

drivers/infiniband/hw/hfi1/file_ops.c +2 -2
index 7750a9c..1df7da4 100644
@@ -763,11 +763,11 @@ static int complete_subctxt(struct hfi1_filedata *fd)
        }
 
        if (ret) {
-               hfi1_rcd_put(fd->uctxt);
-               fd->uctxt = NULL;
                spin_lock_irqsave(&fd->dd->uctxt_lock, flags);
                __clear_bit(fd->subctxt, fd->uctxt->in_use_ctxts);
                spin_unlock_irqrestore(&fd->dd->uctxt_lock, flags);
+               hfi1_rcd_put(fd->uctxt);
+               fd->uctxt = NULL;
        }
 
#3 lore raw
Quoted 36 lines · Michael J
Quoted 23 lines

-----Original Message-----
From: Dan Carpenter [mailto:[email protected]]
Sent: Tuesday, January 9, 2018 4:27 AM
To: Marciniszyn, Mike <[email protected]>; Ruhl, Michael J <[email protected]>
Cc: Dalessandro, Dennis <[email protected]>; Doug Ledford <[email protected]>; Jason Gunthorpe <[email protected]>; linux- [email protected]; [email protected]
Subject: [PATCH] IB/hfi1: Prevent a NULL dereference

In the original code, we set "fd->uctxt" to NULL and then dereference it which will cause an Oops.

Fixes f2a3bc00a03c ("IB/hfi1: Protect context array set/clear with spinlock")
drivers/infiniband/hw/hfi1/file_ops.c +0 -0
index 82086241aac3..3de1ac94bb85 100644
@@ -763,10 +763,10 @@ static int complete_subctxt(struct hfi1_filedata *fd)
 	}

drivers/infiniband/hw/hfi1/file_ops.c static int complete_subctxt(struct hfi1_filedata *fd) · line 772

Quoted 10 lines
drivers/infiniband/hw/hfi1/file_ops.c +1 -1
 
 	if (ret) {
+		__clear_bit(fd->subctxt, fd->uctxt->in_use_ctxts);
 		hfi1_rcd_put(fd->uctxt);
 		fd->uctxt = NULL;
 		spin_lock_irqsave(&fd->dd->uctxt_lock, flags);
-		__clear_bit(fd->subctxt, fd->uctxt->in_use_ctxts);
 		spin_unlock_irqrestore(&fd->dd->uctxt_lock, flags);
 	}
 

Hi Dan,

Quoted 6 lines

Thanks for catching this.

However, the patch is not quite correct.

The __clear_bit() spin_lock_irqsave/restore need stay together. The patch should be:

Oh. Yeah. I should have noticed that now the spin_lock is pointless. Let me resend. Thanks.

regards,
dan carpenter

#5 lore raw

PATCH v2 1/1 IB/hfi1: Prevent a NULL dereference

In reply to a message not in the archive

In the original code, we set "fd->uctxt" to NULL and then dereference it which will cause an Oops.

Fixes f2a3bc00a03c ("IB/hfi1: Protect context array set/clear with spinlock")

---
v2: In v1, I accidentally moved the __clear_bit() out from under the
spin_lock(). Thanks for the review, Michael!

drivers/infiniband/hw/hfi1/file_ops.c +2 -2
index 82086241aac3..bd6f03cc5ee0 100644
@@ -763,11 +763,11 @@ static int complete_subctxt(struct hfi1_filedata *fd)
 	}
 
 	if (ret) {
-		hfi1_rcd_put(fd->uctxt);
-		fd->uctxt = NULL;
 		spin_lock_irqsave(&fd->dd->uctxt_lock, flags);
 		__clear_bit(fd->subctxt, fd->uctxt->in_use_ctxts);
 		spin_unlock_irqrestore(&fd->dd->uctxt_lock, flags);
+		hfi1_rcd_put(fd->uctxt);
+		fd->uctxt = NULL;
 	}
 
 	return ret;
Reviewed-by on v2 1/1
#6 lore raw
Quoted 29 lines

-----Original Message-----
From: [email protected] [mailto:linux-rdma- [email protected]] On Behalf Of Dan Carpenter
Sent: Tuesday, January 9, 2018 3:04 PM
To: Marciniszyn, Mike <[email protected]>
Cc: Dalessandro, Dennis <[email protected]>; Doug Ledford <[email protected]>; Jason Gunthorpe <[email protected]>; linux- [email protected]; [email protected]
Subject: [PATCH v2] IB/hfi1: Prevent a NULL dereference

In the original code, we set "fd->uctxt" to NULL and then dereference it which will cause an Oops.

Fixes f2a3bc00a03c ("IB/hfi1: Protect context array set/clear with spinlock")

---
v2: In v1, I accidentally moved the __clear_bit() out from under the
spin_lock(). Thanks for the review, Michael!

drivers/infiniband/hw/hfi1/file_ops.c +0 -1
index 82086241aac3..bd6f03cc5ee0 100644
@@ -763,11 +763,11 @@ static int complete_subctxt(struct hfi1_filedata *fd)
 	}
 
 	if (ret) {
-		hfi1_rcd_put(fd->uctxt);

drivers/infiniband/hw/hfi1/file_ops.c static int complete_subctxt(struct hfi1_filedata *fd)

Quoted 10 lines
drivers/infiniband/hw/hfi1/file_ops.c +2 -2
-		fd->uctxt = NULL;
 		spin_lock_irqsave(&fd->dd->uctxt_lock, flags);
 		__clear_bit(fd->subctxt, fd->uctxt->in_use_ctxts);
 		spin_unlock_irqrestore(&fd->dd->uctxt_lock, flags);
+		hfi1_rcd_put(fd->uctxt);
+		fd->uctxt = NULL;
 	}
 
 	return ret;
--

Looks good. Adding tag for stable too.

Thanks,

Mike

Quoted 3 lines

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

#7 lore raw
Quoted 37 lines · Michael J
Quoted 37 lines

-----Original Message-----
From: [email protected] [mailto:linux-rdma- [email protected]] On Behalf Of Dan Carpenter
Sent: Tuesday, January 9, 2018 3:04 PM
To: Marciniszyn, Mike <[email protected]>
Cc: Dalessandro, Dennis <[email protected]>; Doug Ledford <[email protected]>; Jason Gunthorpe <[email protected]>; linux- [email protected]; [email protected]
Subject: [PATCH v2] IB/hfi1: Prevent a NULL dereference

In the original code, we set "fd->uctxt" to NULL and then dereference it which will cause an Oops.

Fixes f2a3bc00a03c ("IB/hfi1: Protect context array set/clear with spinlock")

---
v2: In v1, I accidentally moved the __clear_bit() out from under the
spin_lock(). Thanks for the review, Michael!

drivers/infiniband/hw/hfi1/file_ops.c +2 -2
index 82086241aac3..bd6f03cc5ee0 100644
@@ -763,11 +763,11 @@ static int complete_subctxt(struct hfi1_filedata *fd)
 	}
 
 	if (ret) {
-		hfi1_rcd_put(fd->uctxt);
-		fd->uctxt = NULL;
 		spin_lock_irqsave(&fd->dd->uctxt_lock, flags);
 		__clear_bit(fd->subctxt, fd->uctxt->in_use_ctxts);
 		spin_unlock_irqrestore(&fd->dd->uctxt_lock, flags);
+		hfi1_rcd_put(fd->uctxt);
+		fd->uctxt = NULL;
 	}
 
Quoted 4 lines

drivers/infiniband/hw/hfi1/file_ops.c static int complete_subctxt(struct hfi1_filedata *fd)

Quoted 2 lines
drivers/infiniband/hw/hfi1/file_ops.c +0 -1
 	return ret;
--
Cc <[email protected]> # 4.14.x

Unfortunately, patchworks doesn't pick up additional Cc: tags, only reviewed-bys and acks. In any case, I hand added it. Thanks, applied to for-rc.

Quoted 11 lines

Looks good. Adding tag for stable too.

Thanks,

Mike

Quoted 3 lines

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

Signature · 3 lines
Doug Ledford <[email protected]>
    GPG KeyID: B826A3330E572FDD
    Key fingerprint = AE6B 1BDA 122B 23B4 265B  1274 B826 A333 0E57 2FDD