guest_access: harden *copy_to_guest_offset() to prevent const dest operand
authorJulien Grall <jgrall@amazon.com>
Mon, 27 Apr 2020 07:28:21 +0000 (09:28 +0200)
committerJan Beulich <jbeulich@suse.com>
Mon, 27 Apr 2020 07:28:21 +0000 (09:28 +0200)
commit4bdf6b5a7fec876e9bbd70ebe605828ad0fb12a4
tree92a53b607049c7609d31df3084d39647784f0674
parentf093b08c47b39da6019421a2b61d40745b3e573b
guest_access: harden *copy_to_guest_offset() to prevent const dest operand

At the moment, *copy_to_guest_offset() will allow the hypervisor to copy
data to guest handle marked const.

Thankfully, no users of the helper will do that. Rather than hoping this
can be caught during review, harden copy_to_guest_offset() so the build
will fail if such users are introduced.

There is no easy way to check whether a const is NULL in C99. The
approach used is to introduce an unused variable that is non-const and
assign the handle. If the handle were const, this would fail at build
because without an explicit cast, it is not possible to assign a const
variable to a non-const variable.

Suggested-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
xen/include/asm-arm/guest_access.h
xen/include/asm-x86/guest_access.h