* [PATCH] blk-crypto: Add check for mempool_alloc()
@ 2025-01-02 8:33 Haoxiang Li
2025-01-02 17:23 ` Eric Biggers
0 siblings, 1 reply; 2+ messages in thread
From: Haoxiang Li @ 2025-01-02 8:33 UTC (permalink / raw)
To: axboe, satyat, ebiggers; +Cc: linux-block, linux-kernel, Haoxiang Li, stable
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;
+ }
+
f_ctx->crypt_ctx = *bc;
f_ctx->crypt_iter = bio->bi_iter;
f_ctx->bi_private_orig = bio->bi_private;
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] blk-crypto: Add check for mempool_alloc()
2025-01-02 8:33 [PATCH] blk-crypto: Add check for mempool_alloc() Haoxiang Li
@ 2025-01-02 17:23 ` Eric Biggers
0 siblings, 0 replies; 2+ messages in thread
From: Eric Biggers @ 2025-01-02 17:23 UTC (permalink / raw)
To: Haoxiang Li; +Cc: axboe, satyat, linux-block, linux-kernel, stable
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-01-02 17:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-02 8:33 [PATCH] blk-crypto: Add check for mempool_alloc() Haoxiang Li
2025-01-02 17:23 ` Eric Biggers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).