• Nicholas Piggin's avatar
    KVM: PPC: Book3S: Fix H_RTAS rets buffer overflow · f62f3c20
    Nicholas Piggin authored
    The kvmppc_rtas_hcall() sets the host rtas_args.rets pointer based on
    the rtas_args.nargs that was provided by the guest. That guest nargs
    value is not range checked, so the guest can cause the host rets pointer
    to be pointed outside the args array. The individual rtas function
    handlers check the nargs and nrets values to ensure they are correct,
    but if they are not, the handlers store a -3 (0xfffffffd) failure
    indication in rets[0] which corrupts host memory.
    
    Fix this by testing up front whether the guest supplied nargs and nret
    would exceed the array size, and fail the hcall directly without storing
    a failure indication to rets[0].
    
    Also expand on a comment about why we kill the guest and try not to
    return errors directly if we have a valid rets[0] pointer.
    
    Fixes: 8e591cb7 ("KVM: PPC: Book3S: Add infrastructure to implement kernel-side RTAS calls")
    Cc: stable@vger.kernel.org # v3.10+
    Reported-by: default avatarAlexey Kardashevskiy <aik@ozlabs.ru>
    Signed-off-by: default avatarNicholas Piggin <npiggin@gmail.com>
    Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
    f62f3c20
book3s_rtas.c 6.87 KB