Skip to contentSkip to conversation

media: mali-c55: add padding to mali_c55_params_ccm structure

PATCH In review Arnd Bergmann 5 participants 6 messages Sep 15 – Sep 30

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: mali-c55: add padding to mali_c55_params_ccm structure

From: Arnd Bergmann <[email protected]>

The newly added structure has extra padding on the on some architectures, which triggers a pedantic uapi check:

./usr/include/linux/media/arm/mali-c55-config.h:807:1: error: padding struct size to alignment boundary with 2 bytes [-Werror=padded]

Add explicit padding here to avoid risking information leaks and incompatibilities between architectures.

Fixes bb401df68c06 ("media: mali-c55: Add support for CCM")
---
 include/uapi/linux/media/arm/mali-c55-config.h | 1 +
 1 file changed, 1 insertion(+)
include/uapi/linux/media/arm/mali-c55-config.h +1 -0
index 84d8f3901405..9c922290e035 100644
@@ -804,6 +804,7 @@ struct mali_c55_params_ccm {
 	__u16 coeffs[3][3];
 	__u16 gains[3];
 	__u16 offs[3];
+	__u16 __pad;
 };
 
 /**
Signature · 1 line
2.53.0
#1 lore raw

Hi Arnd,

quick question since you are mentioning information leaking in the commit message.

Quoted 21 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The newly added structure has extra padding on the on some architectures, which triggers a pedantic uapi check:

./usr/include/linux/media/arm/mali-c55-config.h:807:1: error: padding struct size to alignment boundary with 2 bytes [-Werror=padded]

Add explicit padding here to avoid risking information leaks and incompatibilities between architectures.

Fixes bb401df68c06 ("media: mali-c55: Add support for CCM")
---
 include/uapi/linux/media/arm/mali-c55-config.h | 1 +
 1 file changed, 1 insertion(+)
include/uapi/linux/media/arm/mali-c55-config.h +0 -0
index 84d8f3901405..9c922290e035 100644

include/uapi/linux/media/arm/mali-c55-config.h struct mali_c55_params_ccm { · line 807

Quoted 4 lines
include/uapi/linux/media/arm/mali-c55-config.h +1 -0
@@ -804,6 +804,7 @@ struct mali_c55_params_ccm {
 	__u16 coeffs[3][3];
 	__u16 gains[3];
 	__u16 offs[3];
+	__u16 __pad;

Does this field need to be explicitly zeroed/validated anywhere the structure is populated? Turning implicit padding into a named member fixes the layout warning, but by itself does not seem to prevent leaking uninitialized data if this structure is ever copied from the kernel to userspace. It might also be worth documenting that __pad is reserved and must be zero.

I think you already checked that changing the explicit structure layout/size is safe for existing userspace :)

Quoted 3 lines
include/uapi/linux/media/arm/mali-c55-config.h +0 -0
 };
 
 /**
Signature · 2 lines
Regards,
Vincenzo
#2 lore raw
Quoted 7 lines · Vincenzo Frascino
Quoted 7 lines
include/uapi/linux/media/arm/mali-c55-config.h +0 -0
index 84d8f3901405..9c922290e035 100644
@@ -804,6 +804,7 @@ struct mali_c55_params_ccm {
 	__u16 coeffs[3][3];
 	__u16 gains[3];
Quoted 8 lines

include/uapi/linux/media/arm/mali-c55-config.h struct mali_c55_params_ccm { · line 807

Quoted 2 lines
include/uapi/linux/media/arm/mali-c55-config.h +1 -0
 	__u16 offs[3];
+	__u16 __pad;

Does this field need to be explicitly zeroed/validated anywhere the structure is populated? Turning implicit padding into a named member fixes the layout warning, but by itself does not seem to prevent leaking uninitialized data if this structure is ever copied from the kernel to userspace. It might also be worth documenting that __pad is reserved and must be zero.

It depends on how the structure is initialized. Depending on the compiler version and optimization level, a local variable declared as

   struct mali_c55_params_ccm v = {};

may end up with uninitialized stack data in unnamed padding, but if you do a memset(), that should always be safe. If the fields are set individually, then you also have to set the __pad field, but that's not how you do it here.

Quoted 2 lines

I think you already checked that changing the explicit structure layout/size is safe for existing userspace :)

On all architectures other than m68k, the position of the struct members and the struct size are unchanged by my patch. On m68k. there is no implied padding at the end of this structure, so this is theoretically an ABI change, but nobody has a mali device on m68k, so we know that it is safe.

Arnd

Reviewed-by
#3 lore raw
Quoted 8 lines · Arnd Bergmann

It depends on how the structure is initialized. Depending on the compiler version and optimization level, a local variable declared as

   struct mali_c55_params_ccm v = {};

may end up with uninitialized stack data in unnamed padding, but if you do a memset(), that should always be safe. If the fields are set individually, then you also have to set the __pad field, but that's not how you do it here.

Fine by me. With this:

Signature · 2 lines
Regards,
Vincenzo
Reviewed-by on v1 1/1
#4 lore raw
In reply to Arnd Bergmann
Quoted 5 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The newly added structure has extra padding on the on some architectures, which triggers a pedantic uapi check:

Quoted 7 lines

./usr/include/linux/media/arm/mali-c55-config.h:807:1: error: padding struct size to alignment boundary with 2 bytes [-Werror=padded]

Add explicit padding here to avoid risking information leaks and incompatibilities between architectures.

Fixes bb401df68c06 ("media: mali-c55: Add support for CCM")

Yours,
Linus Walleij

maintainer
#5 lore raw
In reply to Arnd Bergmann

Hi Arnd

Quoted 5 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The newly added structure has extra padding on the on some architectures, which triggers a pedantic uapi check:

Quoted 7 lines

./usr/include/linux/media/arm/mali-c55-config.h:807:1: error: padding struct size to alignment boundary with 2 bytes [-Werror=padded]

Add explicit padding here to avoid risking information leaks and incompatibilities between architectures.

Fixes bb401df68c06 ("media: mali-c55: Add support for CCM")

The documentation of the newly added field is missing, triggering a warning when building the documentation

https://gitlab.freedesktop.org/linux-media/users/patchwork/-/jobs/110343884

WARNING: ./include/uapi/linux/media/arm/mali-c55-config.h:803 struct member '__pad' not described in 'mali_c55_params_ccm'

I am about to send a PR collecting all mali-related changes, I can add

* @__pad: Padding bytes

To the documentation of struct mali_c55_params_ccm.

Quoted 20 lines
---
 include/uapi/linux/media/arm/mali-c55-config.h | 1 +
 1 file changed, 1 insertion(+)
include/uapi/linux/media/arm/mali-c55-config.h +1 -1
index 84d8f3901405..9c922290e035 100644
@@ -804,6 +804,7 @@ struct mali_c55_params_ccm {
 	__u16 coeffs[3][3];
 	__u16 gains[3];
 	__u16 offs[3];
+	__u16 __pad;
 };
 
 /**
--

2.53.0