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

Ye Chey posted 1 patch 6 months, 3 weeks ago
net/ceph/msgpool.c | 4 ++++
1 file changed, 4 insertions(+)
[PATCH] ceph: fix potential NULL pointer dereference in ceph_msgpool_get
Posted by Ye Chey 6 months, 3 weeks ago
Add NULL check for mempool_alloc return value in ceph_msgpool_get to prevent
potential NULL pointer dereference when memory allocation fails.

Signed-off-by: Ye Chey <yechey@ai-sast.com>
---
 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
Re: [PATCH] ceph: fix potential NULL pointer dereference in ceph_msgpool_get
Posted by Ilya Dryomov 6 months, 1 week ago
On Wed, May 21, 2025 at 4:38 PM Ye Chey <yechey@ai-sast.com> 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@ai-sast.com>
> ---
>  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
>