crypto: nx - Fix packed layout in struct nx842_crypto_header
Subsystems (3)
PATCH 1/1 crypto: nx - Fix packed layout in struct nx842_crypto_header
struct nx842_crypto_header is declared with the __packed attribute,
however the fields grouped with struct_group_tagged() were not packed.
This caused the grouped header portion of the structure to lose the packed layout guarantees of the containing structure.
Fix this by replacing struct_group_tagged() with __struct_group(..., ..., __packed, ...) so the grouped fields are packed, and the original layout is preserved, restoring the intended packed layout of the structure.
Before changes:
struct nx842_crypto_header {
union {
struct {
__be16 magic; /* 0 2 */
__be16 ignore; /* 2 2 */
u8 groups; /* 4 1 */
}; /* 0 6 */
struct nx842_crypto_header_hdr hdr; /* 0 6 */
}; /* 0 6 */
struct nx842_crypto_header_group group[]; /* 6 0 */
/* size: 6, cachelines: 1, members: 2 */
/* last cacheline: 6 bytes */
} __attribute__((__packed__));After changes:
struct nx842_crypto_header {
union {
struct {
__be16 magic; /* 0 2 */
__be16 ignore; /* 2 2 */
u8 groups; /* 4 1 */
} __attribute__((__packed__)); /* 0 5 */
struct nx842_crypto_header_hdr hdr; /* 0 5 */
}; /* 0 5 */
struct nx842_crypto_header_group group[]; /* 5 0 */
/* size: 5, cachelines: 1, members: 2 */
/* last cacheline: 5 bytes */
} __attribute__((__packed__));--- drivers/crypto/nx/nx-842.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/crypto/nx/nx-842.h +2 -2
@@ -159,7 +159,7 @@ struct nx842_crypto_header_group {struct nx842_crypto_header {/* New members MUST be added within the struct_group() macro below. */ - struct_group_tagged(nx842_crypto_header_hdr, hdr, + __struct_group(nx842_crypto_header_hdr, hdr, __packed, __be16 magic; /* NX842_CRYPTO_MAGIC */__be16 ignore;/* decompressed end bytes to ignore */ u8 groups;/* total groups in this header */
@@ -167,7 +167,7 @@ struct nx842_crypto_header {struct nx842_crypto_header_group group[]; } __packed;static_assert (offsetof(struct nx842_crypto_header , group) ==sizeof (struct nx842_crypto_header_hdr ), -"struct member likely outside of struct_group_tagged()" ); +"struct member likely outside of __struct_group()" );#define NX842_CRYPTO_GROUP_MAX (0x20)
Signature · 1 line
2.43.0
Quoted 42 lines · Gustavo A. R. Silva
struct
nx842_crypto_headeris declared with the__packedattribute,
however the fields grouped withstruct_group_tagged()were not packed.
This caused the grouped header portion of the structure to lose the packed layout guarantees of the containing structure.Fix this by replacing
struct_group_tagged()with__struct_group(..., ..., __packed, ...)so the grouped fields are packed, and the original layout is preserved, restoring the intended packed layout of the structure.Before changes:
struct nx842_crypto_header { union { struct { __be16 magic; /* 0 2 */ __be16 ignore; /* 2 2 */ u8 groups; /* 4 1 */ }; /* 0 6 */ struct nx842_crypto_header_hdr hdr; /* 0 6 */ }; /* 0 6 */ struct nx842_crypto_header_group group[]; /* 6 0 */ /* size: 6, cachelines: 1, members: 2 */ /* last cacheline: 6 bytes */ } __attribute__((__packed__));After changes:
struct nx842_crypto_header { union { struct { __be16 magic; /* 0 2 */ __be16 ignore; /* 2 2 */ u8 groups; /* 4 1 */ } __attribute__((__packed__)); /* 0 5 */ struct nx842_crypto_header_hdr hdr; /* 0 5 */ }; /* 0 5 */ struct nx842_crypto_header_group group[]; /* 5 0 */ /* size: 5, cachelines: 1, members: 2 */ /* last cacheline: 5 bytes */ } __attribute__((__packed__));
Quoted 6 lines
Fixes 1e6b251ce175 ("crypto: nx - Avoid -Wflex-array-member-not-at-end warning")Signed-off-by Gustavo A. R. Silva <[email protected]>--- drivers/crypto/nx/nx-842.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Herbert Xu
maintainerQuoted 42 lines · Gustavo A. R. Silva
struct
nx842_crypto_headeris declared with the__packedattribute,
however the fields grouped withstruct_group_tagged()were not packed.
This caused the grouped header portion of the structure to lose the packed layout guarantees of the containing structure.Fix this by replacing
struct_group_tagged()with__struct_group(..., ..., __packed, ...)so the grouped fields are packed, and the original layout is preserved, restoring the intended packed layout of the structure.Before changes:
struct nx842_crypto_header { union { struct { __be16 magic; /* 0 2 */ __be16 ignore; /* 2 2 */ u8 groups; /* 4 1 */ }; /* 0 6 */ struct nx842_crypto_header_hdr hdr; /* 0 6 */ }; /* 0 6 */ struct nx842_crypto_header_group group[]; /* 6 0 */ /* size: 6, cachelines: 1, members: 2 */ /* last cacheline: 6 bytes */ } __attribute__((__packed__));After changes:
struct nx842_crypto_header { union { struct { __be16 magic; /* 0 2 */ __be16 ignore; /* 2 2 */ u8 groups; /* 4 1 */ } __attribute__((__packed__)); /* 0 5 */ struct nx842_crypto_header_hdr hdr; /* 0 5 */ }; /* 0 5 */ struct nx842_crypto_header_group group[]; /* 5 0 */ /* size: 5, cachelines: 1, members: 2 */ /* last cacheline: 5 bytes */ } __attribute__((__packed__));
Quoted 6 lines
Fixes 1e6b251ce175 ("crypto: nx - Avoid -Wflex-array-member-not-at-end warning")Signed-off-by Gustavo A. R. Silva <[email protected]>--- drivers/crypto/nx/nx-842.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Patch applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt