• Sean Christopherson's avatar
    KVM: selftests: Compare insn opcodes directly in fix_hypercall_test · 39426507
    Sean Christopherson authored
    Directly compare the expected versus observed hypercall instructions when
    verifying that KVM patched in the native hypercall (FIX_HYPERCALL_INSN
    quirk enabled).  gcc rightly complains that doing a 4-byte memcpy() with
    an "unsigned char" as the source generates an out-of-bounds accesses.
    
    Alternatively, "exp" and "obs" could be declared as 3-byte arrays, but
    there's no known reason to copy locally instead of comparing directly.
    
    In function ‘assert_hypercall_insn’,
        inlined from ‘guest_main’ at x86_64/fix_hypercall_test.c:91:2:
    x86_64/fix_hypercall_test.c:63:9: error: array subscript ‘unsigned int[0]’
     is partly outside array bounds of ‘unsigned char[1]’ [-Werror=array-bounds]
       63 |         memcpy(&exp, exp_insn, sizeof(exp));
          |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    x86_64/fix_hypercall_test.c: In function ‘guest_main’:
    x86_64/fix_hypercall_test.c:42:22: note: object ‘vmx_hypercall_insn’ of size 1
       42 | extern unsigned char vmx_hypercall_insn;
          |                      ^~~~~~~~~~~~~~~~~~
    x86_64/fix_hypercall_test.c:25:22: note: object ‘svm_hypercall_insn’ of size 1
       25 | extern unsigned char svm_hypercall_insn;
          |                      ^~~~~~~~~~~~~~~~~~
    In function ‘assert_hypercall_insn’,
        inlined from ‘guest_main’ at x86_64/fix_hypercall_test.c:91:2:
    x86_64/fix_hypercall_test.c:64:9: error: array subscript ‘unsigned int[0]’
     is partly outside array bounds of ‘unsigned char[1]’ [-Werror=array-bounds]
       64 |         memcpy(&obs, obs_insn, sizeof(obs));
          |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    x86_64/fix_hypercall_test.c: In function ‘guest_main’:
    x86_64/fix_hypercall_test.c:25:22: note: object ‘svm_hypercall_insn’ of size 1
       25 | extern unsigned char svm_hypercall_insn;
          |                      ^~~~~~~~~~~~~~~~~~
    x86_64/fix_hypercall_test.c:42:22: note: object ‘vmx_hypercall_insn’ of size 1
       42 | extern unsigned char vmx_hypercall_insn;
          |                      ^~~~~~~~~~~~~~~~~~
    cc1: all warnings being treated as errors
    make: *** [../lib.mk:135: tools/testing/selftests/kvm/x86_64/fix_hypercall_test] Error 1
    
    Fixes: 6c2fa8b2 ("selftests: KVM: Test KVM_X86_QUIRK_FIX_HYPERCALL_INSN")
    Cc: Oliver Upton <oliver.upton@linux.dev>
    Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
    Reviewed-by: default avatarOliver Upton <oliver.upton@linux.dev>
    Message-Id: <20220928233652.783504-3-seanjc@google.com>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    39426507
fix_hypercall_test.c 3.59 KB