* [PATCH-for-7.1] hw/tpm/tpm_tis: Avoid eventual read overrun
@ 2022-03-30 23:57 Philippe Mathieu-Daudé
2022-03-31 7:50 ` Marc-André Lureau
0 siblings, 1 reply; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2022-03-30 23:57 UTC (permalink / raw)
To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Stefan Berger
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
The TPMState structure hold an array of TPM_TIS_NUM_LOCALITIES
TPMLocality loc[], having TPM_TIS_NUM_LOCALITIES defined as '5'.
tpm_tis_locality_from_addr() returns up to 3 bits, so 7.
While unlikely, Coverity is right to report an overrun. Assert
we are in range to fix:
*** CID 1487240: Memory - illegal accesses (OVERRUN)
hw/tpm/tpm_tis_common.c: 298 in tpm_tis_dump_state()
294 int idx;
295 uint8_t locty = tpm_tis_locality_from_addr(addr);
296 hwaddr base = addr & ~0xfff;
297
>>> CID 1487240: Memory - illegal accesses (OVERRUN)
>>> Overrunning array "s->loc" of 5 24-byte elements at element index 7 (byte offset 191) using index "locty" (which evaluates to 7).
298 printf("tpm_tis: active locality : %d\n"
299 "tpm_tis: state of locality %d : %d\n"
300 "tpm_tis: register dump:\n",
301 s->active_locty,
302 locty, s->loc[locty].state);
Fixes: Coverity CID 1487240
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
hw/tpm/tpm_tis_common.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/hw/tpm/tpm_tis_common.c b/hw/tpm/tpm_tis_common.c
index e700d82181..5b1055033e 100644
--- a/hw/tpm/tpm_tis_common.c
+++ b/hw/tpm/tpm_tis_common.c
@@ -295,6 +295,7 @@ static void tpm_tis_dump_state(TPMState *s, hwaddr addr)
uint8_t locty = tpm_tis_locality_from_addr(addr);
hwaddr base = addr & ~0xfff;
+ assert(TPM_TIS_IS_VALID_LOCTY(locty));
printf("tpm_tis: active locality : %d\n"
"tpm_tis: state of locality %d : %d\n"
"tpm_tis: register dump:\n",
--
2.35.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH-for-7.1] hw/tpm/tpm_tis: Avoid eventual read overrun
2022-03-30 23:57 [PATCH-for-7.1] hw/tpm/tpm_tis: Avoid eventual read overrun Philippe Mathieu-Daudé
@ 2022-03-31 7:50 ` Marc-André Lureau
2022-03-31 10:42 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 3+ messages in thread
From: Marc-André Lureau @ 2022-03-31 7:50 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: Stefan Berger, QEMU, Philippe Mathieu-Daudé
[-- Attachment #1: Type: text/plain, Size: 2104 bytes --]
Hi
On Thu, Mar 31, 2022 at 4:02 AM Philippe Mathieu-Daudé <
philippe.mathieu.daude@gmail.com> wrote:
> From: Philippe Mathieu-Daudé <f4bug@amsat.org>
>
> The TPMState structure hold an array of TPM_TIS_NUM_LOCALITIES
> TPMLocality loc[], having TPM_TIS_NUM_LOCALITIES defined as '5'.
>
> tpm_tis_locality_from_addr() returns up to 3 bits, so 7.
>
> While unlikely, Coverity is right to report an overrun. Assert
> we are in range to fix:
>
> *** CID 1487240: Memory - illegal accesses (OVERRUN)
> hw/tpm/tpm_tis_common.c: 298 in tpm_tis_dump_state()
> 294 int idx;
> 295 uint8_t locty = tpm_tis_locality_from_addr(addr);
> 296 hwaddr base = addr & ~0xfff;
> 297
> >>> CID 1487240: Memory - illegal accesses (OVERRUN)
> >>> Overrunning array "s->loc" of 5 24-byte elements at element
> index 7 (byte offset 191) using index "locty" (which evaluates to 7).
> 298 printf("tpm_tis: active locality : %d\n"
> 299 "tpm_tis: state of locality %d : %d\n"
> 300 "tpm_tis: register dump:\n",
> 301 s->active_locty,
> 302 locty, s->loc[locty].state);
>
> Fixes: Coverity CID 1487240
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>
Maybe that assert should be in tpm_tis_locality_from_addr(), as various
callers could produce the same report.
---
> hw/tpm/tpm_tis_common.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/hw/tpm/tpm_tis_common.c b/hw/tpm/tpm_tis_common.c
> index e700d82181..5b1055033e 100644
> --- a/hw/tpm/tpm_tis_common.c
> +++ b/hw/tpm/tpm_tis_common.c
> @@ -295,6 +295,7 @@ static void tpm_tis_dump_state(TPMState *s, hwaddr
> addr)
> uint8_t locty = tpm_tis_locality_from_addr(addr);
> hwaddr base = addr & ~0xfff;
>
> + assert(TPM_TIS_IS_VALID_LOCTY(locty));
> printf("tpm_tis: active locality : %d\n"
> "tpm_tis: state of locality %d : %d\n"
> "tpm_tis: register dump:\n",
> --
> 2.35.1
>
>
>
--
Marc-André Lureau
[-- Attachment #2: Type: text/html, Size: 3190 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH-for-7.1] hw/tpm/tpm_tis: Avoid eventual read overrun
2022-03-31 7:50 ` Marc-André Lureau
@ 2022-03-31 10:42 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2022-03-31 10:42 UTC (permalink / raw)
To: Marc-André Lureau, Stefan Berger; +Cc: QEMU, Philippe Mathieu-Daudé
On 31/3/22 09:50, Marc-André Lureau wrote:
> Hi
>
> On Thu, Mar 31, 2022 at 4:02 AM Philippe Mathieu-Daudé
> <philippe.mathieu.daude@gmail.com
> <mailto:philippe.mathieu.daude@gmail.com>> wrote:
>
> From: Philippe Mathieu-Daudé <f4bug@amsat.org <mailto:f4bug@amsat.org>>
>
> The TPMState structure hold an array of TPM_TIS_NUM_LOCALITIES
> TPMLocality loc[], having TPM_TIS_NUM_LOCALITIES defined as '5'.
>
> tpm_tis_locality_from_addr() returns up to 3 bits, so 7.
>
> While unlikely, Coverity is right to report an overrun. Assert
> we are in range to fix:
>
> *** CID 1487240: Memory - illegal accesses (OVERRUN)
> hw/tpm/tpm_tis_common.c: 298 in tpm_tis_dump_state()
> 294 int idx;
> 295 uint8_t locty = tpm_tis_locality_from_addr(addr);
> 296 hwaddr base = addr & ~0xfff;
> 297
> >>> CID 1487240: Memory - illegal accesses (OVERRUN)
> >>> Overrunning array "s->loc" of 5 24-byte elements at
> element index 7 (byte offset 191) using index "locty" (which
> evaluates to 7).
> 298 printf("tpm_tis: active locality : %d\n"
> 299 "tpm_tis: state of locality %d : %d\n"
> 300 "tpm_tis: register dump:\n",
> 301 s->active_locty,
> 302 locty, s->loc[locty].state);
>
> Fixes: Coverity CID 1487240
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org
> <mailto:f4bug@amsat.org>>
>
>
> Maybe that assert should be in tpm_tis_locality_from_addr(), as various
> callers could produce the same report.
OK I see, tpm_tis_memory_ops handlers are safe because mapped as:
memory_region_init_io(&s->mmio, obj, &tpm_tis_memory_ops,
s, "tpm-tis-mmio",
TPM_TIS_NUM_LOCALITIES <<
TPM_TIS_LOCALITY_SHIFT);
So invalid addresses are impossible from guest.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-03-31 10:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-30 23:57 [PATCH-for-7.1] hw/tpm/tpm_tis: Avoid eventual read overrun Philippe Mathieu-Daudé
2022-03-31 7:50 ` Marc-André Lureau
2022-03-31 10:42 ` Philippe Mathieu-Daudé
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.