From: Jason Gunthorpe <jgg@ziepe.ca>
To: Shaobo He <shaobo@cs.utah.edu>
Cc: linux-rdma@vger.kernel.org, Steve Wise <swise@chelsio.com>,
Doug Ledford <dledford@redhat.com>,
open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] cxgb4: fix undefined behavior in mem.c
Date: Mon, 4 Mar 2019 15:54:46 -0400 [thread overview]
Message-ID: <20190304195446.GA7751@ziepe.ca> (raw)
In-Reply-To: <1551393519-96595-1-git-send-email-shaobo@cs.utah.edu>
On Thu, Feb 28, 2019 at 03:38:38PM -0700, Shaobo He wrote:
> 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(-)
Discussion aside, this is a worthwile fix. I rewrote the commit
message to avoid referencing 'undefined behavior' though, this is just
a straight up bug in the logging. Another thread could get the same
pointer value for the mhp before the print creating a confusing log.
cxgb4: kfree mhp after the debug print
In function `c4iw_dealloc_mw`, variable mhp's value is printed after
freed, it is clearer to have the print before the kfree.
Otherwise racing threads could allocate another mhp with the same pointer
value and create confusing tracing.
Jason
prev parent reply other threads:[~2019-03-04 19:54 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190304195446.GA7751@ziepe.ca \
--to=jgg@ziepe.ca \
--cc=dledford@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=shaobo@cs.utah.edu \
--cc=swise@chelsio.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox