Re: [PATCH] block: Fix potential NULL pointer dereference in __bio_crypt_clone()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Sep 01, 2020 at 07:59:21AM -0400, Miaohe Lin wrote:
> mempool_alloc() may return NULL if __GFP_DIRECT_RECLAIM is not set in
> gfp_mask under memory pressure. So we should check the return value of
> mempool_alloc() against NULL before dereference.
> 
> Fixes: a892c8d52c02 ("block: Inline encryption support for blk-mq")
> Signed-off-by: Miaohe Lin <linmiaohe@xxxxxxxxxx>
> ---
>  block/blk-crypto.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/block/blk-crypto.c b/block/blk-crypto.c
> index 2d5e60023b08..046aff85cfa3 100644
> --- a/block/blk-crypto.c
> +++ b/block/blk-crypto.c
> @@ -98,7 +98,8 @@ void __bio_crypt_free_ctx(struct bio *bio)
>  void __bio_crypt_clone(struct bio *dst, struct bio *src, gfp_t gfp_mask)
>  {
>  	dst->bi_crypt_context = mempool_alloc(bio_crypt_ctx_pool, gfp_mask);
> -	*dst->bi_crypt_context = *src->bi_crypt_context;
> +	if (likely(dst->bi_crypt_context))
> +		*dst->bi_crypt_context = *src->bi_crypt_context;
>  }
>  EXPORT_SYMBOL_GPL(__bio_crypt_clone);

It's intended that __GFP_DIRECT_RECLAIM always be set here.
Do you have an example where it isn't set here?

Also, if this can indeed happen, then we need to make __bio_crypt_clone()
(and bio_crypt_clone()) return a bool (or an error code) to indicate whether it
succeeded or failed.  We can't just ignore the allocation failure.

- Eric



[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux