* [PATCH] drm/radeon: make -fstrict-flex-arrays=3 happy
@ 2024-04-15 13:38 Alex Deucher
2024-04-15 14:55 ` Christian König
2024-04-15 16:04 ` Kees Cook
0 siblings, 2 replies; 3+ messages in thread
From: Alex Deucher @ 2024-04-15 13:38 UTC (permalink / raw
To: amd-gfx; +Cc: Alex Deucher, Kees Cook
The driver parses a union where the layout up through the first
array is the same, however, the array has different sizes
depending on the elements in the union. Be explicit to
fix the UBSAN checker.
Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/3323
Fixes: df8fc4e934c1 ("kbuild: Enable -fstrict-flex-arrays=3")
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Cc: Kees Cook <keescook@chromium.org>
---
drivers/gpu/drm/radeon/radeon_atombios.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/radeon/radeon_atombios.c b/drivers/gpu/drm/radeon/radeon_atombios.c
index bb1f0a3371ab5..10793a433bf58 100644
--- a/drivers/gpu/drm/radeon/radeon_atombios.c
+++ b/drivers/gpu/drm/radeon/radeon_atombios.c
@@ -923,8 +923,12 @@ bool radeon_get_atom_connector_info_from_supported_devices_table(struct
max_device = ATOM_MAX_SUPPORTED_DEVICE_INFO;
for (i = 0; i < max_device; i++) {
- ATOM_CONNECTOR_INFO_I2C ci =
- supported_devices->info.asConnInfo[i];
+ ATOM_CONNECTOR_INFO_I2C ci;
+
+ if (frev > 1)
+ ci = supported_devices->info_2d1.asConnInfo[i];
+ else
+ ci = supported_devices->info.asConnInfo[i];
bios_connectors[i].valid = false;
--
2.44.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] drm/radeon: make -fstrict-flex-arrays=3 happy
2024-04-15 13:38 [PATCH] drm/radeon: make -fstrict-flex-arrays=3 happy Alex Deucher
@ 2024-04-15 14:55 ` Christian König
2024-04-15 16:04 ` Kees Cook
1 sibling, 0 replies; 3+ messages in thread
From: Christian König @ 2024-04-15 14:55 UTC (permalink / raw
To: Alex Deucher, amd-gfx; +Cc: Kees Cook
Am 15.04.24 um 15:38 schrieb Alex Deucher:
> The driver parses a union where the layout up through the first
> array is the same, however, the array has different sizes
> depending on the elements in the union. Be explicit to
> fix the UBSAN checker.
>
> Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/3323
> Fixes: df8fc4e934c1 ("kbuild: Enable -fstrict-flex-arrays=3")
> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
> Cc: Kees Cook <keescook@chromium.org>
Acked-by: Christian König <christian.koenig@amd.com>
But I have a bad feeling messing with that old code.
Regards,
Christian.
> ---
> drivers/gpu/drm/radeon/radeon_atombios.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/radeon_atombios.c b/drivers/gpu/drm/radeon/radeon_atombios.c
> index bb1f0a3371ab5..10793a433bf58 100644
> --- a/drivers/gpu/drm/radeon/radeon_atombios.c
> +++ b/drivers/gpu/drm/radeon/radeon_atombios.c
> @@ -923,8 +923,12 @@ bool radeon_get_atom_connector_info_from_supported_devices_table(struct
> max_device = ATOM_MAX_SUPPORTED_DEVICE_INFO;
>
> for (i = 0; i < max_device; i++) {
> - ATOM_CONNECTOR_INFO_I2C ci =
> - supported_devices->info.asConnInfo[i];
> + ATOM_CONNECTOR_INFO_I2C ci;
> +
> + if (frev > 1)
> + ci = supported_devices->info_2d1.asConnInfo[i];
> + else
> + ci = supported_devices->info.asConnInfo[i];
>
> bios_connectors[i].valid = false;
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] drm/radeon: make -fstrict-flex-arrays=3 happy
2024-04-15 13:38 [PATCH] drm/radeon: make -fstrict-flex-arrays=3 happy Alex Deucher
2024-04-15 14:55 ` Christian König
@ 2024-04-15 16:04 ` Kees Cook
1 sibling, 0 replies; 3+ messages in thread
From: Kees Cook @ 2024-04-15 16:04 UTC (permalink / raw
To: Alex Deucher; +Cc: amd-gfx
On Mon, Apr 15, 2024 at 09:38:16AM -0400, Alex Deucher wrote:
> The driver parses a union where the layout up through the first
> array is the same, however, the array has different sizes
> depending on the elements in the union. Be explicit to
> fix the UBSAN checker.
>
> Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/3323
> Fixes: df8fc4e934c1 ("kbuild: Enable -fstrict-flex-arrays=3")
> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
> Cc: Kees Cook <keescook@chromium.org>
Yup, this looks correct to me. These were trailing arrays that were not
bounds checked prior to -fstrict-flex-arrays=3:
#define ATOM_DEVICE_DFP3_INDEX 0x00000009
...
#define ATOM_DEVICE_DFP5_INDEX 0x0000000B
...
#define ATOM_DEVICE_RESERVEDF_INDEX 0x0000000F
...
#define ATOM_MAX_SUPPORTED_DEVICE_INFO (ATOM_DEVICE_DFP3_INDEX+1)
...
#define ATOM_MAX_SUPPORTED_DEVICE (ATOM_DEVICE_RESERVEDF_INDEX+1)
typedef struct _ATOM_SUPPORTED_DEVICES_INFO
...
ATOM_CONNECTOR_INFO_I2C asConnInfo[ATOM_MAX_SUPPORTED_DEVICE_INFO];
typedef struct _ATOM_SUPPORTED_DEVICES_INFO_2
...
ATOM_CONNECTOR_INFO_I2C asConnInfo[ATOM_MAX_SUPPORTED_DEVICE];
And these arrays had different sizes: 10 vs 16
Reviewed-by: Kees Cook <keescook@chromium.org>
-Kees
> ---
> drivers/gpu/drm/radeon/radeon_atombios.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/radeon_atombios.c b/drivers/gpu/drm/radeon/radeon_atombios.c
> index bb1f0a3371ab5..10793a433bf58 100644
> --- a/drivers/gpu/drm/radeon/radeon_atombios.c
> +++ b/drivers/gpu/drm/radeon/radeon_atombios.c
> @@ -923,8 +923,12 @@ bool radeon_get_atom_connector_info_from_supported_devices_table(struct
> max_device = ATOM_MAX_SUPPORTED_DEVICE_INFO;
>
> for (i = 0; i < max_device; i++) {
> - ATOM_CONNECTOR_INFO_I2C ci =
> - supported_devices->info.asConnInfo[i];
> + ATOM_CONNECTOR_INFO_I2C ci;
> +
> + if (frev > 1)
> + ci = supported_devices->info_2d1.asConnInfo[i];
> + else
> + ci = supported_devices->info.asConnInfo[i];
>
> bios_connectors[i].valid = false;
>
> --
> 2.44.0
>
--
Kees Cook
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-04-16 12:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-15 13:38 [PATCH] drm/radeon: make -fstrict-flex-arrays=3 happy Alex Deucher
2024-04-15 14:55 ` Christian König
2024-04-15 16:04 ` Kees Cook
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.