public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc] arm: Avoid UB in elf_machine_rel()
@ 2024-06-26 10:46 Andreas K. Huttel
  0 siblings, 0 replies; only message in thread
From: Andreas K. Huttel @ 2024-06-26 10:46 UTC (permalink / raw)
  To: glibc-cvs

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

commit 07fe71f59b13bbc336ece3ec9ef94dd95c9e0511
Author: Palmer Dabbelt <palmer@rivosinc.com>
Date:   Thu Jun 23 14:49:32 2022 -0700

    arm: Avoid UB in elf_machine_rel()
    
    This recently came up during a cleanup to remove misaligned accesses
    from the RISC-V port.
    
    Link: https://sourceware.org/pipermail/libc-alpha/2022-June/139961.html
    Suggested-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
    Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
    Reviewed-by: Fangrui Song <maskray@google.com>

Diff:
---
 sysdeps/arm/dl-machine.h | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/sysdeps/arm/dl-machine.h b/sysdeps/arm/dl-machine.h
index dd1a0f6b6e..9186831be3 100644
--- a/sysdeps/arm/dl-machine.h
+++ b/sysdeps/arm/dl-machine.h
@@ -349,10 +349,7 @@ elf_machine_rel (struct link_map *map, struct r_scope_elem *scope[],
 	  break;
 	case R_ARM_ABS32:
 	  {
-	    struct unaligned
-	      {
-		Elf32_Addr x;
-	      } __attribute__ ((packed, may_alias));
+	    ElfW(Addr) tmp;
 # ifndef RTLD_BOOTSTRAP
 	   /* This is defined in rtld.c, but nowhere in the static
 	      libc.a; make the reference weak so static programs can
@@ -372,7 +369,9 @@ elf_machine_rel (struct link_map *map, struct r_scope_elem *scope[],
 	      value -= SYMBOL_ADDRESS (map, refsym, true);
 # endif
 	    /* Support relocations on mis-aligned offsets.  */
-	    ((struct unaligned *) reloc_addr)->x += value;
+	    memcpy (&tmp, reloc_addr, sizeof tmp);
+	    tmp += value;
+	    memcpy (reloc_addr, &tmp, sizeof tmp);
 	    break;
 	  }
 	case R_ARM_TLS_DESC:

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-06-26 10:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-26 10:46 [glibc] arm: Avoid UB in elf_machine_rel() Andreas K. Huttel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).