public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/arm/morello/main] aarch64: morello: Return bounded pointer in __tls_get_addr
@ 2022-10-27 13:58 Szabolcs Nagy
  0 siblings, 0 replies; 3+ messages in thread
From: Szabolcs Nagy @ 2022-10-27 13:58 UTC (permalink / raw)
  To: glibc-cvs

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

commit 726db8b202d57c61af8ef00f883688b5596d0318
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date:   Wed Sep 7 14:17:46 2022 +0100

    aarch64: morello: Return bounded pointer in __tls_get_addr
    
    There is no traditional TLS support in morello that would explicitly
    call __tls_get_addr, but the libc uses it internally and the returned
    pointer escapes to user code.  So bound the pointers according to
    the tls symbol size instead of doing so in each caller.
    
    (Affects dlsym and dynamic TLSDESC.)

Diff:
---
 elf/dl-sym.c                         |  4 ++++
 sysdeps/aarch64/morello/dl-tls.c     | 39 ++++++++++++++++++++++++++++++++++++
 sysdeps/aarch64/morello/dl-tls.h     | 26 ++++++++++++++++++++++++
 sysdeps/aarch64/morello/dl-tlsdesc.S |  9 ---------
 4 files changed, 69 insertions(+), 9 deletions(-)

diff --git a/elf/dl-sym.c b/elf/dl-sym.c
index b1cf42f36d..cd7df7e6c7 100644
--- a/elf/dl-sym.c
+++ b/elf/dl-sym.c
@@ -49,6 +49,10 @@ _dl_tls_symaddr (struct link_map *map, const ElfW(Sym) *ref)
     {
       .ti_module = map->l_tls_modid,
       .ti_offset = ref->st_value
+#  ifdef __CHERI_PURE_CAPABILITY__
+	,
+      .ti_size = ref->st_size
+#  endif
     };
 
   return __TLS_GET_ADDR (&tmp);
diff --git a/sysdeps/aarch64/morello/dl-tls.c b/sysdeps/aarch64/morello/dl-tls.c
new file mode 100644
index 0000000000..6fadfe2350
--- /dev/null
+++ b/sysdeps/aarch64/morello/dl-tls.c
@@ -0,0 +1,39 @@
+/* Thread-local storage handling in the ELF dynamic linker.  Morello version.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#ifdef SHARED
+/* Add a wrapper around the generic __tls_get_addr code to set the
+   bounds on the returned pointer.  */
+
+# define __tls_get_addr __tls_get_addr_unbounded
+# include <elf/dl-tls.c>
+# undef __tls_get_addr
+
+void *__tls_get_addr (tls_index *ti);
+rtld_hidden_proto (__tls_get_addr)
+rtld_hidden_def (__tls_get_addr)
+
+void *
+__tls_get_addr (tls_index *ti)
+{
+  void *p = __tls_get_addr_unbounded (ti);
+  return __builtin_cheri_bounds_set_exact (p, ti->ti_size);
+}
+#else
+# include <elf/dl-tls.c>
+#endif
diff --git a/sysdeps/aarch64/morello/dl-tls.h b/sysdeps/aarch64/morello/dl-tls.h
new file mode 100644
index 0000000000..f47f89ca64
--- /dev/null
+++ b/sysdeps/aarch64/morello/dl-tls.h
@@ -0,0 +1,26 @@
+/* Copyright (C) 2022 Free Software Foundation, Inc.
+
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public License as
+   published by the Free Software Foundation; either version 2.1 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+typedef struct
+{
+  unsigned long int ti_module;
+  unsigned long int ti_offset;
+  unsigned long int ti_size;
+} tls_index;
+
+extern void *__tls_get_addr (tls_index *ti);
diff --git a/sysdeps/aarch64/morello/dl-tlsdesc.S b/sysdeps/aarch64/morello/dl-tlsdesc.S
index 6fced53734..d11f5d5fa7 100644
--- a/sysdeps/aarch64/morello/dl-tlsdesc.S
+++ b/sysdeps/aarch64/morello/dl-tlsdesc.S
@@ -193,18 +193,9 @@ _dl_tlsdesc_dynamic:
 
 	SAVE_Q_REGISTERS
 
-	/* TODO: remove once __tls_get_addr is fixed.  */
-	str	c1, [csp, #32*8]
-
 	mov	c0, c1
 	bl	__tls_get_addr
 
-	/* TODO: __tls_get_addr should return bounded pointer,
-	   currently it does not so bound it here.  */
-	ldr	c1, [csp, #32*8]
-	ldr	x3, [c1, #TLSDESC_SIZE]
-	scbndse	c0, c0, x3
-
 	mrs	c2, ctpidr_el0 /* Restore c2.  */
 
 	RESTORE_Q_REGISTERS

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [glibc/arm/morello/main] aarch64: morello: Return bounded pointer in __tls_get_addr
@ 2022-11-23 14:48 Szabolcs Nagy
  0 siblings, 0 replies; 3+ messages in thread
From: Szabolcs Nagy @ 2022-11-23 14:48 UTC (permalink / raw)
  To: glibc-cvs

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

commit b9af312764f7a1f8d0c9c11118bbceae28c950f4
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date:   Wed Sep 7 14:17:46 2022 +0100

    aarch64: morello: Return bounded pointer in __tls_get_addr
    
    There is no traditional TLS support in morello that would explicitly
    call __tls_get_addr, but the libc uses it internally and the returned
    pointer escapes to user code.  So bound the pointers according to
    the tls symbol size instead of doing so in each caller.
    
    (Affects dlsym and dynamic TLSDESC.)

Diff:
---
 elf/dl-sym.c                         |  4 ++++
 sysdeps/aarch64/morello/dl-tls.c     | 39 ++++++++++++++++++++++++++++++++++++
 sysdeps/aarch64/morello/dl-tls.h     | 26 ++++++++++++++++++++++++
 sysdeps/aarch64/morello/dl-tlsdesc.S |  9 ---------
 4 files changed, 69 insertions(+), 9 deletions(-)

diff --git a/elf/dl-sym.c b/elf/dl-sym.c
index b1cf42f36d..cd7df7e6c7 100644
--- a/elf/dl-sym.c
+++ b/elf/dl-sym.c
@@ -49,6 +49,10 @@ _dl_tls_symaddr (struct link_map *map, const ElfW(Sym) *ref)
     {
       .ti_module = map->l_tls_modid,
       .ti_offset = ref->st_value
+#  ifdef __CHERI_PURE_CAPABILITY__
+	,
+      .ti_size = ref->st_size
+#  endif
     };
 
   return __TLS_GET_ADDR (&tmp);
diff --git a/sysdeps/aarch64/morello/dl-tls.c b/sysdeps/aarch64/morello/dl-tls.c
new file mode 100644
index 0000000000..6fadfe2350
--- /dev/null
+++ b/sysdeps/aarch64/morello/dl-tls.c
@@ -0,0 +1,39 @@
+/* Thread-local storage handling in the ELF dynamic linker.  Morello version.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#ifdef SHARED
+/* Add a wrapper around the generic __tls_get_addr code to set the
+   bounds on the returned pointer.  */
+
+# define __tls_get_addr __tls_get_addr_unbounded
+# include <elf/dl-tls.c>
+# undef __tls_get_addr
+
+void *__tls_get_addr (tls_index *ti);
+rtld_hidden_proto (__tls_get_addr)
+rtld_hidden_def (__tls_get_addr)
+
+void *
+__tls_get_addr (tls_index *ti)
+{
+  void *p = __tls_get_addr_unbounded (ti);
+  return __builtin_cheri_bounds_set_exact (p, ti->ti_size);
+}
+#else
+# include <elf/dl-tls.c>
+#endif
diff --git a/sysdeps/aarch64/morello/dl-tls.h b/sysdeps/aarch64/morello/dl-tls.h
new file mode 100644
index 0000000000..f47f89ca64
--- /dev/null
+++ b/sysdeps/aarch64/morello/dl-tls.h
@@ -0,0 +1,26 @@
+/* Copyright (C) 2022 Free Software Foundation, Inc.
+
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public License as
+   published by the Free Software Foundation; either version 2.1 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+typedef struct
+{
+  unsigned long int ti_module;
+  unsigned long int ti_offset;
+  unsigned long int ti_size;
+} tls_index;
+
+extern void *__tls_get_addr (tls_index *ti);
diff --git a/sysdeps/aarch64/morello/dl-tlsdesc.S b/sysdeps/aarch64/morello/dl-tlsdesc.S
index 6fced53734..d11f5d5fa7 100644
--- a/sysdeps/aarch64/morello/dl-tlsdesc.S
+++ b/sysdeps/aarch64/morello/dl-tlsdesc.S
@@ -193,18 +193,9 @@ _dl_tlsdesc_dynamic:
 
 	SAVE_Q_REGISTERS
 
-	/* TODO: remove once __tls_get_addr is fixed.  */
-	str	c1, [csp, #32*8]
-
 	mov	c0, c1
 	bl	__tls_get_addr
 
-	/* TODO: __tls_get_addr should return bounded pointer,
-	   currently it does not so bound it here.  */
-	ldr	c1, [csp, #32*8]
-	ldr	x3, [c1, #TLSDESC_SIZE]
-	scbndse	c0, c0, x3
-
 	mrs	c2, ctpidr_el0 /* Restore c2.  */
 
 	RESTORE_Q_REGISTERS

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [glibc/arm/morello/main] aarch64: morello: Return bounded pointer in __tls_get_addr
@ 2022-10-26 15:20 Szabolcs Nagy
  0 siblings, 0 replies; 3+ messages in thread
From: Szabolcs Nagy @ 2022-10-26 15:20 UTC (permalink / raw)
  To: glibc-cvs

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

commit 82dc687662ad4ca15dcbf0a0886b95ebf2810d2f
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date:   Wed Sep 7 14:17:46 2022 +0100

    aarch64: morello: Return bounded pointer in __tls_get_addr
    
    There is no traditional TLS support in morello that would explicitly
    call __tls_get_addr, but the libc uses it internally and the returned
    pointer escapes to user code.  So bound the pointers according to
    the tls symbol size instead of doing so in each caller.
    
    (Affects dlsym and dynamic TLSDESC.)

Diff:
---
 elf/dl-sym.c                         |  4 ++++
 sysdeps/aarch64/morello/dl-tls.c     | 39 ++++++++++++++++++++++++++++++++++++
 sysdeps/aarch64/morello/dl-tls.h     | 26 ++++++++++++++++++++++++
 sysdeps/aarch64/morello/dl-tlsdesc.S |  9 ---------
 4 files changed, 69 insertions(+), 9 deletions(-)

diff --git a/elf/dl-sym.c b/elf/dl-sym.c
index b1cf42f36d..cd7df7e6c7 100644
--- a/elf/dl-sym.c
+++ b/elf/dl-sym.c
@@ -49,6 +49,10 @@ _dl_tls_symaddr (struct link_map *map, const ElfW(Sym) *ref)
     {
       .ti_module = map->l_tls_modid,
       .ti_offset = ref->st_value
+#  ifdef __CHERI_PURE_CAPABILITY__
+	,
+      .ti_size = ref->st_size
+#  endif
     };
 
   return __TLS_GET_ADDR (&tmp);
diff --git a/sysdeps/aarch64/morello/dl-tls.c b/sysdeps/aarch64/morello/dl-tls.c
new file mode 100644
index 0000000000..6fadfe2350
--- /dev/null
+++ b/sysdeps/aarch64/morello/dl-tls.c
@@ -0,0 +1,39 @@
+/* Thread-local storage handling in the ELF dynamic linker.  Morello version.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#ifdef SHARED
+/* Add a wrapper around the generic __tls_get_addr code to set the
+   bounds on the returned pointer.  */
+
+# define __tls_get_addr __tls_get_addr_unbounded
+# include <elf/dl-tls.c>
+# undef __tls_get_addr
+
+void *__tls_get_addr (tls_index *ti);
+rtld_hidden_proto (__tls_get_addr)
+rtld_hidden_def (__tls_get_addr)
+
+void *
+__tls_get_addr (tls_index *ti)
+{
+  void *p = __tls_get_addr_unbounded (ti);
+  return __builtin_cheri_bounds_set_exact (p, ti->ti_size);
+}
+#else
+# include <elf/dl-tls.c>
+#endif
diff --git a/sysdeps/aarch64/morello/dl-tls.h b/sysdeps/aarch64/morello/dl-tls.h
new file mode 100644
index 0000000000..f47f89ca64
--- /dev/null
+++ b/sysdeps/aarch64/morello/dl-tls.h
@@ -0,0 +1,26 @@
+/* Copyright (C) 2022 Free Software Foundation, Inc.
+
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public License as
+   published by the Free Software Foundation; either version 2.1 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+typedef struct
+{
+  unsigned long int ti_module;
+  unsigned long int ti_offset;
+  unsigned long int ti_size;
+} tls_index;
+
+extern void *__tls_get_addr (tls_index *ti);
diff --git a/sysdeps/aarch64/morello/dl-tlsdesc.S b/sysdeps/aarch64/morello/dl-tlsdesc.S
index 6fced53734..d11f5d5fa7 100644
--- a/sysdeps/aarch64/morello/dl-tlsdesc.S
+++ b/sysdeps/aarch64/morello/dl-tlsdesc.S
@@ -193,18 +193,9 @@ _dl_tlsdesc_dynamic:
 
 	SAVE_Q_REGISTERS
 
-	/* TODO: remove once __tls_get_addr is fixed.  */
-	str	c1, [csp, #32*8]
-
 	mov	c0, c1
 	bl	__tls_get_addr
 
-	/* TODO: __tls_get_addr should return bounded pointer,
-	   currently it does not so bound it here.  */
-	ldr	c1, [csp, #32*8]
-	ldr	x3, [c1, #TLSDESC_SIZE]
-	scbndse	c0, c0, x3
-
 	mrs	c2, ctpidr_el0 /* Restore c2.  */
 
 	RESTORE_Q_REGISTERS

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-23 14:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-27 13:58 [glibc/arm/morello/main] aarch64: morello: Return bounded pointer in __tls_get_addr Szabolcs Nagy
  -- strict thread matches above, loose matches on Subject: below --
2022-11-23 14:48 Szabolcs Nagy
2022-10-26 15:20 Szabolcs Nagy

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).