From: Adhemerval Zanella Date: Fri, 18 Apr 2025 12:49:59 +0000 (-0300) Subject: x86_64: Fix UB on plt rewrite X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8cc687cbacf4f2b9950e7ac4b3738e0add136098;p=thirdparty%2Fglibc.git x86_64: Fix UB on plt rewrite The elf/tst-plt-rewrite2 and elf/tst-plt-rewrite2 triggers the failures with ubsan: UBSAN: Undefined behaviour in ../sysdeps/x86_64/dl-machine.h:637:39 store to misaligned address 0x00007adb50230021 for type 'uint32_t' --- diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h index 572a1a7395..3799894589 100644 --- a/sysdeps/x86_64/dl-machine.h +++ b/sysdeps/x86_64/dl-machine.h @@ -633,7 +633,7 @@ x86_64_rewrite_plt (struct link_map *map, ElfW(Addr) plt_rewrite) /* Write out direct branch. */ *(uint8_t *) branch_start = JMP32_INSN_OPCODE; - *(uint32_t *) (branch_start + 1) = disp; + memcpy ((void *)(branch_start + 1), &disp, sizeof (uint32_t)); } else {