* [PATCH][next] xen: privcmd: Replace zero-length array with flex-array member and use __counted_by
@ 2023-11-16 18:54 Gustavo A. R. Silva
2023-11-16 21:08 ` Kees Cook
2023-11-17 7:24 ` Juergen Gross
0 siblings, 2 replies; 4+ messages in thread
From: Gustavo A. R. Silva @ 2023-11-16 18:54 UTC (permalink / raw)
To: Juergen Gross, Stefano Stabellini, Oleksandr Tyshchenko
Cc: xen-devel, linux-kernel, Gustavo A. R. Silva, linux-hardening
Fake flexible arrays (zero-length and one-element arrays) are deprecated,
and should be replaced by flexible-array members. So, replace
zero-length array with a flexible-array member in `struct
privcmd_kernel_ioreq`.
Also annotate array `ports` with `__counted_by()` to prepare for the
coming implementation by GCC and Clang of the `__counted_by` attribute.
Flexible array members annotated with `__counted_by` can have their
accesses bounds-checked at run-time via `CONFIG_UBSAN_BOUNDS` (for array
indexing) and `CONFIG_FORTIFY_SOURCE` (for strcpy/memcpy-family functions).
This fixes multiple -Warray-bounds warnings:
drivers/xen/privcmd.c:1239:30: warning: array subscript i is outside array bounds of 'struct ioreq_port[0]' [-Warray-bounds=]
drivers/xen/privcmd.c:1240:30: warning: array subscript i is outside array bounds of 'struct ioreq_port[0]' [-Warray-bounds=]
drivers/xen/privcmd.c:1241:30: warning: array subscript i is outside array bounds of 'struct ioreq_port[0]' [-Warray-bounds=]
drivers/xen/privcmd.c:1245:33: warning: array subscript i is outside array bounds of 'struct ioreq_port[0]' [-Warray-bounds=]
drivers/xen/privcmd.c:1258:67: warning: array subscript i is outside array bounds of 'struct ioreq_port[0]' [-Warray-bounds=]
This results in no differences in binary output.
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
drivers/xen/privcmd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c
index 1ce7f3c7a950..0eb337a8ec0f 100644
--- a/drivers/xen/privcmd.c
+++ b/drivers/xen/privcmd.c
@@ -1115,7 +1115,7 @@ struct privcmd_kernel_ioreq {
spinlock_t lock; /* Protects ioeventfds list */
struct list_head ioeventfds;
struct list_head list;
- struct ioreq_port ports[0];
+ struct ioreq_port ports[] __counted_by(vcpus);
};
static irqreturn_t ioeventfd_interrupt(int irq, void *dev_id)
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH][next] xen: privcmd: Replace zero-length array with flex-array member and use __counted_by
2023-11-16 18:54 [PATCH][next] xen: privcmd: Replace zero-length array with flex-array member and use __counted_by Gustavo A. R. Silva
@ 2023-11-16 21:08 ` Kees Cook
2023-11-16 21:18 ` Gustavo A. R. Silva
2023-11-17 7:24 ` Juergen Gross
1 sibling, 1 reply; 4+ messages in thread
From: Kees Cook @ 2023-11-16 21:08 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Juergen Gross, Stefano Stabellini, Oleksandr Tyshchenko,
xen-devel, linux-kernel, linux-hardening
On Thu, Nov 16, 2023 at 12:54:59PM -0600, Gustavo A. R. Silva wrote:
> Fake flexible arrays (zero-length and one-element arrays) are deprecated,
> and should be replaced by flexible-array members. So, replace
> zero-length array with a flexible-array member in `struct
> privcmd_kernel_ioreq`.
>
> Also annotate array `ports` with `__counted_by()` to prepare for the
> coming implementation by GCC and Clang of the `__counted_by` attribute.
> Flexible array members annotated with `__counted_by` can have their
> accesses bounds-checked at run-time via `CONFIG_UBSAN_BOUNDS` (for array
> indexing) and `CONFIG_FORTIFY_SOURCE` (for strcpy/memcpy-family functions).
>
> This fixes multiple -Warray-bounds warnings:
> drivers/xen/privcmd.c:1239:30: warning: array subscript i is outside array bounds of 'struct ioreq_port[0]' [-Warray-bounds=]
> drivers/xen/privcmd.c:1240:30: warning: array subscript i is outside array bounds of 'struct ioreq_port[0]' [-Warray-bounds=]
> drivers/xen/privcmd.c:1241:30: warning: array subscript i is outside array bounds of 'struct ioreq_port[0]' [-Warray-bounds=]
> drivers/xen/privcmd.c:1245:33: warning: array subscript i is outside array bounds of 'struct ioreq_port[0]' [-Warray-bounds=]
> drivers/xen/privcmd.c:1258:67: warning: array subscript i is outside array bounds of 'struct ioreq_port[0]' [-Warray-bounds=]
>
> This results in no differences in binary output.
>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Looks right to me. I can see the allocation:
size = struct_size(kioreq, ports, ioeventfd->vcpus);
kioreq = kzalloc(size, GFP_KERNEL);
if (!kioreq)
return ERR_PTR(-ENOMEM);
kioreq->dom = ioeventfd->dom;
kioreq->vcpus = ioeventfd->vcpus;
Reviewed-by: Kees Cook <keescook@chromium.org>
--
Kees Cook
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH][next] xen: privcmd: Replace zero-length array with flex-array member and use __counted_by
2023-11-16 21:08 ` Kees Cook
@ 2023-11-16 21:18 ` Gustavo A. R. Silva
0 siblings, 0 replies; 4+ messages in thread
From: Gustavo A. R. Silva @ 2023-11-16 21:18 UTC (permalink / raw)
To: Kees Cook, Gustavo A. R. Silva
Cc: Juergen Gross, Stefano Stabellini, Oleksandr Tyshchenko,
xen-devel, linux-kernel, linux-hardening
On 11/16/23 15:08, Kees Cook wrote:
> On Thu, Nov 16, 2023 at 12:54:59PM -0600, Gustavo A. R. Silva wrote:
>> Fake flexible arrays (zero-length and one-element arrays) are deprecated,
>> and should be replaced by flexible-array members. So, replace
>> zero-length array with a flexible-array member in `struct
>> privcmd_kernel_ioreq`.
>>
>> Also annotate array `ports` with `__counted_by()` to prepare for the
>> coming implementation by GCC and Clang of the `__counted_by` attribute.
>> Flexible array members annotated with `__counted_by` can have their
>> accesses bounds-checked at run-time via `CONFIG_UBSAN_BOUNDS` (for array
>> indexing) and `CONFIG_FORTIFY_SOURCE` (for strcpy/memcpy-family functions).
>>
>> This fixes multiple -Warray-bounds warnings:
>> drivers/xen/privcmd.c:1239:30: warning: array subscript i is outside array bounds of 'struct ioreq_port[0]' [-Warray-bounds=]
>> drivers/xen/privcmd.c:1240:30: warning: array subscript i is outside array bounds of 'struct ioreq_port[0]' [-Warray-bounds=]
>> drivers/xen/privcmd.c:1241:30: warning: array subscript i is outside array bounds of 'struct ioreq_port[0]' [-Warray-bounds=]
>> drivers/xen/privcmd.c:1245:33: warning: array subscript i is outside array bounds of 'struct ioreq_port[0]' [-Warray-bounds=]
>> drivers/xen/privcmd.c:1258:67: warning: array subscript i is outside array bounds of 'struct ioreq_port[0]' [-Warray-bounds=]
>>
>> This results in no differences in binary output.
>>
>> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
>
> Looks right to me. I can see the allocation:
Yep, I always check for that; in particular, the 'counter' assignment. :)
Do you want me to mention it in the changelog text?
>
> size = struct_size(kioreq, ports, ioeventfd->vcpus);
> kioreq = kzalloc(size, GFP_KERNEL);
> if (!kioreq)
> return ERR_PTR(-ENOMEM);
>
> kioreq->dom = ioeventfd->dom;
> kioreq->vcpus = ioeventfd->vcpus;
>
>
> Reviewed-by: Kees Cook <keescook@chromium.org>
Thanks!
--
Gustavo
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH][next] xen: privcmd: Replace zero-length array with flex-array member and use __counted_by
2023-11-16 18:54 [PATCH][next] xen: privcmd: Replace zero-length array with flex-array member and use __counted_by Gustavo A. R. Silva
2023-11-16 21:08 ` Kees Cook
@ 2023-11-17 7:24 ` Juergen Gross
1 sibling, 0 replies; 4+ messages in thread
From: Juergen Gross @ 2023-11-17 7:24 UTC (permalink / raw)
To: Gustavo A. R. Silva, Stefano Stabellini, Oleksandr Tyshchenko
Cc: xen-devel, linux-kernel, linux-hardening
[-- Attachment #1.1.1: Type: text/plain, Size: 1535 bytes --]
On 16.11.23 19:54, Gustavo A. R. Silva wrote:
> Fake flexible arrays (zero-length and one-element arrays) are deprecated,
> and should be replaced by flexible-array members. So, replace
> zero-length array with a flexible-array member in `struct
> privcmd_kernel_ioreq`.
>
> Also annotate array `ports` with `__counted_by()` to prepare for the
> coming implementation by GCC and Clang of the `__counted_by` attribute.
> Flexible array members annotated with `__counted_by` can have their
> accesses bounds-checked at run-time via `CONFIG_UBSAN_BOUNDS` (for array
> indexing) and `CONFIG_FORTIFY_SOURCE` (for strcpy/memcpy-family functions).
>
> This fixes multiple -Warray-bounds warnings:
> drivers/xen/privcmd.c:1239:30: warning: array subscript i is outside array bounds of 'struct ioreq_port[0]' [-Warray-bounds=]
> drivers/xen/privcmd.c:1240:30: warning: array subscript i is outside array bounds of 'struct ioreq_port[0]' [-Warray-bounds=]
> drivers/xen/privcmd.c:1241:30: warning: array subscript i is outside array bounds of 'struct ioreq_port[0]' [-Warray-bounds=]
> drivers/xen/privcmd.c:1245:33: warning: array subscript i is outside array bounds of 'struct ioreq_port[0]' [-Warray-bounds=]
> drivers/xen/privcmd.c:1258:67: warning: array subscript i is outside array bounds of 'struct ioreq_port[0]' [-Warray-bounds=]
>
> This results in no differences in binary output.
>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Reviewed-by: Juergen Gross <jgross@suse.com>
Juergen
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3743 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-11-17 7:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-16 18:54 [PATCH][next] xen: privcmd: Replace zero-length array with flex-array member and use __counted_by Gustavo A. R. Silva
2023-11-16 21:08 ` Kees Cook
2023-11-16 21:18 ` Gustavo A. R. Silva
2023-11-17 7:24 ` Juergen Gross
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.