Netdev List
 help / color / mirror / Atom feed
* [PATCH] libceph: potential NULL dereference in ceph_msg_data_create()
@ 2017-07-17  8:13 Dan Carpenter
  2017-07-17 13:17 ` Ilya Dryomov
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2017-07-17  8:13 UTC (permalink / raw)
  To: Ilya Dryomov, Alex Elder
  Cc: Yan, Zheng, Sage Weil, David S. Miller, ceph-devel, netdev,
	kernel-janitors

If kmem_cache_zalloc() returns NULL then the INIT_LIST_HEAD(&data->links);
will Oops.  The callers aren't really prepared for NULL returns so it
doesn't make a lot of difference in real life.

Fixes: 5240d9f95dfe ("libceph: replace message data pointer with list")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
index 0c31035bbfee..b7cc615d42ef 100644
--- a/net/ceph/messenger.c
+++ b/net/ceph/messenger.c
@@ -3203,8 +3203,10 @@ static struct ceph_msg_data *ceph_msg_data_create(enum ceph_msg_data_type type)
 		return NULL;
 
 	data = kmem_cache_zalloc(ceph_msg_data_cache, GFP_NOFS);
-	if (data)
-		data->type = type;
+	if (!data)
+		return NULL;
+
+	data->type = type;
 	INIT_LIST_HEAD(&data->links);
 
 	return data;

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] libceph: potential NULL dereference in ceph_msg_data_create()
  2017-07-17  8:13 [PATCH] libceph: potential NULL dereference in ceph_msg_data_create() Dan Carpenter
@ 2017-07-17 13:17 ` Ilya Dryomov
  0 siblings, 0 replies; 2+ messages in thread
From: Ilya Dryomov @ 2017-07-17 13:17 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Alex Elder, Yan, Zheng, Sage Weil, David S. Miller,
	Ceph Development, netdev, kernel-janitors

On Mon, Jul 17, 2017 at 10:13 AM, Dan Carpenter
<dan.carpenter@oracle.com> wrote:
> If kmem_cache_zalloc() returns NULL then the INIT_LIST_HEAD(&data->links);
> will Oops.  The callers aren't really prepared for NULL returns so it
> doesn't make a lot of difference in real life.
>
> Fixes: 5240d9f95dfe ("libceph: replace message data pointer with list")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>
> diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
> index 0c31035bbfee..b7cc615d42ef 100644
> --- a/net/ceph/messenger.c
> +++ b/net/ceph/messenger.c
> @@ -3203,8 +3203,10 @@ static struct ceph_msg_data *ceph_msg_data_create(enum ceph_msg_data_type type)
>                 return NULL;
>
>         data = kmem_cache_zalloc(ceph_msg_data_cache, GFP_NOFS);
> -       if (data)
> -               data->type = type;
> +       if (!data)
> +               return NULL;
> +
> +       data->type = type;
>         INIT_LIST_HEAD(&data->links);
>
>         return data;

Applied.

Thanks,

                Ilya

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-07-17 13:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-17  8:13 [PATCH] libceph: potential NULL dereference in ceph_msg_data_create() Dan Carpenter
2017-07-17 13:17 ` Ilya Dryomov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox