All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dmg: avoid out-of-bounds memory load in dmg_read_mish_block()
@ 2026-10-13 19:37 Stefan Hajnoczi
  2026-10-13 20:22 ` Eric Blake
  0 siblings, 1 reply; 2+ messages in thread
From: Stefan Hajnoczi @ 2026-10-13 19:37 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, qemu-block, Stefan Hajnoczi, Hanna Reitz

dmg_read_mish_block() loads from memory beyond the end of the buffer
when count is less than 4.

There is no known security impact here because dmg_read_mish_block()
returns almost immediately without any opportunity to gain control of
execution or cause other damage. A crash will not happen because it's a
32-bit load from a memory address that was just heap allocated. The
address will be properly aligned and will not span a page of memory.

Reported-by: router0mail <https://gitlab.com/router0mail>
Fixes: 7aee37b93a4f ("block/dmg: process a buffer instead of reading ints")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4569
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 block/dmg.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/block/dmg.c b/block/dmg.c
index 5d7d3b8901f..412d4bfc354 100644
--- a/block/dmg.c
+++ b/block/dmg.c
@@ -226,9 +226,13 @@ static int dmg_read_mish_block(BDRVDMGState *s, DmgHeaderState *ds,
     uint64_t in_offset = ds->data_fork_offset;
     uint64_t out_offset;
 
+    if (count < 244) {
+        return 0; /* too small, skip silently */
+    }
+
     type = buff_read_uint32(buffer, offset);
-    /* skip data that is not a valid MISH block (invalid magic or too small) */
-    if (type != 0x6d697368 || count < 244) {
+    /* skip data that is not a valid MISH block (invalid magic) */
+    if (type != 0x6d697368) {
         /* assume success for now */
         return 0;
     }
-- 
2.56.0



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

* Re: [PATCH] dmg: avoid out-of-bounds memory load in dmg_read_mish_block()
  2026-10-13 19:37 [PATCH] dmg: avoid out-of-bounds memory load in dmg_read_mish_block() Stefan Hajnoczi
@ 2026-10-13 20:22 ` Eric Blake
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Blake @ 2026-10-13 20:22 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: qemu-devel, Kevin Wolf, qemu-block, Hanna Reitz

On Tue, Oct 13, 2026 at 03:37:08PM -0400, Stefan Hajnoczi wrote:
> dmg_read_mish_block() loads from memory beyond the end of the buffer
> when count is less than 4.
> 
> There is no known security impact here because dmg_read_mish_block()
> returns almost immediately without any opportunity to gain control of
> execution or cause other damage. A crash will not happen because it's a
> 32-bit load from a memory address that was just heap allocated. The
> address will be properly aligned and will not span a page of memory.
> 
> Reported-by: router0mail <https://gitlab.com/router0mail>
> Fixes: 7aee37b93a4f ("block/dmg: process a buffer instead of reading ints")
> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4569
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  block/dmg.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/block/dmg.c b/block/dmg.c
> index 5d7d3b8901f..412d4bfc354 100644
> --- a/block/dmg.c
> +++ b/block/dmg.c
> @@ -226,9 +226,13 @@ static int dmg_read_mish_block(BDRVDMGState *s, DmgHeaderState *ds,
>      uint64_t in_offset = ds->data_fork_offset;
>      uint64_t out_offset;
>  
> +    if (count < 244) {
> +        return 0; /* too small, skip silently */
> +    }
> +
>      type = buff_read_uint32(buffer, offset);
> -    /* skip data that is not a valid MISH block (invalid magic or too small) */
> -    if (type != 0x6d697368 || count < 244) {
> +    /* skip data that is not a valid MISH block (invalid magic) */
> +    if (type != 0x6d697368) {
>          /* assume success for now */
>          return 0;
>      }

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org



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

end of thread, other threads:[~2026-10-13 20:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-13 19:37 [PATCH] dmg: avoid out-of-bounds memory load in dmg_read_mish_block() Stefan Hajnoczi
2026-10-13 20:22 ` Eric Blake

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.