All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Elder <elder@dreamhost.com>
To: Xi Wang <xi.wang@gmail.com>
Cc: Sage Weil <sage@newdream.net>, ceph-devel@vger.kernel.org
Subject: Re: [PATCH v2 1/3] libceph: fix overflow in __decode_pool_names()
Date: Wed, 06 Jun 2012 11:26:07 -0500	[thread overview]
Message-ID: <4FCF849F.7000704@dreamhost.com> (raw)
In-Reply-To: <4F9CE8A0.80306@gmail.com>

On 04/29/2012 02:07 AM, Xi Wang wrote:
> `len' is read from network and thus needs validation.  Otherwise a
> large `len' would cause out-of-bounds access via the memcpy() call.
> In addition, len = 0xffffffff would overflow the kmalloc() size,
> leading to out-of-bounds write.
> 
> This patch adds a check of `len' via ceph_decode_need().  Also use
> kstrndup rather than kmalloc/memcpy.

This looks good, however I'd like to correct one thing, and fix
another (both noted below) before committing.  Please confirm/ack my
suggested change; I'll still credit you with the original patch.
Thanks.

					-Alex

> Signed-off-by: Xi Wang <xi.wang@gmail.com>
> ---
> Subject corrected.  Sorry, my bad.
> ---
>  net/ceph/osdmap.c |    9 +++------
>  1 files changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c
> index 29ad46e..f80afc3 100644
> --- a/net/ceph/osdmap.c
> +++ b/net/ceph/osdmap.c
> @@ -495,15 +495,12 @@ static int __decode_pool_names(void **p, void *end, struct ceph_osdmap *map)
>  		ceph_decode_32_safe(p, end, pool, bad);
>  		ceph_decode_32_safe(p, end, len, bad);
>  		dout("  pool %d len %d\n", pool, len);
> +		ceph_decode_need(p, end, len, bad);
>  		pi = __lookup_pg_pool(&map->pg_pools, pool);
>  		if (pi) {
>  			kfree(pi->name);
> -			pi->name = kmalloc(len + 1, GFP_NOFS);
> -			if (pi->name) {
> -				memcpy(pi->name, *p, len);
> -				pi->name[len] = '\0';
> -				dout("  name is %s\n", pi->name);
> -			}
> +			pi->name = kstrndup(*p, len, GFP_NOFS);
> +			dout("  name is %s\n", pi->name);

Instead:
		if (pi) {
			char *name = kstrndup(*p, len, GFP_NOFS);

			if (!name)
				return -ENOMEM;
			kfree(pi->name);
			pi->name = name;
			dout("  name is %s\n", pi->name);
		}

>  		}
>  		*p += len;
>  	}


  reply	other threads:[~2012-06-06 16:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-29  6:59 [PATCH 1/3] ligceph: fix overflow in __decode_pool_names() Xi Wang
2012-04-29  6:59 ` [PATCH 2/3] libceph: fix overflow in osdmap_decode() Xi Wang
2012-06-06 16:26   ` Alex Elder
2012-06-06 17:56     ` Xi Wang
2012-06-06 19:14       ` Alex Elder
2012-06-06 19:20         ` Xi Wang
2012-04-29  6:59 ` [PATCH 3/3] libceph: fix overflow in osdmap_apply_incremental() Xi Wang
2012-06-06 16:26   ` Alex Elder
2012-04-29  7:07 ` [PATCH v2 1/3] libceph: fix overflow in __decode_pool_names() Xi Wang
2012-06-06 16:26   ` Alex Elder [this message]
2012-06-06 17:54     ` Xi Wang
2012-06-06 19:14       ` Alex Elder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4FCF849F.7000704@dreamhost.com \
    --to=elder@dreamhost.com \
    --cc=ceph-devel@vger.kernel.org \
    --cc=elder@inktank.com \
    --cc=sage@newdream.net \
    --cc=xi.wang@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.