Message ID | 20250102083319.176310-1-haoxiang_li2024@163.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | blk-crypto: Add check for mempool_alloc() | expand |
On Thu, Jan 02, 2025 at 04:33:19PM +0800, Haoxiang Li wrote: > Add check for the return value of mempool_alloc() to > catch the potential exception and avoid null pointer > dereference. > > Fixes: 488f6682c832 ("block: blk-crypto-fallback for Inline Encryption") > Cc: stable@vger.kernel.org > Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com> > --- > block/blk-crypto-fallback.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/block/blk-crypto-fallback.c b/block/blk-crypto-fallback.c > index 29a205482617..47acd7a48767 100644 > --- a/block/blk-crypto-fallback.c > +++ b/block/blk-crypto-fallback.c > @@ -514,6 +514,12 @@ bool blk_crypto_fallback_bio_prep(struct bio **bio_ptr) > * bi_end_io appropriately to trigger decryption when the bio is ended. > */ > f_ctx = mempool_alloc(bio_fallback_crypt_ctx_pool, GFP_NOIO); > + > + if (!f_ctx) { > + bio->bi_status = BLK_STS_RESOURCE; > + return false; > + } mempool_alloc() with a mask that includes ___GFP_DIRECT_RECLAIM, such as the GFP_NOIO which is used here, never returns NULL. - Eric
diff --git a/block/blk-crypto-fallback.c b/block/blk-crypto-fallback.c index 29a205482617..47acd7a48767 100644 --- a/block/blk-crypto-fallback.c +++ b/block/blk-crypto-fallback.c @@ -514,6 +514,12 @@ bool blk_crypto_fallback_bio_prep(struct bio **bio_ptr) * bi_end_io appropriately to trigger decryption when the bio is ended. */ f_ctx = mempool_alloc(bio_fallback_crypt_ctx_pool, GFP_NOIO); + + if (!f_ctx) { + bio->bi_status = BLK_STS_RESOURCE; + return false; + } + f_ctx->crypt_ctx = *bc; f_ctx->crypt_iter = bio->bi_iter; f_ctx->bi_private_orig = bio->bi_private;
Add check for the return value of mempool_alloc() to catch the potential exception and avoid null pointer dereference. Fixes: 488f6682c832 ("block: blk-crypto-fallback for Inline Encryption") Cc: stable@vger.kernel.org Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com> --- block/blk-crypto-fallback.c | 6 ++++++ 1 file changed, 6 insertions(+)