diff mbox

libceph: potential NULL dereference in ceph_msg_data_create()

Message ID 20170717081335.3hhaj2k2frpq7gfa@mwanda (mailing list archive)
State New, archived
Headers show

Commit Message

Dan Carpenter July 17, 2017, 8:13 a.m. UTC
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>

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Ilya Dryomov July 17, 2017, 1:17 p.m. UTC | #1
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
--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

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;