linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cxgb4: fix undefined behavior in mem.c
@ 2019-02-28 22:38 Shaobo He
  2019-02-28 22:56 ` Bart Van Assche
  2019-03-04 19:54 ` Jason Gunthorpe
  0 siblings, 2 replies; 9+ messages in thread
From: Shaobo He @ 2019-02-28 22:38 UTC (permalink / raw)
  To: linux-rdma; +Cc: shaobo, Steve Wise, Doug Ledford, Jason Gunthorpe, open list

In function `c4iw_dealloc_mw`, variable mhp's value is printed after
freed, which triggers undefined behavior according to this post:
https://trust-in-soft.com/dangling-pointer-indeterminate/.

This commit fixes it by swapping the order of `kfree` and `pr_debug`.

Signed-off-by: Shaobo He <shaobo@cs.utah.edu>
---
 drivers/infiniband/hw/cxgb4/mem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
index 7b76e6f..bb8e0bc 100644
--- a/drivers/infiniband/hw/cxgb4/mem.c
+++ b/drivers/infiniband/hw/cxgb4/mem.c
@@ -684,8 +684,8 @@ int c4iw_dealloc_mw(struct ib_mw *mw)
 			  mhp->wr_waitp);
 	kfree_skb(mhp->dereg_skb);
 	c4iw_put_wr_wait(mhp->wr_waitp);
-	kfree(mhp);
 	pr_debug("ib_mw %p mmid 0x%x ptr %p\n", mw, mmid, mhp);
+	kfree(mhp);
 	return 0;
 }
 
-- 
2.7.4


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

end of thread, other threads:[~2019-03-04 19:54 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-28 22:38 [PATCH] cxgb4: fix undefined behavior in mem.c Shaobo He
2019-02-28 22:56 ` Bart Van Assche
2019-02-28 23:18   ` Shaobo He
2019-02-28 23:33     ` Bart Van Assche
2019-02-28 23:57       ` Shaobo He
2019-03-01 14:26         ` Doug Ledford
2019-03-01 21:21           ` Shaobo He
2019-03-01 18:15     ` Christopher Lameter
2019-03-04 19:54 ` Jason Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).