block: Fix potential NULL pointer dereference in __bio_crypt_clone()
Quoted 10 lines · Eric Biggers
Quoted 6 lines · Miaohe Lin
mempool_alloc()may return NULL if__GFP_DIRECT_RECLAIMis not set ingfp_maskunder memory pressure. So we should check the return value ofmempool_alloc()against NULL before dereference.Fixes a892c8d52c02 ("block: Inline encryption support for blk-mq")Signed-off-by Miaohe Lin <[email protected]>It's intended that
__GFP_DIRECT_RECLAIMalways be set here. Do you have an example where it isn't set here?
map_request() only pass GFP_ATOMIC to gfp_mask, though bio crypt is not used yet.
Quoted 3 lines
Also, if this can indeed happen, then we need to make
__bio_crypt_clone()(andbio_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
IMO, just the allocation failure is ok or we would break KABI. Many thanks.
Quoted 12 lines · linmiaohe
Quoted 10 lines · Eric Biggers
Quoted 6 lines · Miaohe Lin
mempool_alloc()may return NULL if__GFP_DIRECT_RECLAIMis not set ingfp_maskunder memory pressure. So we should check the return value ofmempool_alloc()against NULL before dereference.Fixes a892c8d52c02 ("block: Inline encryption support for blk-mq")Signed-off-by Miaohe Lin <[email protected]>It's intended that
__GFP_DIRECT_RECLAIMalways be set here. Do you have an example where it isn't set here?
Quoted 9 lines
map_request()only passGFP_ATOMICtogfp_mask, though bio crypt is not used yet.Quoted 3 lines
Also, if this can indeed happen, then we need to make
__bio_crypt_clone()(andbio_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
IMO, just the allocation failure is ok or we would break KABI. Many thanks.
Ignoring the allocation failure isn't okay, since it would cause encrypted I/O to fall back to unencrypted I/O, which would cause data corruption.
Also, upstream doesn't have a stable KABI.
I sent out a patch with what I have in mind; can you take a look?
https://lkml.kernel.org/r/[email protected]
- Eric