All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2 1/1] cadence_uart: Check baud rate generator and divider values on migration
@ 2016-11-08  0:34 Alistair Francis
  2016-11-16 22:04 ` Alistair Francis
  2016-11-28 11:31 ` Peter Maydell
  0 siblings, 2 replies; 4+ messages in thread
From: Alistair Francis @ 2016-11-08  0:34 UTC (permalink / raw)
  To: qemu-devel, peter.maydell; +Cc: alistair.francis, alistair23, pjp, psirt

The Cadence UART device emulator calculates speed by dividing the
baud rate by a 'baud rate generator' & 'baud rate divider' value.
The device specification defines these register values to be
non-zero and within certain limits. Checks were recently added when
writing to these registers but not when restoring from migration.

This patch adds checks when restoring from migration to avoid divide by
zero errors.

Reported-by: Huawei PSIRT <psirt@huawei.com>
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
---
V2:
 - Abort the migration if the data is invalid

 hw/char/cadence_uart.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/hw/char/cadence_uart.c b/hw/char/cadence_uart.c
index def34cd..9568ac6 100644
--- a/hw/char/cadence_uart.c
+++ b/hw/char/cadence_uart.c
@@ -487,6 +487,13 @@ static int cadence_uart_post_load(void *opaque, int version_id)
 {
     CadenceUARTState *s = opaque;
 
+    /* Ensure these two aren't invalid numbers */
+    if (s->r[R_BRGR] <= 1 || s->r[R_BRGR] & 0xFFFF ||
+        s->r[R_BDIV] <= 3 || s->r[R_BDIV] & 0xFF) {
+        /* Value is invalid, abort */
+        return 1;
+    }
+
     uart_parameters_setup(s);
     uart_update_status(s);
     return 0;
-- 
2.7.4

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

* Re: [Qemu-devel] [PATCH v2 1/1] cadence_uart: Check baud rate generator and divider values on migration
  2016-11-08  0:34 [Qemu-devel] [PATCH v2 1/1] cadence_uart: Check baud rate generator and divider values on migration Alistair Francis
@ 2016-11-16 22:04 ` Alistair Francis
  2016-11-28 11:31 ` Peter Maydell
  1 sibling, 0 replies; 4+ messages in thread
From: Alistair Francis @ 2016-11-16 22:04 UTC (permalink / raw)
  To: Alistair Francis
  Cc: qemu-devel@nongnu.org Developers, Peter Maydell, Prasad J Pandit,
	Huawei PSIRT

On Mon, Nov 7, 2016 at 4:34 PM, Alistair Francis
<alistair.francis@xilinx.com> wrote:
> The Cadence UART device emulator calculates speed by dividing the
> baud rate by a 'baud rate generator' & 'baud rate divider' value.
> The device specification defines these register values to be
> non-zero and within certain limits. Checks were recently added when
> writing to these registers but not when restoring from migration.
>
> This patch adds checks when restoring from migration to avoid divide by
> zero errors.

Ping!

Thanks,

Alistair

>
> Reported-by: Huawei PSIRT <psirt@huawei.com>
> Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
> ---
> V2:
>  - Abort the migration if the data is invalid
>
>  hw/char/cadence_uart.c | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/hw/char/cadence_uart.c b/hw/char/cadence_uart.c
> index def34cd..9568ac6 100644
> --- a/hw/char/cadence_uart.c
> +++ b/hw/char/cadence_uart.c
> @@ -487,6 +487,13 @@ static int cadence_uart_post_load(void *opaque, int version_id)
>  {
>      CadenceUARTState *s = opaque;
>
> +    /* Ensure these two aren't invalid numbers */
> +    if (s->r[R_BRGR] <= 1 || s->r[R_BRGR] & 0xFFFF ||
> +        s->r[R_BDIV] <= 3 || s->r[R_BDIV] & 0xFF) {
> +        /* Value is invalid, abort */
> +        return 1;
> +    }
> +
>      uart_parameters_setup(s);
>      uart_update_status(s);
>      return 0;
> --
> 2.7.4
>

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

* Re: [Qemu-devel] [PATCH v2 1/1] cadence_uart: Check baud rate generator and divider values on migration
  2016-11-08  0:34 [Qemu-devel] [PATCH v2 1/1] cadence_uart: Check baud rate generator and divider values on migration Alistair Francis
  2016-11-16 22:04 ` Alistair Francis
@ 2016-11-28 11:31 ` Peter Maydell
  2016-11-28 23:15   ` Alistair Francis
  1 sibling, 1 reply; 4+ messages in thread
From: Peter Maydell @ 2016-11-28 11:31 UTC (permalink / raw)
  To: Alistair Francis
  Cc: QEMU Developers, Alistair Francis, Prasad J Pandit, Huawei PSIRT

On 8 November 2016 at 00:34, Alistair Francis
<alistair.francis@xilinx.com> wrote:
> The Cadence UART device emulator calculates speed by dividing the
> baud rate by a 'baud rate generator' & 'baud rate divider' value.
> The device specification defines these register values to be
> non-zero and within certain limits. Checks were recently added when
> writing to these registers but not when restoring from migration.
>
> This patch adds checks when restoring from migration to avoid divide by
> zero errors.
>
> Reported-by: Huawei PSIRT <psirt@huawei.com>
> Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
> ---
> V2:
>  - Abort the migration if the data is invalid
>
>  hw/char/cadence_uart.c | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/hw/char/cadence_uart.c b/hw/char/cadence_uart.c
> index def34cd..9568ac6 100644
> --- a/hw/char/cadence_uart.c
> +++ b/hw/char/cadence_uart.c
> @@ -487,6 +487,13 @@ static int cadence_uart_post_load(void *opaque, int version_id)
>  {
>      CadenceUARTState *s = opaque;
>
> +    /* Ensure these two aren't invalid numbers */
> +    if (s->r[R_BRGR] <= 1 || s->r[R_BRGR] & 0xFFFF ||
> +        s->r[R_BDIV] <= 3 || s->r[R_BDIV] & 0xFF) {
> +        /* Value is invalid, abort */
> +        return 1;
> +    }

The "s->r[R_BRGR] & 0xFFFF" and "s->r[R_BDIV] & 0xFF" checks
look wrong -- it's ok for the low bits to be set, it's only
if high bits are set that we want to abort the migration.
Missing '~'s ? (I'm surprised this bug doesn't cause migration
to fail every time.)

thanks
-- PMM

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

* Re: [Qemu-devel] [PATCH v2 1/1] cadence_uart: Check baud rate generator and divider values on migration
  2016-11-28 11:31 ` Peter Maydell
@ 2016-11-28 23:15   ` Alistair Francis
  0 siblings, 0 replies; 4+ messages in thread
From: Alistair Francis @ 2016-11-28 23:15 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Alistair Francis, QEMU Developers, Prasad J Pandit, Huawei PSIRT

On Mon, Nov 28, 2016 at 3:31 AM, Peter Maydell <peter.maydell@linaro.org> wrote:
> On 8 November 2016 at 00:34, Alistair Francis
> <alistair.francis@xilinx.com> wrote:
>> The Cadence UART device emulator calculates speed by dividing the
>> baud rate by a 'baud rate generator' & 'baud rate divider' value.
>> The device specification defines these register values to be
>> non-zero and within certain limits. Checks were recently added when
>> writing to these registers but not when restoring from migration.
>>
>> This patch adds checks when restoring from migration to avoid divide by
>> zero errors.
>>
>> Reported-by: Huawei PSIRT <psirt@huawei.com>
>> Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
>> ---
>> V2:
>>  - Abort the migration if the data is invalid
>>
>>  hw/char/cadence_uart.c | 7 +++++++
>>  1 file changed, 7 insertions(+)
>>
>> diff --git a/hw/char/cadence_uart.c b/hw/char/cadence_uart.c
>> index def34cd..9568ac6 100644
>> --- a/hw/char/cadence_uart.c
>> +++ b/hw/char/cadence_uart.c
>> @@ -487,6 +487,13 @@ static int cadence_uart_post_load(void *opaque, int version_id)
>>  {
>>      CadenceUARTState *s = opaque;
>>
>> +    /* Ensure these two aren't invalid numbers */
>> +    if (s->r[R_BRGR] <= 1 || s->r[R_BRGR] & 0xFFFF ||
>> +        s->r[R_BDIV] <= 3 || s->r[R_BDIV] & 0xFF) {
>> +        /* Value is invalid, abort */
>> +        return 1;
>> +    }
>
> The "s->r[R_BRGR] & 0xFFFF" and "s->r[R_BDIV] & 0xFF" checks
> look wrong -- it's ok for the low bits to be set, it's only
> if high bits are set that we want to abort the migration.
> Missing '~'s ? (I'm surprised this bug doesn't cause migration
> to fail every time.)

Yep, you are right. Those are wrong. I'll fix them up.

I didn't have a migration test case to work with. I will set something
up this time to make sure something like that doesn't slip though.

Thanks,

Alistair

>
> thanks
> -- PMM

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

end of thread, other threads:[~2016-11-28 23:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-08  0:34 [Qemu-devel] [PATCH v2 1/1] cadence_uart: Check baud rate generator and divider values on migration Alistair Francis
2016-11-16 22:04 ` Alistair Francis
2016-11-28 11:31 ` Peter Maydell
2016-11-28 23:15   ` Alistair Francis

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.