drm/i915/gvt: Improve intel_vgpu_ioctl hdr error handling
PATCH 1/1 drm/i915/gvt: Improve intel_vgpu_ioctl hdr error handling
Add error handling for the following VFIO_DEVICE_SET_IRQS cases with respect to the hdr struct:
- More than one VFIO_IRQ_DATA_TYPE_MASK flag is set in hdr.flags
- More than one VFIO_IRQ_ACTION_TYPE_MASK flag is set in hdr.flags
- hdr.count is not specified
Note that since hdr.count != 0, data_size != 0 is guaranteed unless vfio_set_irqs_validate_and_prepare fails and returns an error. So, we no longer need to check data_size before running memdup_user because checking the return value of the function is sufficient.
--- drivers/gpu/drm/i915/gvt/kvmgt.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
drivers/gpu/drm/i915/gvt/kvmgt.c +12 -6
@@ -1361,21 +1361,27 @@ static long intel_vgpu_ioctl(struct vfio_device *vfio_dev, unsigned int cmd,if (copy_from_user (&hdr, (void __user *)arg, minsz))return -EFAULT ; +if (hweight32 (hdr.flags &VFIO_IRQ_DATA_TYPE_MASK ) !=1 || +hweight32 (hdr.flags &VFIO_IRQ_ACTION_TYPE_MASK ) !=1 ) +return -EINVAL ; +if (!(hdr.flags &VFIO_IRQ_SET_DATA_NONE )) {int max =intel_vgpu_get_irq_count (vgpu, hdr.index); +if (!hdr.count) +return -EINVAL ; + ret =vfio_set_irqs_validate_and_prepare (&hdr, max,VFIO_PCI_NUM_IRQS , &data_size);if (ret) {gvt_vgpu_err ("intel:vfio_set_irqs_validate_and_prepare failed\n" );return -EINVAL ; } -if (data_size) { - data =memdup_user ((void __user *)(arg + minsz), - data_size); -if (IS_ERR (data)) -return PTR_ERR (data); - } + + data =memdup_user ((void __user *)(arg + minsz), + data_size); +if (IS_ERR (data)) +return PTR_ERR (data); } ret = intel_vgpu_set_irqs(vgpu, hdr.flags, hdr.index,
Signature · 1 line
2.43.0
Patchwork
CI✗ Fi.CI.BUILD: failure for drm/i915/gvt: Improve intel_vgpu_ioctl hdr error handling
== Series Details ==
== Series Details ==
Series: drm/i915/gvt: Improve intel_vgpu_ioctl hdr error handling
URL : https://patchwork.freedesktop.org/series/154798/
State : failure
== Summary ==
Error: make failed
CALL scripts/checksyscalls.sh
DESCEND objtool
INSTALL libsubcmd_headers
LD [M] drivers/gpu/drm/i915/i915.o
CC [M] drivers/gpu/drm/i915/gvt/kvmgt.o
In file included from ./arch/x86/include/asm/bitops.h:427,
from ./include/linux/bitops.h:67,
from ./include/linux/kernel.h:23,
from ./include/linux/cpumask.h:11,
from ./arch/x86/include/asm/paravirt.h:21,
from ./arch/x86/include/asm/irqflags.h:102,
from ./include/linux/irqflags.h:18,
from ./include/linux/spinlock.h:59,
from ./include/linux/mmzone.h:8,
from ./include/linux/gfp.h:7,
from ./include/linux/mm.h:7,
from drivers/gpu/drm/i915/gvt/kvmgt.c:37:
drivers/gpu/drm/i915/gvt/kvmgt.c: In function ‘intel_vgpu_ioctl’:
drivers/gpu/drm/i915/gvt/kvmgt.c:1364:43: error: ‘VFIO_IRQ_DATA_TYPE_MASK’ undeclared (first use in this function); did you mean ‘VFIO_IRQ_SET_DATA_TYPE_MASK’?
1364 | if (hweight32(hdr.flags & VFIO_IRQ_DATA_TYPE_MASK) != 1 ||
| ^~~~~~~~~~~~~~~~~~~~~~~./include/asm-generic/bitops/const_hweight.h:28:44: note: in definition of macro ‘hweight32’
28 | #define hweight32(w) (__builtin_constant_p(w) ? __const_hweight32(w) : __arch_hweight32(w))
| ^drivers/gpu/drm/i915/gvt/kvmgt.c:1364:43: note: each undeclared identifier is reported only once for each function it appears in
1364 | if (hweight32(hdr.flags & VFIO_IRQ_DATA_TYPE_MASK) != 1 ||
| ^~~~~~~~~~~~~~~~~~~~~~~
./include/asm-generic/bitops/const_hweight.h:28:44: note: in definition of macro ‘hweight32’
28 | #define hweight32(w) (__builtin_constant_p(w) ? __const_hweight32(w) : __arch_hweight32(w))
| ^drivers/gpu/drm/i915/gvt/kvmgt.c:1365:43: error: ‘VFIO_IRQ_ACTION_TYPE_MASK’ undeclared (first use in this function); did you mean ‘VFIO_IRQ_SET_ACTION_TYPE_MASK’?
1365 | hweight32(hdr.flags & VFIO_IRQ_ACTION_TYPE_MASK) != 1)
| ^~~~~~~~~~~~~~~~~~~~~~~~~
./include/asm-generic/bitops/const_hweight.h:28:44: note: in definition of macro ‘hweight32’
28 | #define hweight32(w) (__builtin_constant_p(w) ? __const_hweight32(w) : __arch_hweight32(w))
| ^
make[6]: *** [scripts/Makefile.build:287: drivers/gpu/drm/i915/gvt/kvmgt.o] Error 1 make[5]: *** [scripts/Makefile.build:556: drivers/gpu/drm/i915] Error 2
make[4]: *** [scripts/Makefile.build:556: drivers/gpu/drm] Error 2
make[3]: *** [scripts/Makefile.build:556: drivers/gpu] Error 2
make[2]: *** [scripts/Makefile.build:556: drivers] Error 2
make[1]: *** [/home/kbuild/kernel/Makefile:2011: .] Error 2
make: *** [Makefile:248: __sub-make] Error 2
Build failed, no error log produced