From: Paolo Bonzini <pbonzini@redhat.com>
To: Gonglei <arei.gonglei@huawei.com>, qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org
Subject: Re: [Qemu-trivial] [PATCH 2/6] sheepdog: fix possible resouce leak and out-of-bounds access
Date: Thu, 3 Mar 2016 12:17:43 +0100 [thread overview]
Message-ID: <56D81D57.4040605@redhat.com> (raw)
In-Reply-To: <1456998223-12356-3-git-send-email-arei.gonglei@huawei.com>
On 03/03/2016 10:43, Gonglei wrote:
> CID 1352418 (#1 of 1): Out-of-bounds access (INCOMPATIBLE_CAST)
> incompatible_cast: Pointer &snap_id points to an object whose effective
> type is unsigned int (32 bits, unsigned) but is dereferenced as a wider
> unsigned long (64 bits, unsigned). This may lead to memory corruption.
>
> We also need to free local_err when ret is not equals to 0.
>
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
> block/sheepdog.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/block/sheepdog.c b/block/sheepdog.c
> index 8739acc..3d81bba 100644
> --- a/block/sheepdog.c
> +++ b/block/sheepdog.c
> @@ -2543,7 +2543,7 @@ static int sd_snapshot_delete(BlockDriverState *bs,
> const char *name,
> Error **errp)
> {
> - uint32_t snap_id = 0;
> + unsigned long snap_id = 0;
> char snap_tag[SD_MAX_VDI_TAG_LEN];
> Error *local_err = NULL;
> int fd, ret;
> @@ -2565,20 +2565,23 @@ static int sd_snapshot_delete(BlockDriverState *bs,
> memset(buf, 0, sizeof(buf));
> memset(snap_tag, 0, sizeof(snap_tag));
> pstrcpy(buf, SD_MAX_VDI_LEN, s->name);
> - if (qemu_strtoul(snapshot_id, NULL, 10, (unsigned long *)&snap_id)) {
> + if (qemu_strtoul(snapshot_id, NULL, 10, &snap_id)) {
> return -1;
> }
>
> if (snap_id) {
> + assert(snap_id <= UINT_MAX);
> +
> hdr.snapid = snap_id;
> } else {
> pstrcpy(snap_tag, sizeof(snap_tag), snapshot_id);
> pstrcpy(buf + SD_MAX_VDI_LEN, SD_MAX_VDI_TAG_LEN, snap_tag);
> }
>
> - ret = find_vdi_name(s, s->name, snap_id, snap_tag, &vid, true,
> + ret = find_vdi_name(s, s->name, hdr.snapid, snap_tag, &vid, true,
> &local_err);
> if (ret) {
> + error_report_err(local_err);
> return ret;
> }
>
>
A patch for this has been posted yesterday by Jeff Cody.
Paolo
WARNING: multiple messages have this Message-ID (diff)
From: Paolo Bonzini <pbonzini@redhat.com>
To: Gonglei <arei.gonglei@huawei.com>, qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 2/6] sheepdog: fix possible resouce leak and out-of-bounds access
Date: Thu, 3 Mar 2016 12:17:43 +0100 [thread overview]
Message-ID: <56D81D57.4040605@redhat.com> (raw)
In-Reply-To: <1456998223-12356-3-git-send-email-arei.gonglei@huawei.com>
On 03/03/2016 10:43, Gonglei wrote:
> CID 1352418 (#1 of 1): Out-of-bounds access (INCOMPATIBLE_CAST)
> incompatible_cast: Pointer &snap_id points to an object whose effective
> type is unsigned int (32 bits, unsigned) but is dereferenced as a wider
> unsigned long (64 bits, unsigned). This may lead to memory corruption.
>
> We also need to free local_err when ret is not equals to 0.
>
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
> block/sheepdog.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/block/sheepdog.c b/block/sheepdog.c
> index 8739acc..3d81bba 100644
> --- a/block/sheepdog.c
> +++ b/block/sheepdog.c
> @@ -2543,7 +2543,7 @@ static int sd_snapshot_delete(BlockDriverState *bs,
> const char *name,
> Error **errp)
> {
> - uint32_t snap_id = 0;
> + unsigned long snap_id = 0;
> char snap_tag[SD_MAX_VDI_TAG_LEN];
> Error *local_err = NULL;
> int fd, ret;
> @@ -2565,20 +2565,23 @@ static int sd_snapshot_delete(BlockDriverState *bs,
> memset(buf, 0, sizeof(buf));
> memset(snap_tag, 0, sizeof(snap_tag));
> pstrcpy(buf, SD_MAX_VDI_LEN, s->name);
> - if (qemu_strtoul(snapshot_id, NULL, 10, (unsigned long *)&snap_id)) {
> + if (qemu_strtoul(snapshot_id, NULL, 10, &snap_id)) {
> return -1;
> }
>
> if (snap_id) {
> + assert(snap_id <= UINT_MAX);
> +
> hdr.snapid = snap_id;
> } else {
> pstrcpy(snap_tag, sizeof(snap_tag), snapshot_id);
> pstrcpy(buf + SD_MAX_VDI_LEN, SD_MAX_VDI_TAG_LEN, snap_tag);
> }
>
> - ret = find_vdi_name(s, s->name, snap_id, snap_tag, &vid, true,
> + ret = find_vdi_name(s, s->name, hdr.snapid, snap_tag, &vid, true,
> &local_err);
> if (ret) {
> + error_report_err(local_err);
> return ret;
> }
>
>
A patch for this has been posted yesterday by Jeff Cody.
Paolo
next prev parent reply other threads:[~2016-03-03 11:17 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-03 9:43 [Qemu-trivial] [PATCH 0/6] fix some coverity complains Gonglei
2016-03-03 9:43 ` [Qemu-devel] " Gonglei
2016-03-03 9:43 ` [Qemu-trivial] [PATCH 1/6] egl-helpers: fix possible resource leak Gonglei
2016-03-03 9:43 ` [Qemu-devel] " Gonglei
2016-03-03 11:19 ` [Qemu-trivial] " Paolo Bonzini
2016-03-03 11:19 ` [Qemu-devel] " Paolo Bonzini
2016-05-10 6:02 ` [Qemu-trivial] " Gonglei (Arei)
2016-05-10 6:02 ` [Qemu-devel] " Gonglei (Arei)
2016-03-03 9:43 ` [Qemu-trivial] [PATCH 2/6] sheepdog: fix possible resouce leak and out-of-bounds access Gonglei
2016-03-03 9:43 ` [Qemu-devel] " Gonglei
2016-03-03 11:17 ` Paolo Bonzini [this message]
2016-03-03 11:17 ` Paolo Bonzini
2016-03-03 12:00 ` [Qemu-trivial] " Gonglei (Arei)
2016-03-03 12:00 ` [Qemu-devel] " Gonglei (Arei)
2016-03-03 12:12 ` [Qemu-trivial] " Paolo Bonzini
2016-03-03 12:12 ` [Qemu-devel] " Paolo Bonzini
2016-03-03 12:35 ` [Qemu-trivial] " Gonglei (Arei)
2016-03-03 12:35 ` [Qemu-devel] " Gonglei (Arei)
2016-03-03 9:43 ` [Qemu-trivial] [PATCH 3/6] spice: fix coverity complains Gonglei
2016-03-03 9:43 ` [Qemu-devel] " Gonglei
2016-03-03 11:19 ` [Qemu-trivial] " Paolo Bonzini
2016-03-03 11:19 ` [Qemu-devel] " Paolo Bonzini
2016-05-10 5:59 ` [Qemu-trivial] " Gonglei (Arei)
2016-05-10 5:59 ` [Qemu-devel] " Gonglei (Arei)
2016-03-03 9:43 ` [Qemu-trivial] [PATCH 4/6] hostmem-file: fix memory leak Gonglei
2016-03-03 9:43 ` [Qemu-devel] " Gonglei
2016-03-03 11:19 ` [Qemu-trivial] " Paolo Bonzini
2016-03-03 11:19 ` [Qemu-devel] " Paolo Bonzini
2016-03-03 9:43 ` [Qemu-trivial] [PATCH 5/6] spapr: fix possible Negative array index read Gonglei
2016-03-03 9:43 ` [Qemu-devel] " Gonglei
2016-03-03 11:19 ` [Qemu-trivial] " Paolo Bonzini
2016-03-03 11:19 ` [Qemu-devel] " Paolo Bonzini
2016-03-03 9:43 ` [Qemu-trivial] [PATCH 6/6] smbus: fix memory leak Gonglei
2016-03-03 9:43 ` [Qemu-devel] " Gonglei
2016-03-03 11:19 ` [Qemu-trivial] " Paolo Bonzini
2016-03-03 11:19 ` [Qemu-devel] " Paolo Bonzini
2016-03-03 12:05 ` [Qemu-trivial] " Gonglei (Arei)
2016-03-03 12:05 ` [Qemu-devel] " Gonglei (Arei)
2016-04-06 2:12 ` [Qemu-trivial] [PATCH 0/6] fix some coverity complains Gonglei (Arei)
2016-04-06 2:12 ` [Qemu-devel] " Gonglei (Arei)
2016-04-06 6:30 ` [Qemu-trivial] " Paolo Bonzini
2016-04-06 6:30 ` [Qemu-devel] " Paolo Bonzini
2016-04-06 6:31 ` [Qemu-trivial] " Paolo Bonzini
2016-04-06 6:31 ` [Qemu-devel] " Paolo Bonzini
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=56D81D57.4040605@redhat.com \
--to=pbonzini@redhat.com \
--cc=arei.gonglei@huawei.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
/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.