From b31d085855f6ff0db5f465ed936cbce1b69d366c Mon Sep 17 00:00:00 2001From: Andrew <andreasx0@protonmail.com>
Date: Sun, 29 Jun 2025 15:33:26 +0300
Subject: [PATCH] x86/dmi: Fix misaligned dmi_alloc use on dmi_scan.c by using struct alignment
On x86, dmi_alloc() uses extend_brk() with only 4-byte alignment,
which can cause UBSAN warnings when accessing struct dmi_device,
whose members require 8-byte alignment.
Fix this by aligning allocations to the maximum of sizeof(int) and
__alignof__(struct dmi_device).
Signed-off-by: Andrew <andreasx0@protonmail.com>
---
arch/x86/include/asm/dmi.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/include/asm/dmi.h b/arch/x86/include/asm/dmi.h
index b825cb201251..2d6c3bea718c 100644
--- a/arch/x86/include/asm/dmi.h
+++ b/arch/x86/include/asm/dmi.h
@@ -10,7 +10,7 @@
static __always_inline __init void *dmi_alloc(unsigned len)
{
- return extend_brk(len, sizeof(int));
+ return extend_brk(len, max_t(size_t, sizeof(int), __alignof__(struct dmi_device)));
}
/* Use early IO mappings for DMI because it's initialized early */
--
2.50.0
/* SPDX-License-Identifier: GPL-2.0 */#ifndef _ASM_X86_DMI_H
#define _ASM_X86_DMI_H
#include <linux/compiler.h>
#include <linux/init.h>
#include <linux/io.h>
#include <asm/setup.h>
static __always_inline __init void *dmi_alloc(unsigned len)
{
return extend_brk(len, max_t(size_t, sizeof(int), __alignof__(struct dmi_device)));
}
/* Use early IO mappings for DMI because it's initialized early */
#define dmi_early_remap early_memremap
#define dmi_early_unmap early_memunmap
#define dmi_remap(_x, _l) memremap(_x, _l, MEMREMAP_WB)
#define dmi_unmap(_x) memunmap(_x)
#endif /* _ASM_X86_DMI_H */