KVM: x86: Clean up partially uninitialized integer in emulate_pop()
authorJulian Stecklina <julian.stecklina@cyberus-technology.de>
Mon, 9 Oct 2023 09:20:53 +0000 (11:20 +0200)
committerSean Christopherson <seanjc@google.com>
Thu, 8 Feb 2024 00:08:54 +0000 (16:08 -0800)
commit6fd1e3963f20e850d7b3c89485e58d1ae79c309a
tree20a19bd906e83ad4640eab64c7cd7ee48d870e0c
parent03f6298c7cf6d2c1ccd0961ab9b340502d63840a
KVM: x86: Clean up partially uninitialized integer in emulate_pop()

Explicitly zero out variables passed to emulate_pop() as output params
to harden against consuming uninitialized data, and to make sanitizers
happy.  Many flows that use emulate_pop() pass an "unsigned long" so as
to be able to hold the largest possible operand, but the actual number
of bytes written is usually the word with of the vCPU.  E.g. if the vCPU
is in 16-bit or 32-bit mode (on a 64-bit host), the upper portion of the
output param will be uninitialized.

Passing around the uninitialized data is benign, as actual KVM usage of
the output is also tied to the word width, but passing around
uninitialized data makes some sanitizers rightly complain.

Note, initializing the data in emulate_pop() is not a safe alternative,
e.g. it would result in em_leave() clobbering RBP[31:16] if LEAVE were
emulated with a 16-bit stack.

Signed-off-by: Julian Stecklina <julian.stecklina@cyberus-technology.de>
Link: https://lore.kernel.org/r/20231009092054.556935-1-julian.stecklina@cyberus-technology.de
[sean: massage changelog, drop em_popa() variable size change]]
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/emulate.c