[glibc/azanella/ubsan-undef] x86_64: Fix UB on plt rewrite

Adhemerval Zanella azanella@sourceware.org
Wed May 7 14:13:33 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=b56ea5e8b96238d420044824dbf805c114fd6787

commit b56ea5e8b96238d420044824dbf805c114fd6787
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Fri Apr 18 09:49:59 2025 -0300

    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:
---
 sysdeps/x86_64/dl-machine.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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
 	  {


More information about the Glibc-cvs mailing list