[07/12] aarch64: fix syscalls for BTI

Message ID 20200430174250.GC29015@arm.com
State Superseded
Headers
Series aarch64: branch protection support |

Commit Message

Szabolcs Nagy April 30, 2020, 5:42 p.m. UTC
  
  

Comments

Adhemerval Zanella May 7, 2020, 7:40 p.m. UTC | #1
On 30/04/2020 14:42, Szabolcs Nagy wrote:
> Syscall asm code needs an ELF property marking for BTI
> when glibc is built with BTI support so we add AArch64
> variants of syscall-template.S and umount2.S.
> ---
>  .../sysv/linux/aarch64/syscall-template.S     | 20 +++++++++++++++
>  sysdeps/unix/sysv/linux/aarch64/umount2.S     | 25 +++++++++++++++++++
>  2 files changed, 45 insertions(+)
>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/syscall-template.S
>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/umount2.S
> 
> diff --git a/sysdeps/unix/sysv/linux/aarch64/syscall-template.S b/sysdeps/unix/sysv/linux/aarch64/syscall-template.S
> new file mode 100644
> index 0000000000..50db585289
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/aarch64/syscall-template.S
> @@ -0,0 +1,20 @@
> +/* Assembly code template for system call stubs.
> +   Copyright (C) 2020 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/>.  */
> +
> +#include <sysdeps/unix/syscall-template.S>
> +END_FILE

Although I am not very found of adding another arch-specific file,
I don't see better straightforward solution.

> diff --git a/sysdeps/unix/sysv/linux/aarch64/umount2.S b/sysdeps/unix/sysv/linux/aarch64/umount2.S
> new file mode 100644
> index 0000000000..4fe26c35e2
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/aarch64/umount2.S
> @@ -0,0 +1,25 @@
> +/* umount system call with two parameters.
> +   Copyright (C) 2020 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/>.  */
> +
> +#include <sysdep.h>
> +PSEUDO (__umount2, umount2, 2)
> +	ret
> +PSEUDO_END(__umount2)
> +weak_alias (__umount2, umount2)
> +END_FILE

I think it is better to adapt the linux umount2.S to a C file instead of
adding another arch-specific implementation.  Only alpha and ia64 do
not support __NR_umount2 (exported as __NR_umount), but recent kernel
fixes (74cd2184833f for ia64, 12b57c5c70f39 for alpha) add the alias.
So we can use __NR_umount without the need to check its definition:

diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index 0326f92c40..62ac921e8f 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -54,7 +54,7 @@ CFLAGS-malloc.c += -DMORECORE_CLEARS=2
 endif
 
 ifeq ($(subdir),misc)
-sysdep_routines += adjtimex clone umount umount2 readahead sysctl \
+sysdep_routines += adjtimex clone umount readahead sysctl \
 		   setfsuid setfsgid epoll_pwait signalfd \
 		   eventfd eventfd_read eventfd_write prlimit \
 		   personality epoll_wait tee vmsplice splice \
diff --git a/sysdeps/unix/sysv/linux/ia64/syscalls.list b/sysdeps/unix/sysv/linux/ia64/syscalls.list
index 56f4138c43..bd39441d3c 100644
--- a/sysdeps/unix/sysv/linux/ia64/syscalls.list
+++ b/sysdeps/unix/sysv/linux/ia64/syscalls.list
@@ -1,7 +1,5 @@
 # File name	Caller	Syscall name	# args	Strong name	Weak names
 
-umount2		-	umount		2	__umount2	umount2
-
 getpriority	-	getpriority	i:ii	__getpriority	getpriority
 
 # proper socket implementations:
diff --git a/sysdeps/unix/sysv/linux/umount.c b/sysdeps/unix/sysv/linux/umount.c
index ab6a20f596..cdc8759118 100644
--- a/sysdeps/unix/sysv/linux/umount.c
+++ b/sysdeps/unix/sysv/linux/umount.c
@@ -16,12 +16,17 @@
    License along with the GNU C Library.  If not, see
    <https://www.gnu.org/licenses/>.  */
 
-/* Since the generic Linux syscall ABI doesn't have an oldumount system call,
-   do what the kernel does down here.  */
+#include <sys/mount.h>
+#include <sysdep.h>
 
-extern long int __umount2 (const char *name, int flags);
+int
+__umount2 (const char *special_file, int flags)
+{
+  return INLINE_SYSCALL_CALL (umount2, special_file, flags);
+}
+weak_alias (__umount2, umount2)
 
-long int
+int
 __umount (const char *name)
 {
   return __umount2 (name, 0);
diff --git a/sysdeps/unix/sysv/linux/umount2.S b/sysdeps/unix/sysv/linux/umount2.S
deleted file mode 100644
index 92241bbf97..0000000000
--- a/sysdeps/unix/sysv/linux/umount2.S
+++ /dev/null
@@ -1,13 +0,0 @@
-/* umount system call with two parameters.  */
-
-#include <sysdep.h>
-#if defined __NR_oldumount || defined __NR_umount2
-#ifdef __NR_oldumount
-PSEUDO (__umount2, umount, 2)
-#else
-PSEUDO (__umount2, umount2, 2)
-#endif
-	ret
-PSEUDO_END(__umount2)
-weak_alias (__umount2, umount2)
-#endif
  
Szabolcs Nagy May 11, 2020, 11:46 a.m. UTC | #2
The 05/07/2020 16:40, Adhemerval Zanella via Libc-alpha wrote:
> > +#include <sysdep.h>
> > +PSEUDO (__umount2, umount2, 2)
> > +	ret
> > +PSEUDO_END(__umount2)
> > +weak_alias (__umount2, umount2)
> > +END_FILE
> 
> I think it is better to adapt the linux umount2.S to a C file instead of
> adding another arch-specific implementation.  Only alpha and ia64 do
> not support __NR_umount2 (exported as __NR_umount), but recent kernel
> fixes (74cd2184833f for ia64, 12b57c5c70f39 for alpha) add the alias.
> So we can use __NR_umount without the need to check its definition:

yes i think this is a useful thing to do
(independently of aarch64 bti work).

doesn't the patch add new umount2 symbol on
ia64 and alpha though?

> diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
> index 0326f92c40..62ac921e8f 100644
> --- a/sysdeps/unix/sysv/linux/Makefile
> +++ b/sysdeps/unix/sysv/linux/Makefile
> @@ -54,7 +54,7 @@ CFLAGS-malloc.c += -DMORECORE_CLEARS=2
>  endif
>  
>  ifeq ($(subdir),misc)
> -sysdep_routines += adjtimex clone umount umount2 readahead sysctl \
> +sysdep_routines += adjtimex clone umount readahead sysctl \
>  		   setfsuid setfsgid epoll_pwait signalfd \
>  		   eventfd eventfd_read eventfd_write prlimit \
>  		   personality epoll_wait tee vmsplice splice \
> diff --git a/sysdeps/unix/sysv/linux/ia64/syscalls.list b/sysdeps/unix/sysv/linux/ia64/syscalls.list
> index 56f4138c43..bd39441d3c 100644
> --- a/sysdeps/unix/sysv/linux/ia64/syscalls.list
> +++ b/sysdeps/unix/sysv/linux/ia64/syscalls.list
> @@ -1,7 +1,5 @@
>  # File name	Caller	Syscall name	# args	Strong name	Weak names
>  
> -umount2		-	umount		2	__umount2	umount2
> -
>  getpriority	-	getpriority	i:ii	__getpriority	getpriority
>  
>  # proper socket implementations:
> diff --git a/sysdeps/unix/sysv/linux/umount.c b/sysdeps/unix/sysv/linux/umount.c
> index ab6a20f596..cdc8759118 100644
> --- a/sysdeps/unix/sysv/linux/umount.c
> +++ b/sysdeps/unix/sysv/linux/umount.c
> @@ -16,12 +16,17 @@
>     License along with the GNU C Library.  If not, see
>     <https://www.gnu.org/licenses/>.  */
>  
> -/* Since the generic Linux syscall ABI doesn't have an oldumount system call,
> -   do what the kernel does down here.  */
> +#include <sys/mount.h>
> +#include <sysdep.h>
>  
> -extern long int __umount2 (const char *name, int flags);
> +int
> +__umount2 (const char *special_file, int flags)
> +{
> +  return INLINE_SYSCALL_CALL (umount2, special_file, flags);
> +}
> +weak_alias (__umount2, umount2)
>  
> -long int
> +int
>  __umount (const char *name)
>  {
>    return __umount2 (name, 0);
> diff --git a/sysdeps/unix/sysv/linux/umount2.S b/sysdeps/unix/sysv/linux/umount2.S
> deleted file mode 100644
> index 92241bbf97..0000000000
> --- a/sysdeps/unix/sysv/linux/umount2.S
> +++ /dev/null
> @@ -1,13 +0,0 @@
> -/* umount system call with two parameters.  */
> -
> -#include <sysdep.h>
> -#if defined __NR_oldumount || defined __NR_umount2
> -#ifdef __NR_oldumount
> -PSEUDO (__umount2, umount, 2)
> -#else
> -PSEUDO (__umount2, umount2, 2)
> -#endif
> -	ret
> -PSEUDO_END(__umount2)
> -weak_alias (__umount2, umount2)
> -#endif
> 
> 

--
  

Patch

From 10741a1943239f0b22c8dd3f7df93aa338ec003f Mon Sep 17 00:00:00 2001
From: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date: Wed, 1 Apr 2020 15:27:12 +0100
Subject: [PATCH 07/12] aarch64: fix syscalls for BTI

Syscall asm code needs an ELF property marking for BTI
when glibc is built with BTI support so we add AArch64
variants of syscall-template.S and umount2.S.
---
 .../sysv/linux/aarch64/syscall-template.S     | 20 +++++++++++++++
 sysdeps/unix/sysv/linux/aarch64/umount2.S     | 25 +++++++++++++++++++
 2 files changed, 45 insertions(+)
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/syscall-template.S
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/umount2.S

diff --git a/sysdeps/unix/sysv/linux/aarch64/syscall-template.S b/sysdeps/unix/sysv/linux/aarch64/syscall-template.S
new file mode 100644
index 0000000000..50db585289
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/syscall-template.S
@@ -0,0 +1,20 @@ 
+/* Assembly code template for system call stubs.
+   Copyright (C) 2020 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/>.  */
+
+#include <sysdeps/unix/syscall-template.S>
+END_FILE
diff --git a/sysdeps/unix/sysv/linux/aarch64/umount2.S b/sysdeps/unix/sysv/linux/aarch64/umount2.S
new file mode 100644
index 0000000000..4fe26c35e2
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/umount2.S
@@ -0,0 +1,25 @@ 
+/* umount system call with two parameters.
+   Copyright (C) 2020 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/>.  */
+
+#include <sysdep.h>
+PSEUDO (__umount2, umount2, 2)
+	ret
+PSEUDO_END(__umount2)
+weak_alias (__umount2, umount2)
+END_FILE
-- 
2.17.1