qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Edgar E. Iglesias" <edgar.iglesias@gmail.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org,
	 Alistair Francis <alistair@alistair23.me>
Subject: Re: [PATCH for-8.0] hw/char/cadence_uart: Fix guards on invalid BRGR/BDIV settings
Date: Tue, 14 Mar 2023 19:50:57 +0100	[thread overview]
Message-ID: <CAJy5ezom5DELwTM9JAeUkL7yrftnLwm2XuWVCizKwppk_XjKiw@mail.gmail.com> (raw)
In-Reply-To: <20230314170804.1196232-1-peter.maydell@linaro.org>

[-- Attachment #1: Type: text/plain, Size: 1641 bytes --]

On Tue, Mar 14, 2023 at 6:08 PM Peter Maydell <peter.maydell@linaro.org>
wrote:

> The cadence UART attempts to avoid allowing the guset to set invalid
> baud rate register values in the uart_write() function.  However it
> does the "mask to the size of the register field" and "check for
> invalid values" in the wrong order, which means that a malicious
> guest can get a bogus value into the register by setting also some
> high bits in the value, and cause QEMU to crash by division-by-zero.
>
> Do the mask before the bounds check instead of afterwards.
>
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1493
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>

Reviewed-by: Edgar E. Iglesias <edgar@zeroasic.com>



> ---
>  hw/char/cadence_uart.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/hw/char/cadence_uart.c b/hw/char/cadence_uart.c
> index c069a30842e..807e3985419 100644
> --- a/hw/char/cadence_uart.c
> +++ b/hw/char/cadence_uart.c
> @@ -450,13 +450,15 @@ static MemTxResult uart_write(void *opaque, hwaddr
> offset,
>          }
>          break;
>      case R_BRGR: /* Baud rate generator */
> +        value &= 0xffff;
>          if (value >= 0x01) {
> -            s->r[offset] = value & 0xFFFF;
> +            s->r[offset] = value;
>          }
>          break;
>      case R_BDIV:    /* Baud rate divider */
> +        value &= 0xff;
>          if (value >= 0x04) {
> -            s->r[offset] = value & 0xFF;
> +            s->r[offset] = value;
>          }
>          break;
>      default:
> --
> 2.34.1
>
>

[-- Attachment #2: Type: text/html, Size: 2511 bytes --]

  parent reply	other threads:[~2023-03-14 18:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-14 17:08 [PATCH for-8.0] hw/char/cadence_uart: Fix guards on invalid BRGR/BDIV settings Peter Maydell
2023-03-14 17:44 ` Thomas Huth
2023-03-14 18:50 ` Edgar E. Iglesias [this message]
2023-03-14 23:35 ` Wilfred Mallawa
2023-03-15  0:04 ` Alistair Francis
2023-03-15  8:47 ` Philippe Mathieu-Daudé
2023-03-15  9:27 ` Qiang Liu

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=CAJy5ezom5DELwTM9JAeUkL7yrftnLwm2XuWVCizKwppk_XjKiw@mail.gmail.com \
    --to=edgar.iglesias@gmail.com \
    --cc=alistair@alistair23.me \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).