Re: [PATCH] ceph: fix potential NULL pointer dereference in ceph_msgpool_get

From: Ilya Dryomov
Date: Mon Jun 09 2025 - 16:52:20 EST


On Wed, May 21, 2025 at 4:38 PM Ye Chey <yechey@xxxxxxxxxxx> wrote:
>
> Add NULL check for mempool_alloc return value in ceph_msgpool_get to prevent
> potential NULL pointer dereference when memory allocation fails.

Hi Ye,

I don't see any dereference after the call to mempool_alloc() in this
function -- the pointer that is returned by mempool_alloc() is simply
propagated. The dout may log it but it's not dereferenced there.

Thanks,

Ilya

>
> Signed-off-by: Ye Chey <yechey@xxxxxxxxxxx>
> ---
> net/ceph/msgpool.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/net/ceph/msgpool.c b/net/ceph/msgpool.c
> index e3ecb80cd..e9d81c76d 100644
> --- a/net/ceph/msgpool.c
> +++ b/net/ceph/msgpool.c
> @@ -74,6 +74,10 @@ struct ceph_msg *ceph_msgpool_get(struct ceph_msgpool *pool, int front_len,
> }
>
> msg = mempool_alloc(pool->pool, GFP_NOFS);
> + if (!msg) {
> + dout("msgpool_get %s failed\n", pool->name);
> + return NULL;
> + }
> dout("msgpool_get %s %p\n", pool->name, msg);
> return msg;
> }
> --
> 2.44.0
>