All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: kvm@vger.kernel.org
Subject: [PATCH kvm-unit-tests] x86: access: avoid undefined behavior
Date: Fri,  9 Aug 2019 12:57:14 +0200	[thread overview]
Message-ID: <20190809105714.9450-1-pbonzini@redhat.com> (raw)

In this test, at->ptep is tested in one argument to ac_test_check
and dereferenced in another.  The compiler notices that and observes
that at->ptep cannot be NULL.  The test is indeed broken and has
been broken for 9+ years: the ac_test_check should not be performed at
all if there is no PTE.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 x86/access.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/x86/access.c b/x86/access.c
index f0d1879..4ec0b0a 100644
--- a/x86/access.c
+++ b/x86/access.c
@@ -704,8 +704,9 @@ static int ac_test_do_access(ac_test_t *at)
                   "unexpected access");
     ac_test_check(at, &success, fault && e != at->expected_error,
                   "error code %x expected %x", e, at->expected_error);
-    ac_test_check(at, &success, at->ptep && *at->ptep != at->expected_pte,
-                  "pte %x expected %x", *at->ptep, at->expected_pte);
+    if (at->ptep)
+        ac_test_check(at, &success, *at->ptep != at->expected_pte,
+                      "pte %x expected %x", *at->ptep, at->expected_pte);
     ac_test_check(at, &success,
                   !pt_match(*at->pdep, at->expected_pde, at->ignore_pde),
                   "pde %x expected %x", *at->pdep, at->expected_pde);
-- 
2.21.0


                 reply	other threads:[~2019-08-09 10:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20190809105714.9450-1-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kvm@vger.kernel.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 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.