All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: "Christian A. Ehrhardt" <lk@c--e.de>
Cc: qemu-devel@nongnu.org,  Eric DeVolder <eric.devolder@oracle.com>,
	qemu-stable@nongnu.org,  "Michael S. Tsirkin" <mst@redhat.com>,
	 Igor Mammedov <imammedo@redhat.com>,
	 Ani Sinha <ani@anisinha.ca>
Subject: Re: [PATCH] hw/acpi/erst.c: Fix memset argument order
Date: Thu, 20 Oct 2022 08:14:32 +0200	[thread overview]
Message-ID: <87r0z3dnsn.fsf@pond.sub.org> (raw)
In-Reply-To: <20221019191522.1004804-1-lk@c--e.de> (Christian A. Ehrhardt's message of "Wed, 19 Oct 2022 21:15:22 +0200")

"Christian A. Ehrhardt" <lk@c--e.de> writes:

> Fix memset argument order: The second argument is
> the value, the length goes last.

Impact of the bug?

> Cc: Eric DeVolder <eric.devolder@oracle.com>
> Cc: qemu-stable@nongnu.org
> Fixes: f7e26ffa590 ("ACPI ERST: support for ACPI ERST feature")
> Signed-off-by: Christian A. Ehrhardt <lk@c--e.de>
> ---
>  hw/acpi/erst.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/acpi/erst.c b/hw/acpi/erst.c
> index df856b2669..26391f93ca 100644
> --- a/hw/acpi/erst.c
> +++ b/hw/acpi/erst.c
> @@ -716,7 +716,7 @@ static unsigned write_erst_record(ERSTDeviceState *s)
       exchange_length = memory_region_size(&s->exchange_mr);

This is the size of the exchange buffer.

Aside: it's unsigned int, but memory_region_size() returns uint64_t.
Unclean if it fits, bug if it doesn't.

       /* Validate record_offset */
       if (s->record_offset > (exchange_length - UEFI_CPER_RECORD_MIN_SIZE)) {
           return STATUS_FAILED;
       }

       /* Obtain pointer to record in the exchange buffer */
       exchange = memory_region_get_ram_ptr(&s->exchange_mr);
       exchange += s->record_offset;

       /* Validate CPER record_length */
       memcpy((uint8_t *)&record_length, &exchange[UEFI_CPER_RECORD_LENGTH_OFFSET],
           sizeof(uint32_t));

Aside: record_length = *(uint32_t *)exchange[UEFI_CPER_RECORD_LENGTH_OFFSET]
would do, since UEFI_CPER_RECORD_LENGTH_OFFSET is a multiple of 4.

       record_length = le32_to_cpu(record_length);
       if (record_length < UEFI_CPER_RECORD_MIN_SIZE) {
           return STATUS_FAILED;
       }
       if ((s->record_offset + record_length) > exchange_length) {
           return STATUS_FAILED;
       }

This ensures there are at least @record_length bytes of space left in
the exchange buffer.  Good.

       [...]
>      if (nvram) {
>          /* Write the record into the slot */
>          memcpy(nvram, exchange, record_length);

This first copies @record_length bytes into the exchange buffer.

> -        memset(nvram + record_length, exchange_length - record_length, 0xFF);
> +        memset(nvram + record_length, 0xFF, exchange_length - record_length);

The new code pads it to the full exchange buffer size.

The old code writes 0xFF bytes.

If 0xFF < exchange_length - record_length, the padding doesn't extend to
the end of the buffer.  Impact?

If 0xFF > exchange_length - record_length, we write beyond the end of
the buffer.  Impact?

>          /* If a new record, increment the record_count */
>          if (!record_found) {
>              uint32_t record_count;



  parent reply	other threads:[~2022-10-20  6:31 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-19 19:15 [PATCH] hw/acpi/erst.c: Fix memset argument order Christian A. Ehrhardt
2022-10-19 19:37 ` Philippe Mathieu-Daudé
2022-10-19 19:45   ` Eric DeVolder
2022-10-20  6:14 ` Markus Armbruster [this message]
2022-10-20 19:58   ` Christian A. Ehrhardt
2022-10-21  4:22     ` Markus Armbruster
2022-10-21  6:42       ` Christian A. Ehrhardt
2022-10-21 15:29   ` Eric DeVolder
2022-10-21 19:05 ` Alexander Bulekov
2022-10-22  5:37   ` Alexander Bulekov
2022-10-23 14:37     ` Christian A. Ehrhardt
2022-10-24 13:20       ` Alexander Bulekov
2022-10-24 14:04         ` Michael S. Tsirkin
2022-10-24 15:42           ` [PATCH v2] hw/acpi/erst.c: Fix memory handling issues Christian A. Ehrhardt
2022-10-24 16:24             ` Alexander Bulekov
2022-10-25  0:24               ` Alexander Bulekov
2022-10-24 20:34             ` Eric DeVolder
2022-10-24 20:37             ` Michael S. Tsirkin

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=87r0z3dnsn.fsf@pond.sub.org \
    --to=armbru@redhat.com \
    --cc=ani@anisinha.ca \
    --cc=eric.devolder@oracle.com \
    --cc=imammedo@redhat.com \
    --cc=lk@c--e.de \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@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.