IB/hfi1: Prevent a NULL dereference
Subsystems (3)
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.
drivers/infiniband/hw/hfi1/file_ops.c +1 -1
@@ -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); }
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")Signed-off-by Dan Carpenter <[email protected]>drivers/infiniband/hw/hfi1/file_ops.c +0
-0@@ -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
-1if (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!
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 dereferenceIn 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")Signed-off-by Dan Carpenter <[email protected]>drivers/infiniband/hw/hfi1/file_ops.c +0
-0@@ -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
-1if (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
@@ -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 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 dereferenceIn 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")Signed-off-by Dan Carpenter <[email protected]>drivers/infiniband/hw/hfi1/file_ops.c +0
-0@@ -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
-1if (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
PATCH v2 1/1 IB/hfi1: Prevent a NULL dereference
In reply to a message not in the archiveIn the original code, we set "fd->uctxt" to NULL and then dereference it which will cause an Oops.
---
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
@@ -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;
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 dereferenceIn 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")Signed-off-by Dan Carpenter <[email protected]>---
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@@ -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
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 dereferenceIn 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")Signed-off-by Dan Carpenter <[email protected]>---
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@@ -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
-1return 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
Reviewed-by Michael J. Ruhl <[email protected]>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