6a8703aecb
Change the data type of the ioctl _request_ argument from 'int' to 'unsigned long' for the various accel/kvm functions which are essentially wrappers around the ioctl() syscall. The correct type for ioctl()'s 'request' argument is confused: * POSIX defines the request argument as 'int' * glibc uses 'unsigned long' in the prototype in sys/ioctl.h * the glibc info documentation uses 'int' * the Linux manpage uses 'unsigned long' * the Linux implementation of the syscall uses 'unsigned int' If we wrap ioctl() with another function which uses 'int' as the type for the request argument, then requests with the 0x8000_0000 bit set will be sign-extended when the 'int' is cast to 'unsigned long' for the call to ioctl(). On x86_64 one such example is the KVM_IRQ_LINE_STATUS request. Bit requests with the _IOC_READ direction bit set, will have the high bit set. Fortunately the Linux Kernel truncates the upper 32bit of the request on 64bit machines (because it uses 'unsigned int', and see also Linus Torvalds' comments in https://sourceware.org/bugzilla/show_bug.cgi?id=14362 ) so this doesn't cause active problems for us. However it is more consistent to follow the glibc ioctl() prototype when we define functions that are essentially wrappers around ioctl(). This resolves a Coverity issue where it points out that in kvm_get_xsave() we assign a value (KVM_GET_XSAVE or KVM_GET_XSAVE2) to an 'int' variable which can't hold it without overflow. Resolves: Coverity CID 1547759 Signed-off-by: Johannes Stoelp <johannes.stoelp@gmail.com> Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Eric Blake <eblake@redhat.com> Message-id: 20240815122747.3053871-1-peter.maydell@linaro.org [PMM: Rebased patch, adjusted commit message, included note about Coverity fix, updated the type of the local var in kvm_get_xsave, updated the comment in the KVMState struct definition] Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
||
---|---|---|
.. | ||
accel-blocker.h | ||
accel-ops.h | ||
arch_init.h | ||
balloon.h | ||
block-backend-common.h | ||
block-backend-global-state.h | ||
block-backend-io.h | ||
block-backend.h | ||
block-ram-registrar.h | ||
blockdev.h | ||
cpu-throttle.h | ||
cpu-timers-internal.h | ||
cpu-timers.h | ||
cpus.h | ||
cryptodev-vhost-user.h | ||
cryptodev-vhost.h | ||
cryptodev.h | ||
device_tree.h | ||
dirtylimit.h | ||
dirtyrate.h | ||
dma.h | ||
dump-arch.h | ||
dump.h | ||
event-loop-base.h | ||
host_iommu_device.h | ||
hostmem.h | ||
hvf_int.h | ||
hvf.h | ||
hw_accel.h | ||
iommufd.h | ||
iothread.h | ||
kvm_int.h | ||
kvm_xen.h | ||
kvm.h | ||
memory_mapping.h | ||
numa.h | ||
nvmm.h | ||
os-posix.h | ||
os-win32.h | ||
qtest.h | ||
replay.h | ||
reset.h | ||
rng-random.h | ||
rng.h | ||
rtc.h | ||
runstate-action.h | ||
runstate.h | ||
seccomp.h | ||
spdm-socket.h | ||
stats.h | ||
sysemu.h | ||
tcg.h | ||
tpm_backend.h | ||
tpm_util.h | ||
tpm.h | ||
vhost-user-backend.h | ||
watchdog.h | ||
whpx.h | ||
xen-mapcache.h | ||
xen.h |