public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Peter Gonda <pgonda@google.com>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
	Paolo Bonzini <pbonzini@redhat.com>,
	Marc Orr <marcorr@google.com>
Subject: Re: [PATCH] selftests: sev_migrate_tests: Fix sev_ioctl()
Date: Tue, 7 Dec 2021 21:24:54 +0000	[thread overview]
Message-ID: <Ya/RJiTOQjJ+fj73@google.com> (raw)
In-Reply-To: <20211207201034.1392660-1-pgonda@google.com>

On Tue, Dec 07, 2021, Peter Gonda wrote:
> TEST_ASSERT in SEV ioctl was allowing errors because it checked return
> value was good OR the FW error code was OK. This TEST_ASSERT should
> require both (aka. AND) values are OK. Removes the LAUNCH_START from the
> mirror VM because this call correctly fails because mirror VMs cannot
> call this command.

This probably should be two separate patches.  First remove the bogus LAUNCH_START
call, then fix the assert.
 
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Sean Christopherson <seanjc@google.com>
> Cc: Marc Orr <marcorr@google.com>
> Signed-off-by: Peter Gonda <pgonda@google.com>
> ---
>  tools/testing/selftests/kvm/x86_64/sev_migrate_tests.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/testing/selftests/kvm/x86_64/sev_migrate_tests.c b/tools/testing/selftests/kvm/x86_64/sev_migrate_tests.c
> index 29b18d565cf4..8e1b1e737cb1 100644
> --- a/tools/testing/selftests/kvm/x86_64/sev_migrate_tests.c
> +++ b/tools/testing/selftests/kvm/x86_64/sev_migrate_tests.c
> @@ -31,7 +31,7 @@ static void sev_ioctl(int vm_fd, int cmd_id, void *data)
>  	int ret;
>  
>  	ret = ioctl(vm_fd, KVM_MEMORY_ENCRYPT_OP, &cmd);
> -	TEST_ASSERT((ret == 0 || cmd.error == SEV_RET_SUCCESS),
> +	TEST_ASSERT(ret == 0 && cmd.error == SEV_RET_SUCCESS,
>  		    "%d failed: return code: %d, errno: %d, fw error: %d",
>  		    cmd_id, ret, errno, cmd.error);

Hmm, reading cmd.error could also consume uninitialized data, e.g. if the ioctl()
fails before getting into the PSP command, the error message will dump garbage.

And theoretically this could get a false negative if the test stack happens to have
'0' for cmd.error and KVM neglects to fill cmd.error when the ioctl() succeeds.

So in additional to fixing the assert itself, I vote we also do:

diff --git a/tools/testing/selftests/kvm/x86_64/sev_migrate_tests.c b/tools/testing/selftests/kvm/x86_64/sev_migrate_tests.c
index 29b18d565cf4..50132e165a8d 100644
--- a/tools/testing/selftests/kvm/x86_64/sev_migrate_tests.c
+++ b/tools/testing/selftests/kvm/x86_64/sev_migrate_tests.c
@@ -26,6 +26,7 @@ static void sev_ioctl(int vm_fd, int cmd_id, void *data)
        struct kvm_sev_cmd cmd = {
                .id = cmd_id,
                .data = (uint64_t)data,
+               .error = -1u,
                .sev_fd = open_sev_dev_path_or_exit(),
        };
        int ret;

  reply	other threads:[~2021-12-07 21:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-07 20:10 [PATCH] selftests: sev_migrate_tests: Fix sev_ioctl() Peter Gonda
2021-12-07 21:24 ` Sean Christopherson [this message]
2021-12-07 21:27   ` Peter Gonda
2021-12-07 22:47 ` Marc Orr

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=Ya/RJiTOQjJ+fj73@google.com \
    --to=seanjc@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcorr@google.com \
    --cc=pbonzini@redhat.com \
    --cc=pgonda@google.com \
    /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