qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PULL v1 0/2] Merge tpm 2022/06/07 v1
@ 2022-06-08  1:00 Stefan Berger
  2022-06-08  1:00 ` [PULL v1 1/2] hw/tpm/tpm_tis_common.c: Assert that locty is in range Stefan Berger
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Stefan Berger @ 2022-06-08  1:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, Stefan Berger

Hi!

The patches in this PR resolve several Coverity issues and mark a memory
region with TPM response data as dirty so that it does not get lost during 
migration.

   Stefan

The following changes since commit 7077fcb9b68f058809c9dd9fd1dacae1881e886c:

  Merge tag 'vmbus-maint-20220530' of https://github.com/maciejsszmigiero/qemu into staging (2022-05-30 12:40:36 -0700)

are available in the Git repository at:

  https://github.com/stefanberger/qemu-tpm.git tags/pull-tpm-2022-06-07-1

for you to fetch changes up to e37a0ef4605e5d2041785ff3fc89ca6021faf7a0:

  tpm_crb: mark command buffer as dirty on request completion (2022-06-07 20:37:25 -0400)

Anthony PERARD (1):
      tpm_crb: mark command buffer as dirty on request completion

Peter Maydell (1):
      hw/tpm/tpm_tis_common.c: Assert that locty is in range

 hw/tpm/tpm_crb.c        | 1 +
 hw/tpm/tpm_tis_common.c | 7 ++++++-
 2 files changed, 7 insertions(+), 1 deletion(-)

-- 
2.35.3


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

* [PULL v1 1/2] hw/tpm/tpm_tis_common.c: Assert that locty is in range
  2022-06-08  1:00 [PULL v1 0/2] Merge tpm 2022/06/07 v1 Stefan Berger
@ 2022-06-08  1:00 ` Stefan Berger
  2022-06-08  1:00 ` [PULL v1 2/2] tpm_crb: mark command buffer as dirty on request completion Stefan Berger
  2022-06-08 14:40 ` [PULL v1 0/2] Merge tpm 2022/06/07 v1 Richard Henderson
  2 siblings, 0 replies; 4+ messages in thread
From: Stefan Berger @ 2022-06-08  1:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, Stefan Berger, Marc-André Lureau

From: Peter Maydell <peter.maydell@linaro.org>

In tpm_tis_mmio_read(), tpm_tis_mmio_write() and
tpm_tis_dump_state(), we calculate a locality index with
tpm_tis_locality_from_addr() and then use it as an index into the
s->loc[] array.  In all these cases, the array index can't overflow
because the MemoryRegion is sized to be TPM_TIS_NUM_LOCALITIES <<
TPM_TIS_LOCALITY_SHIFT bytes.  However, Coverity can't see that, and
it complains (CID 1487138, 1487180, 1487188, 1487198, 1487240).

Add an assertion to tpm_tis_locality_from_addr() that the calculated
locality index is valid, which will help Coverity and also catch any
potential future bug where the MemoryRegion isn't sized exactly.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-id: 20220525125904.483075-1-stefanb@linux.ibm.com
---
 hw/tpm/tpm_tis_common.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/hw/tpm/tpm_tis_common.c b/hw/tpm/tpm_tis_common.c
index e700d82181..503be2a541 100644
--- a/hw/tpm/tpm_tis_common.c
+++ b/hw/tpm/tpm_tis_common.c
@@ -50,7 +50,12 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr addr,
 
 static uint8_t tpm_tis_locality_from_addr(hwaddr addr)
 {
-    return (uint8_t)((addr >> TPM_TIS_LOCALITY_SHIFT) & 0x7);
+    uint8_t locty;
+
+    locty = (uint8_t)((addr >> TPM_TIS_LOCALITY_SHIFT) & 0x7);
+    assert(TPM_TIS_IS_VALID_LOCTY(locty));
+
+    return locty;
 }
 
 
-- 
2.35.3



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

* [PULL v1 2/2] tpm_crb: mark command buffer as dirty on request completion
  2022-06-08  1:00 [PULL v1 0/2] Merge tpm 2022/06/07 v1 Stefan Berger
  2022-06-08  1:00 ` [PULL v1 1/2] hw/tpm/tpm_tis_common.c: Assert that locty is in range Stefan Berger
@ 2022-06-08  1:00 ` Stefan Berger
  2022-06-08 14:40 ` [PULL v1 0/2] Merge tpm 2022/06/07 v1 Richard Henderson
  2 siblings, 0 replies; 4+ messages in thread
From: Stefan Berger @ 2022-06-08  1:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, Anthony PERARD, Stefan Berger

From: Anthony PERARD <anthony.perard@citrix.com>

At the moment, there doesn't seems to be any way to know that QEMU
made modification to the command buffer. This is potentially an issue
on Xen while migrating a guest, as modification to the buffer after
the migration as started could be ignored and not transfered to the
destination.

Mark the memory region of the command buffer as dirty once a request
is completed.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Message-id: 20220411144749.47185-1-anthony.perard@citrix.com
---
 hw/tpm/tpm_crb.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/tpm/tpm_crb.c b/hw/tpm/tpm_crb.c
index aa9c00aad3..67db594c48 100644
--- a/hw/tpm/tpm_crb.c
+++ b/hw/tpm/tpm_crb.c
@@ -197,6 +197,7 @@ static void tpm_crb_request_completed(TPMIf *ti, int ret)
         ARRAY_FIELD_DP32(s->regs, CRB_CTRL_STS,
                          tpmSts, 1); /* fatal error */
     }
+    memory_region_set_dirty(&s->cmdmem, 0, CRB_CTRL_CMD_SIZE);
 }
 
 static enum TPMVersion tpm_crb_get_version(TPMIf *ti)
-- 
2.35.3



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

* Re: [PULL v1 0/2] Merge tpm 2022/06/07 v1
  2022-06-08  1:00 [PULL v1 0/2] Merge tpm 2022/06/07 v1 Stefan Berger
  2022-06-08  1:00 ` [PULL v1 1/2] hw/tpm/tpm_tis_common.c: Assert that locty is in range Stefan Berger
  2022-06-08  1:00 ` [PULL v1 2/2] tpm_crb: mark command buffer as dirty on request completion Stefan Berger
@ 2022-06-08 14:40 ` Richard Henderson
  2 siblings, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2022-06-08 14:40 UTC (permalink / raw)
  To: Stefan Berger, qemu-devel; +Cc: peter.maydell

On 6/7/22 18:00, Stefan Berger wrote:
> Hi!
> 
> The patches in this PR resolve several Coverity issues and mark a memory
> region with TPM response data as dirty so that it does not get lost during
> migration.
> 
>     Stefan

Applied, thanks.  Please update https://wiki.qemu.org/ChangeLog/7.1 as appropriate.


r~


> 
> The following changes since commit 7077fcb9b68f058809c9dd9fd1dacae1881e886c:
> 
>    Merge tag 'vmbus-maint-20220530' of https://github.com/maciejsszmigiero/qemu into staging (2022-05-30 12:40:36 -0700)
> 
> are available in the Git repository at:
> 
>    https://github.com/stefanberger/qemu-tpm.git tags/pull-tpm-2022-06-07-1
> 
> for you to fetch changes up to e37a0ef4605e5d2041785ff3fc89ca6021faf7a0:
> 
>    tpm_crb: mark command buffer as dirty on request completion (2022-06-07 20:37:25 -0400)
> 
> Anthony PERARD (1):
>        tpm_crb: mark command buffer as dirty on request completion
> 
> Peter Maydell (1):
>        hw/tpm/tpm_tis_common.c: Assert that locty is in range
> 
>   hw/tpm/tpm_crb.c        | 1 +
>   hw/tpm/tpm_tis_common.c | 7 ++++++-
>   2 files changed, 7 insertions(+), 1 deletion(-)
> 



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

end of thread, other threads:[~2022-06-08 14:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-08  1:00 [PULL v1 0/2] Merge tpm 2022/06/07 v1 Stefan Berger
2022-06-08  1:00 ` [PULL v1 1/2] hw/tpm/tpm_tis_common.c: Assert that locty is in range Stefan Berger
2022-06-08  1:00 ` [PULL v1 2/2] tpm_crb: mark command buffer as dirty on request completion Stefan Berger
2022-06-08 14:40 ` [PULL v1 0/2] Merge tpm 2022/06/07 v1 Richard Henderson

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).