* [PATCH] KVM: use struct_size() and flex_array_size() helpers in kvm_io_bus_unregister_dev()
@ 2020-09-18 12:05 Rustam Kovhaev
2020-09-19 0:09 ` Gustavo A. R. Silva
2020-09-21 12:54 ` Sasha Levin
0 siblings, 2 replies; 5+ messages in thread
From: Rustam Kovhaev @ 2020-09-18 12:05 UTC (permalink / raw)
To: pbonzini, vkuznets, gustavoars, kvm
Cc: linux-kernel, gregkh, stable, Rustam Kovhaev
Make use of the struct_size() helper to avoid any potential type
mistakes and protect against potential integer overflows
Make use of the flex_array_size() helper to calculate the size of a
flexible array member within an enclosing structure
Cc: stable@vger.kernel.org
Suggested-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Rustam Kovhaev <rkovhaev@gmail.com>
---
virt/kvm/kvm_main.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index cf88233b819a..68edd25dcb11 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -4350,10 +4350,10 @@ void kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx,
new_bus = kmalloc(struct_size(bus, range, bus->dev_count - 1),
GFP_KERNEL_ACCOUNT);
if (new_bus) {
- memcpy(new_bus, bus, sizeof(*bus) + i * sizeof(struct kvm_io_range));
+ memcpy(new_bus, bus, struct_size(bus, range, i));
new_bus->dev_count--;
memcpy(new_bus->range + i, bus->range + i + 1,
- (new_bus->dev_count - i) * sizeof(struct kvm_io_range));
+ flex_array_size(new_bus, range, new_bus->dev_count - i));
} else {
pr_err("kvm: failed to shrink bus, removing it completely\n");
for (j = 0; j < bus->dev_count; j++) {
--
2.28.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] KVM: use struct_size() and flex_array_size() helpers in kvm_io_bus_unregister_dev()
2020-09-18 12:05 [PATCH] KVM: use struct_size() and flex_array_size() helpers in kvm_io_bus_unregister_dev() Rustam Kovhaev
@ 2020-09-19 0:09 ` Gustavo A. R. Silva
2020-09-22 12:43 ` Paolo Bonzini
2020-09-21 12:54 ` Sasha Levin
1 sibling, 1 reply; 5+ messages in thread
From: Gustavo A. R. Silva @ 2020-09-19 0:09 UTC (permalink / raw)
To: Rustam Kovhaev; +Cc: pbonzini, vkuznets, kvm, linux-kernel, gregkh, stable
On Fri, Sep 18, 2020 at 05:05:00AM -0700, Rustam Kovhaev wrote:
> Make use of the struct_size() helper to avoid any potential type
> mistakes and protect against potential integer overflows
> Make use of the flex_array_size() helper to calculate the size of a
> flexible array member within an enclosing structure
>
> Cc: stable@vger.kernel.org
I don't think this change applies for -stable.
> Suggested-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> Signed-off-by: Rustam Kovhaev <rkovhaev@gmail.com>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Thanks!
--
Gustavo
> ---
> virt/kvm/kvm_main.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index cf88233b819a..68edd25dcb11 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -4350,10 +4350,10 @@ void kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx,
> new_bus = kmalloc(struct_size(bus, range, bus->dev_count - 1),
> GFP_KERNEL_ACCOUNT);
> if (new_bus) {
> - memcpy(new_bus, bus, sizeof(*bus) + i * sizeof(struct kvm_io_range));
> + memcpy(new_bus, bus, struct_size(bus, range, i));
> new_bus->dev_count--;
> memcpy(new_bus->range + i, bus->range + i + 1,
> - (new_bus->dev_count - i) * sizeof(struct kvm_io_range));
> + flex_array_size(new_bus, range, new_bus->dev_count - i));
> } else {
> pr_err("kvm: failed to shrink bus, removing it completely\n");
> for (j = 0; j < bus->dev_count; j++) {
> --
> 2.28.0
>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] KVM: use struct_size() and flex_array_size() helpers in kvm_io_bus_unregister_dev()
2020-09-18 12:05 [PATCH] KVM: use struct_size() and flex_array_size() helpers in kvm_io_bus_unregister_dev() Rustam Kovhaev
2020-09-19 0:09 ` Gustavo A. R. Silva
@ 2020-09-21 12:54 ` Sasha Levin
2020-09-30 17:58 ` Gustavo A. R. Silva
1 sibling, 1 reply; 5+ messages in thread
From: Sasha Levin @ 2020-09-21 12:54 UTC (permalink / raw)
To: Sasha Levin, Rustam Kovhaev, pbonzini, vkuznets, gustavoars
Cc: linux-kernel, gregkh, stable, stable
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 6425 bytes --]
Hi
[This is an automated email]
This commit has been processed because it contains a -stable tag.
The stable tag indicates that it's relevant for the following trees: all
The bot has tested the following trees: v5.8.10, v5.4.66, v4.19.146, v4.14.198, v4.9.236, v4.4.236.
v5.8.10: Build OK!
v5.4.66: Build failed! Errors:
virt/kvm/kvm_main.c:4034:5: error: implicit declaration of function ‘flex_array_size’; did you mean ‘array_size’? [-Werror=implicit-function-declaration]
virt/kvm/kvm_main.c:4034:30: error: ‘range’ undeclared (first use in this function)
virt/kvm/kvm_main.c:4034:5: error: implicit declaration of function ‘flex_array_size’; did you mean ‘array_size’? [-Werror=implicit-function-declaration]
virt/kvm/kvm_main.c:4034:30: error: ‘range’ undeclared (first use in this function)
arch/s390/kvm/../../../virt/kvm/kvm_main.c:4034:5: error: implicit declaration of function 'flex_array_size'; did you mean 'array_size'? [-Werror=implicit-function-declaration]
arch/s390/kvm/../../../virt/kvm/kvm_main.c:4034:30: error: 'range' undeclared (first use in this function)
virt/kvm/kvm_main.c:4034:5: error: implicit declaration of function ‘flex_array_size’; did you mean ‘array_size’? [-Werror=implicit-function-declaration]
virt/kvm/kvm_main.c:4034:30: error: ‘range’ undeclared (first use in this function)
virt/kvm/kvm_main.c:4034:5: error: implicit declaration of function ‘flex_array_size’; did you mean ‘array_size’? [-Werror=implicit-function-declaration]
virt/kvm/kvm_main.c:4034:30: error: ‘range’ undeclared (first use in this function)
arch/s390/kvm/../../../virt/kvm/kvm_main.c:4034:5: error: implicit declaration of function 'flex_array_size'; did you mean 'array_size'? [-Werror=implicit-function-declaration]
arch/s390/kvm/../../../virt/kvm/kvm_main.c:4034:30: error: 'range' undeclared (first use in this function)
virt/kvm/kvm_main.c:4034:5: error: implicit declaration of function ‘flex_array_size’; did you mean ‘array_size’? [-Werror=implicit-function-declaration]
virt/kvm/kvm_main.c:4034:30: error: ‘range’ undeclared (first use in this function)
virt/kvm/kvm_main.c:4034:5: error: implicit declaration of function ‘flex_array_size’; did you mean ‘array_size’? [-Werror=implicit-function-declaration]
virt/kvm/kvm_main.c:4034:30: error: ‘range’ undeclared (first use in this function)
arch/s390/kvm/../../../virt/kvm/kvm_main.c:4034:5: error: implicit declaration of function 'flex_array_size'; did you mean 'array_size'? [-Werror=implicit-function-declaration]
arch/s390/kvm/../../../virt/kvm/kvm_main.c:4034:30: error: 'range' undeclared (first use in this function)
virt/kvm/kvm_main.c:4034:5: error: implicit declaration of function ‘flex_array_size’; did you mean ‘array_size’? [-Werror=implicit-function-declaration]
virt/kvm/kvm_main.c:4034:30: error: ‘range’ undeclared (first use in this function)
virt/kvm/kvm_main.c:4034:5: error: implicit declaration of function ‘flex_array_size’; did you mean ‘array_size’? [-Werror=implicit-function-declaration]
virt/kvm/kvm_main.c:4034:30: error: ‘range’ undeclared (first use in this function)
arch/s390/kvm/../../../virt/kvm/kvm_main.c:4034:5: error: implicit declaration of function 'flex_array_size'; did you mean 'array_size'? [-Werror=implicit-function-declaration]
arch/s390/kvm/../../../virt/kvm/kvm_main.c:4034:30: error: 'range' undeclared (first use in this function)
arch/arm64/kvm/../../../virt/kvm/kvm_main.c:4034:5: error: implicit declaration of function 'flex_array_size'; did you mean 'array_size'? [-Werror=implicit-function-declaration]
arch/arm64/kvm/../../../virt/kvm/kvm_main.c:4034:30: error: 'range' undeclared (first use in this function)
v4.19.146: Failed to apply! Possible dependencies:
0804c849f1df ("kvm/x86 : add coalesced pio support")
360cae313702 ("KVM: PPC: Book3S HV: Nested guest entry via hypercall")
41f4e631daf8 ("KVM: PPC: Book3S HV: Extract PMU save/restore operations as C-callable functions")
89329c0be8bd ("KVM: PPC: Book3S HV: Clear partition table entry on vm teardown")
8e3f5fc1045d ("KVM: PPC: Book3S HV: Framework and hcall stubs for nested virtualization")
90952cd38859 ("kvm: Use struct_size() in kmalloc()")
95a6432ce903 ("KVM: PPC: Book3S HV: Streamlined guest entry/exit path on P9 for radix guests")
9943450b7b88 ("kvm/x86 : add document for coalesced mmio")
aa069a996951 ("KVM: PPC: Book3S HV: Add a VM capability to enable nested virtualization")
b12ce36a43f2 ("kvm: Add memcg accounting to KVM allocations")
df709a296ef7 ("KVM: PPC: Book3S HV: Simplify real-mode interrupt handling")
f7035ce9f1df ("KVM: PPC: Book3S HV: Move interrupt delivery on guest entry to C code")
v4.14.198: Failed to apply! Possible dependencies:
0804c849f1df ("kvm/x86 : add coalesced pio support")
7bf14c28ee77 ("Merge branch 'x86/hyperv' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip")
90952cd38859 ("kvm: Use struct_size() in kmalloc()")
b12ce36a43f2 ("kvm: Add memcg accounting to KVM allocations")
d4c67a7a54f1 ("kvm: use insert sort in kvm_io_bus_register_dev function")
v4.9.236: Failed to apply! Possible dependencies:
0804c849f1df ("kvm/x86 : add coalesced pio support")
4a12f9517728 ("KVM: mark kvm->busses as rcu protected")
7bf14c28ee77 ("Merge branch 'x86/hyperv' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip")
90952cd38859 ("kvm: Use struct_size() in kmalloc()")
b12ce36a43f2 ("kvm: Add memcg accounting to KVM allocations")
d4c67a7a54f1 ("kvm: use insert sort in kvm_io_bus_register_dev function")
v4.4.236: Failed to apply! Possible dependencies:
4a12f9517728 ("KVM: mark kvm->busses as rcu protected")
5c919412fe61 ("kvm/x86: Hyper-V synthetic interrupt controller")
6308630bd3db ("kvm/x86: split ioapic-handled and EOI exit bitmaps")
765eaa0f70ea ("kvm/x86: Hyper-V SynIC message slot pending clearing at SINT ack")
90952cd38859 ("kvm: Use struct_size() in kmalloc()")
d4c67a7a54f1 ("kvm: use insert sort in kvm_io_bus_register_dev function")
d62caabb41f3 ("kvm/x86: per-vcpu apicv deactivation support")
NOTE: The patch will not be queued to stable trees until it is upstream.
How should we proceed with this patch?
--
Thanks
Sasha
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] KVM: use struct_size() and flex_array_size() helpers in kvm_io_bus_unregister_dev()
2020-09-21 12:54 ` Sasha Levin
@ 2020-09-30 17:58 ` Gustavo A. R. Silva
0 siblings, 0 replies; 5+ messages in thread
From: Gustavo A. R. Silva @ 2020-09-30 17:58 UTC (permalink / raw)
To: Sasha Levin, Rustam Kovhaev, pbonzini, vkuznets, gustavoars
Cc: linux-kernel, gregkh, stable
Hi Sasha,
On 9/21/20 07:54, Sasha Levin wrote:
>
> NOTE: The patch will not be queued to stable trees until it is upstream.
>
> How should we proceed with this patch?
>
This patch should not go to -stable.
The author has resent it without the _stable_ stag.
Thanks
--
Gustavo
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-09-30 18:14 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-18 12:05 [PATCH] KVM: use struct_size() and flex_array_size() helpers in kvm_io_bus_unregister_dev() Rustam Kovhaev
2020-09-19 0:09 ` Gustavo A. R. Silva
2020-09-22 12:43 ` Paolo Bonzini
2020-09-21 12:54 ` Sasha Levin
2020-09-30 17:58 ` Gustavo A. R. Silva
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.