criu/compel/src/lib
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
..
handle-elf-host.c compel: Build host program 2017-03-14 23:58:10 +03:00
handle-elf.c Fix some codespell warnings 2022-04-28 17:53:52 -07:00
infect-rpc.c Run 'make indent' on all C files 2021-09-03 10:31:00 -07:00
infect-util.c criu: use libuuid for criu_run_id generation 2025-03-21 12:40:31 -07:00
infect.c compel: fix heap alignment for structs with xsave state 2026-03-25 04:31:18 +01:00
log-host.c compel: Add callback-based log engine 2017-03-15 00:06:02 +03:00
log.c compel: Remove compel.h 2020-03-27 19:36:20 +03:00
ptrace.c compel: set TRACESYSGOOD to distinguish breakpoints from syscalls 2023-04-15 21:17:21 -07:00