criu/include/common
Adrian Reber 4bcf08ce7f compel: fix heap alignment for structs with xsave state
struct parasite_ctl, parasite_thread_ctl, and plain_regs_struct
all contain user_fpregs_struct_t (typedef for struct xsave_struct),
which is declared with __aligned(64). When these structs are
allocated on the heap with xmalloc/xzalloc (i.e. malloc/calloc),
the allocator only guarantees 16-byte alignment on x86_64.

The compiler, seeing the __aligned(64) attribute on the struct
type, may emit aligned memory instructions (e.g. movaps, vmovdqa)
for struct copies, assuming the memory is properly aligned. When
the heap pointer is not 64-byte aligned, these instructions trigger
a General Protection Fault (#GP).

This was observed as a crash in save_regs_plain() at infect.c:1314
(prs->regs = *r) on CentOS Stream 10 under QEMU/KVM, where the
compiler generated aligned vector instructions for the struct copy.
The crash did not reproduce on bare metal with a different compiler
version that happened to emit unaligned instructions.

Add xmemalign() wrapper around posix_memalign() to xmalloc.h and
use it for all three allocation sites:
 - compel_prepare_noctx(): struct parasite_ctl
 - compel_prepare_thread(): struct parasite_thread_ctl
 - compel_prepare(): struct plain_regs_struct

Memory from posix_memalign() can be freed with free(), so no
changes to cleanup paths are needed.

Assisted-by: Claude:claude-opus-4-6
Signed-off-by: Adrian Reber <areber@redhat.com>
2026-03-25 04:31:18 +01:00
..
arch loongarch64: implement atomic_dec_and_test 2026-03-12 18:03:08 +00:00
asm-generic asm: fix for_each_bit macro 2023-04-15 21:17:21 -07:00
bitops.h Run 'make indent' on header files 2021-09-03 10:31:00 -07:00
bitsperlong.h
bug.h Run 'make indent' on header files 2021-09-03 10:31:00 -07:00
compiler.h compiler: add ALIGN_DOWN macro 2024-09-11 16:02:11 -07:00
err.h Run 'make indent' on header files 2021-09-03 10:31:00 -07:00
list.h Run 'make indent' on header files 2021-09-03 10:31:00 -07:00
lock.h criu: fix log_keep_err signal deadlock 2025-03-25 14:31:33 -07:00
page.h
scm-code.c Fix some codespell warnings 2022-04-28 17:53:52 -07:00
scm.h ci: fix new codespell errors 2023-10-22 13:29:25 -07:00
xmalloc.h compel: fix heap alignment for structs with xsave state 2026-03-25 04:31:18 +01:00