Thread (4 messages) 4 messages, 2 authors, 2025-07-24

Re: [PATCH] bootconfig: Fix unaligned access when building footer

From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Date: 2025-07-24 01:10:47
Also in: lkml

On Wed, 23 Jul 2025 22:20:35 +0200
Ben Hutchings [off-list ref] wrote:
On Thu, 2025-07-24 at 00:37 +0900, Masami Hiramatsu wrote:
quoted
On Wed, 23 Jul 2025 12:49:25 +0200
Ben Hutchings [off-list ref] wrote:
[...]
quoted
quoted
 static int apply_xbc(const char *path, const char *xbc_path)
 {
-	char *buf, *data, *p;
+	struct {
+		uint32_t size;
+		uint32_t csum;
+		char magic[BOOTCONFIG_MAGIC_LEN];
+	} footer;
Don't we need __attribute__((__packed__)) for the footer?
I don't see any reason for there to be padding in this structure, since
it has an alignment of 4 and the size of each member is a multiple of 4.

I included an assertion that there is no padding:

[...]
quoted
quoted
+	memcpy(footer.magic, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN);
+	static_assert(sizeof(footer) == BOOTCONFIG_FOOTER_SIZE);
+	memcpy(data + size, &footer, BOOTCONFIG_FOOTER_SIZE);
[...]
OK, if we saw the assertion error, we'll add packed attribute.
Let me pick it as it is.

Thank you!

Ben.

-- 
Ben Hutchings - Debian developer, member of kernel, installer and LTS
teams

-- 
Masami Hiramatsu (Google) [off-list ref]
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help