lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1551394596.31902.209.camel@acm.org>
Date:   Thu, 28 Feb 2019 14:56:36 -0800
From:   Bart Van Assche <bvanassche@....org>
To:     Shaobo He <shaobo@...utah.edu>, linux-rdma@...r.kernel.org
Cc:     Steve Wise <swise@...lsio.com>, Doug Ledford <dledford@...hat.com>,
        Jason Gunthorpe <jgg@...pe.ca>,
        open list <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] cxgb4: fix undefined behavior in mem.c

On Thu, 2019-02-28 at 15:38 -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@...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;
>  }

Please quote the relevant paragraphs from the C standard. All I have found
about free() in ISO/IEC 9899:2017 is the following:

Description
The free function causes the space pointed to by ptr to be deallocated, that
is, made available for further allocation. If ptr is a null pointer, no
action occurs. Otherwise, if the argument does not match a pointer earlier
returned by a memory management function, or if the space has been
deallocated by a call to free or realloc, the behavior is undefined.

That is not sufficient to claim that the above code triggers undefined
behavior.

Bart.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ