arm64 tagged address ABI
v9 cover arm64 tagged address ABI
Hi,
This series is an update to the arm64 tagged address ABI documentation patches v8, posted here:
http://lkml.kernel.org/r/[email protected]
From v8, I dropped patches 2 and 3 as they've been queued by Will via the arm64 tree. Reposting patch 1 (unmodified) as it should be merged via the mm tree.
Changes in v9:
- Replaced the emphasized/bold font with a typewriter one for function/constant names
- Simplified the mmap/brk bullet points when describing the tagged pointer origin
- Reworded expected syscall behaviour with valid tagged pointers
- Reworded the prctl/ioctl restrictions to clarify the allowed tagged pointers w.r.t. user data access by the kernel
Catalin Marinas (1):
mm: untag user pointers in mmap/munmap/mremap/brk
Vincenzo Frascino (2):
arm64: Define Documentation/arm64/tagged-address-abi.rst
arm64: Relax Documentation/arm64/tagged-pointers.rst
Documentation/arm64/tagged-address-abi.rst | 156 +++++++++++++++++++++ Documentation/arm64/tagged-pointers.rst | 23 ++- mm/mmap.c | 5 + mm/mremap.c | 6 +- 4 files changed, 178 insertions(+), 12 deletions(-) create mode 100644 Documentation/arm64/tagged-address-abi.rst
PATCH v9 1/3 mm: untag user pointers in mmap/munmap/mremap/brk
There isn't a good reason to differentiate between the user address space layout modification syscalls and the other memory permission/attributes ones (e.g. mprotect, madvise) w.r.t. the tagged address ABI. Untag the user addresses on entry to these functions.
--- mm/mmap.c | 5 +++++ mm/mremap.c | 6 +----- 2 files changed, 6 insertions(+), 5 deletions(-)
mm/mmap.c +5 -0
@@ -201,6 +201,8 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)bool downgraded = false;LIST_HEAD (uf); + brk =untagged_addr (brk); +if (down_write_killable (&mm->mmap_sem))return -EINTR ;
@@ -1573,6 +1575,8 @@ unsigned long ksys_mmap_pgoff(unsigned long addr, unsigned long len,struct file *file =NULL ;unsigned long retval; + addr =untagged_addr (addr); +if (!(flags &MAP_ANONYMOUS )) {audit_mmap_fd (fd, flags); file =fget (fd);
@@ -2874,6 +2878,7 @@ EXPORT_SYMBOL(vm_munmap); SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len) { + addr =untagged_addr (addr);profile_munmap (addr);return __vm_munmap (addr, len, true); }
mm/mremap.c +1 -5
@@ -606,12 +606,8 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,LIST_HEAD (uf_unmap_early);LIST_HEAD (uf_unmap); -/* -* Architectures may interpret the tag passed to mmap as a background -* colour for the corresponding vma. For mremap we don't allow tagged -* new_addr to preserve similar behaviour to mmap. -*/ addr =untagged_addr (addr); + new_addr =untagged_addr (new_addr);if (flags & ~(MREMAP_FIXED |MREMAP_MAYMOVE ))return ret;
PATCH v9 2/3 arm64: Define Documentation/arm64/tagged-address-abi.rst
In reply to Catalin MarinasFrom: Vincenzo Frascino <[email protected]>
On AArch64 the TCR_EL1.TBI0 bit is set by default, allowing userspace (EL0) to perform memory accesses through 64-bit pointers with a non-zero top byte. Introduce the document describing the relaxation of the syscall ABI that allows userspace to pass certain tagged pointers to kernel syscalls.
--- Documentation/arm64/tagged-address-abi.rst | 156 +++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 Documentation/arm64/tagged-address-abi.rst
Documentation/arm64/tagged-address-abi.rst new file +156 -0
@@ -0,0 +1,156 @@ +========================== +AArch64 TAGGED ADDRESS ABI +========================== + +Authors: Vincenzo Frascino <[email protected]> + Catalin Marinas <[email protected]> + +Date: 21 August 2019 + +This document describes the usage and semantics of the Tagged Address +ABI on AArch64 Linux. + +1. Introduction +--------------- + +On AArch64 the ``TCR_EL1.TBI0`` bit is set by default, allowing +userspace (EL0) to perform memory accesses through 64-bit pointers with +a non-zero top byte. This document describes the relaxation of the +syscall ABI that allows userspace to pass certain tagged pointers to +kernel syscalls. + +2. AArch64 Tagged Address ABI +----------------------------- + +From the kernel syscall interface perspective and for the purposes of +this document, a "valid tagged pointer" is a pointer with a potentially +non-zero top-byte that references an address in the user process address +space obtained in one of the following ways: + +- ``mmap()`` syscall where either: + + - flags have the ``MAP_ANONYMOUS`` bit set or + - the file descriptor refers to a regular file (including those + returned by ``memfd_create()``) or ``/dev/zero`` + +- ``brk()`` syscall (i.e. the heap area between the initial location of + the program break at process creation and its current location). + +- any memory mapped by the kernel in the address space of the process + during creation and with the same restrictions as for ``mmap()`` above + (e.g. data, bss, stack). + +The AArch64 Tagged Address ABI has two stages of relaxation depending +how the user addresses are used by the kernel: + +1. User addresses not accessed by the kernel but used for address space + management (e.g. ``mmap()``, ``mprotect()``, ``madvise()``). The use + of valid tagged pointers in this context is always allowed. + +2. User addresses accessed by the kernel (e.g. ``write()``). This ABI + relaxation is disabled by default and the application thread needs to + explicitly enable it via ``prctl()`` as follows: + + - ``PR_SET_TAGGED_ADDR_CTRL``: enable or disable the AArch64 Tagged + Address ABI for the calling thread. + + The ``(unsigned int) arg2`` argument is a bit mask describing the + control mode used: + + - ``PR_TAGGED_ADDR_ENABLE``: enable AArch64 Tagged Address ABI. + Default status is disabled. + + Arguments ``arg3``, ``arg4``, and ``arg5`` must be 0. + + - ``PR_GET_TAGGED_ADDR_CTRL``: get the status of the AArch64 Tagged + Address ABI for the calling thread. + + Arguments ``arg2``, ``arg3``, ``arg4``, and ``arg5`` must be 0. + + The ABI properties described above are thread-scoped, inherited on + clone() and fork() and cleared on exec(). + + Calling ``prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE, 0, 0, 0)`` + returns ``-EINVAL`` if the AArch64 Tagged Address ABI is globally + disabled by ``sysctl abi.tagged_addr_disabled=1``. The default + ``sysctl abi.tagged_addr_disabled`` configuration is 0. + +When the AArch64 Tagged Address ABI is enabled for a thread, the +following behaviours are guaranteed: + +- All syscalls except the cases mentioned in section 3 can accept any + valid tagged pointer. + +- The syscall behaviour is undefined for invalid tagged pointers: it may + result in an error code being returned, a (fatal) signal being raised, + or other modes of failure. + +- The syscall behaviour for a valid tagged pointer is the same as for + the corresponding untagged pointer. + + +A definition of the meaning of tagged pointers on AArch64 can be found +in Documentation/arm64/tagged-pointers.rst. + +3. AArch64 Tagged Address ABI Exceptions +----------------------------------------- + +The following system call parameters must be untagged regardless of the +ABI relaxation: + +- ``prctl()`` other than pointers to user data either passed directly or + indirectly as arguments to be accessed by the kernel. + +- ``ioctl()`` other than pointers to user data either passed directly or + indirectly as arguments to be accessed by the kernel. + +- ``shmat()`` and ``shmdt()``. + +Any attempt to use non-zero tagged pointers may result in an error code +being returned, a (fatal) signal being raised, or other modes of +failure. + +4. Example of correct usage +--------------------------- +.. code-block:: c + + #include <stdlib.h> + #include <string.h> + #include <unistd.h> + #include <sys/mman.h> + #include <sys/prctl.h> + + #define PR_SET_TAGGED_ADDR_CTRL 55 + #define PR_TAGGED_ADDR_ENABLE (1UL << 0) + + #define TAG_SHIFT 56 + + int main(void) + { + int tbi_enabled = 0; + unsigned long tag = 0; + char *ptr; + + /* check/enable the tagged address ABI */ + if (!prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE, 0, 0, 0)) + tbi_enabled = 1; + + /* memory allocation */ + ptr = mmap(NULL, sysconf(_SC_PAGE_SIZE), PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (ptr == MAP_FAILED) + return 1; + + /* set a non-zero tag if the ABI is available */ + if (tbi_enabled) + tag = rand() & 0xff; + ptr = (char *)((unsigned long)ptr | (tag << TAG_SHIFT)); + + /* memory access to a tagged address */ + strcpy(ptr, "tagged pointer\n"); + + /* syscall with a tagged pointer */ + write(1, ptr, strlen(ptr)); + + return 0; + }
Re: [PATCH v9 2/3] arm64: Define Documentation/arm64/tagged-address-abi.rst
Quoted 9 lines · Catalin Marinas
From: Vincenzo Frascino <[email protected]>
On AArch64 the TCR_EL1.TBI0 bit is set by default, allowing userspace (EL0) to perform memory accesses through 64-bit pointers with a non-zero top byte. Introduce the document describing the relaxation of the syscall ABI that allows userspace to pass certain tagged pointers to kernel syscalls.
Quoted 7 lines
Cc Will Deacon <[email protected]>Cc Andrey Konovalov <[email protected]>Cc Szabolcs Nagy <[email protected]>Cc Kevin Brodsky <[email protected]>Signed-off-by Vincenzo Frascino <[email protected]>Co-developed-by Catalin Marinas <[email protected]>Signed-off-by Catalin Marinas <[email protected]>
Quoted 167 lines
--- Documentation/arm64/tagged-address-abi.rst | 156 +++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 Documentation/arm64/tagged-address-abi.rstDocumentation/arm64/tagged-address-abi.rst new file +156
-0@@ -0,0 +1,156 @@ +========================== +AArch64 TAGGED ADDRESS ABI +========================== + +Authors: Vincenzo Frascino <[email protected]> + Catalin Marinas <[email protected]> + +Date: 21 August 2019 + +This document describes the usage and semantics of the Tagged Address +ABI on AArch64 Linux. + +1. Introduction +--------------- + +On AArch64 the ``TCR_EL1.TBI0`` bit is set by default, allowing +userspace (EL0) to perform memory accesses through 64-bit pointers with +a non-zero top byte. This document describes the relaxation of the +syscall ABI that allows userspace to pass certain tagged pointers to +kernel syscalls. + +2. AArch64 Tagged Address ABI +----------------------------- + +From the kernel syscall interface perspective and for the purposes of +this document, a "valid tagged pointer" is a pointer with a potentially +non-zero top-byte that references an address in the user process address +space obtained in one of the following ways: + +- ``mmap()`` syscall where either: + + - flags have the ``MAP_ANONYMOUS`` bit set or + - the file descriptor refers to a regular file (including those + returned by ``memfd_create()``) or ``/dev/zero`` + +- ``brk()`` syscall (i.e. the heap area between the initial location of + the program break at process creation and its current location). + +- any memory mapped by the kernel in the address space of the process + during creation and with the same restrictions as for ``mmap()`` above + (e.g. data, bss, stack). + +The AArch64 Tagged Address ABI has two stages of relaxation depending +how the user addresses are used by the kernel: + +1. User addresses not accessed by the kernel but used for address space + management (e.g. ``mmap()``, ``mprotect()``, ``madvise()``). The use + of valid tagged pointers in this context is always allowed. + +2. User addresses accessed by the kernel (e.g. ``write()``). This ABI + relaxation is disabled by default and the application thread needs to + explicitly enable it via ``prctl()`` as follows: + + - ``PR_SET_TAGGED_ADDR_CTRL``: enable or disable the AArch64 Tagged + Address ABI for the calling thread. + + The ``(unsigned int) arg2`` argument is a bit mask describing the + control mode used: + + - ``PR_TAGGED_ADDR_ENABLE``: enable AArch64 Tagged Address ABI. + Default status is disabled. + + Arguments ``arg3``, ``arg4``, and ``arg5`` must be 0. + + - ``PR_GET_TAGGED_ADDR_CTRL``: get the status of the AArch64 Tagged + Address ABI for the calling thread. + + Arguments ``arg2``, ``arg3``, ``arg4``, and ``arg5`` must be 0. + + The ABI properties described above are thread-scoped, inherited on + clone() and fork() and cleared on exec(). + + Calling ``prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE, 0, 0, 0)`` + returns ``-EINVAL`` if the AArch64 Tagged Address ABI is globally + disabled by ``sysctl abi.tagged_addr_disabled=1``. The default + ``sysctl abi.tagged_addr_disabled`` configuration is 0. + +When the AArch64 Tagged Address ABI is enabled for a thread, the +following behaviours are guaranteed: + +- All syscalls except the cases mentioned in section 3 can accept any + valid tagged pointer. + +- The syscall behaviour is undefined for invalid tagged pointers: it may + result in an error code being returned, a (fatal) signal being raised, + or other modes of failure. + +- The syscall behaviour for a valid tagged pointer is the same as for + the corresponding untagged pointer. + + +A definition of the meaning of tagged pointers on AArch64 can be found +in Documentation/arm64/tagged-pointers.rst. + +3. AArch64 Tagged Address ABI Exceptions +----------------------------------------- + +The following system call parameters must be untagged regardless of the +ABI relaxation: + +- ``prctl()`` other than pointers to user data either passed directly or + indirectly as arguments to be accessed by the kernel. + +- ``ioctl()`` other than pointers to user data either passed directly or + indirectly as arguments to be accessed by the kernel. + +- ``shmat()`` and ``shmdt()``. + +Any attempt to use non-zero tagged pointers may result in an error code +being returned, a (fatal) signal being raised, or other modes of +failure. + +4. Example of correct usage +--------------------------- +.. code-block:: c + + #include <stdlib.h> + #include <string.h> + #include <unistd.h> + #include <sys/mman.h> + #include <sys/prctl.h> + + #define PR_SET_TAGGED_ADDR_CTRL 55 + #define PR_TAGGED_ADDR_ENABLE (1UL << 0) + + #define TAG_SHIFT 56 + + int main(void) + { + int tbi_enabled = 0; + unsigned long tag = 0; + char *ptr; + + /* check/enable the tagged address ABI */ + if (!prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE, 0, 0, 0)) + tbi_enabled = 1; + + /* memory allocation */ + ptr = mmap(NULL, sysconf(_SC_PAGE_SIZE), PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (ptr == MAP_FAILED) + return 1; + + /* set a non-zero tag if the ABI is available */ + if (tbi_enabled) + tag = rand() & 0xff; + ptr = (char *)((unsigned long)ptr | (tag << TAG_SHIFT)); + + /* memory access to a tagged address */ + strcpy(ptr, "tagged pointer\n"); + + /* syscall with a tagged pointer */ + write(1, ptr, strlen(ptr)); + + return 0; + }
Kevin Brodsky
Acked-byRe: [PATCH v9 2/3] arm64: Define Documentation/arm64/tagged-address-abi.rst
Quoted 9 lines · Andrey Konovalov
Quoted 8 lines · Catalin Marinas
From: Vincenzo Frascino <[email protected]>
On AArch64 the TCR_EL1.TBI0 bit is set by default, allowing userspace (EL0) to perform memory accesses through 64-bit pointers with a non-zero top byte. Introduce the document describing the relaxation of the syscall ABI that allows userspace to pass certain tagged pointers to kernel syscalls.
Quoted 8 lines
Quoted 7 lines
Cc Will Deacon <[email protected]>Cc Andrey Konovalov <[email protected]>Cc Szabolcs Nagy <[email protected]>Cc Kevin Brodsky <[email protected]>Signed-off-by Vincenzo Frascino <[email protected]>Co-developed-by Catalin Marinas <[email protected]>Signed-off-by Catalin Marinas <[email protected]>Acked-by Andrey Konovalov <[email protected]>
Quoted 167 lines
Quoted 167 lines
--- Documentation/arm64/tagged-address-abi.rst | 156 +++++++++++++++++++++ 1 file changed, 156 insertions(+)create mode 100644
Documentation/arm64/tagged-address-abi.rstDocumentation/arm64/tagged-address-abi.rst new file +156
-0@@ -0,0 +1,156 @@ +========================== +AArch64 TAGGED ADDRESS ABI +========================== + +Authors: Vincenzo Frascino <[email protected]> + Catalin Marinas <[email protected]> + +Date: 21 August 2019 + +This document describes the usage and semantics of the Tagged Address +ABI on AArch64 Linux. + +1. Introduction +--------------- + +On AArch64 the ``TCR_EL1.TBI0`` bit is set by default, allowing +userspace (EL0) to perform memory accesses through 64-bit pointers with +a non-zero top byte. This document describes the relaxation of the +syscall ABI that allows userspace to pass certain tagged pointers to +kernel syscalls. + +2. AArch64 Tagged Address ABI +----------------------------- + +From the kernel syscall interface perspective and for the purposes of +this document, a "valid tagged pointer" is a pointer with a potentially +non-zero top-byte that references an address in the user process address +space obtained in one of the following ways: + +- ``mmap()`` syscall where either: + + - flags have the ``MAP_ANONYMOUS`` bit set or + - the file descriptor refers to a regular file (including those + returned by ``memfd_create()``) or ``/dev/zero`` + +- ``brk()`` syscall (i.e. the heap area between the initial location of + the program break at process creation and its current location). + +- any memory mapped by the kernel in the address space of the process + during creation and with the same restrictions as for ``mmap()`` above + (e.g. data, bss, stack). + +The AArch64 Tagged Address ABI has two stages of relaxation depending +how the user addresses are used by the kernel: + +1. User addresses not accessed by the kernel but used for address space + management (e.g. ``mmap()``, ``mprotect()``, ``madvise()``). The use + of valid tagged pointers in this context is always allowed. + +2. User addresses accessed by the kernel (e.g. ``write()``). This ABI + relaxation is disabled by default and the application thread needs to + explicitly enable it via ``prctl()`` as follows: + + - ``PR_SET_TAGGED_ADDR_CTRL``: enable or disable the AArch64 Tagged + Address ABI for the calling thread. + + The ``(unsigned int) arg2`` argument is a bit mask describing the + control mode used: + + - ``PR_TAGGED_ADDR_ENABLE``: enable AArch64 Tagged Address ABI. + Default status is disabled. + + Arguments ``arg3``, ``arg4``, and ``arg5`` must be 0. + + - ``PR_GET_TAGGED_ADDR_CTRL``: get the status of the AArch64 Tagged + Address ABI for the calling thread. + + Arguments ``arg2``, ``arg3``, ``arg4``, and ``arg5`` must be 0. + + The ABI properties described above are thread-scoped, inherited on + clone() and fork() and cleared on exec(). + + Calling ``prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE, 0, 0, 0)`` + returns ``-EINVAL`` if the AArch64 Tagged Address ABI is globally + disabled by ``sysctl abi.tagged_addr_disabled=1``. The default + ``sysctl abi.tagged_addr_disabled`` configuration is 0. + +When the AArch64 Tagged Address ABI is enabled for a thread, the +following behaviours are guaranteed: + +- All syscalls except the cases mentioned in section 3 can accept any + valid tagged pointer. + +- The syscall behaviour is undefined for invalid tagged pointers: it may + result in an error code being returned, a (fatal) signal being raised, + or other modes of failure. + +- The syscall behaviour for a valid tagged pointer is the same as for + the corresponding untagged pointer. + + +A definition of the meaning of tagged pointers on AArch64 can be found +in Documentation/arm64/tagged-pointers.rst. + +3. AArch64 Tagged Address ABI Exceptions +----------------------------------------- + +The following system call parameters must be untagged regardless of the +ABI relaxation: + +- ``prctl()`` other than pointers to user data either passed directly or + indirectly as arguments to be accessed by the kernel. + +- ``ioctl()`` other than pointers to user data either passed directly or + indirectly as arguments to be accessed by the kernel. + +- ``shmat()`` and ``shmdt()``. + +Any attempt to use non-zero tagged pointers may result in an error code +being returned, a (fatal) signal being raised, or other modes of +failure. + +4. Example of correct usage +--------------------------- +.. code-block:: c + + #include <stdlib.h> + #include <string.h> + #include <unistd.h> + #include <sys/mman.h> + #include <sys/prctl.h> + + #define PR_SET_TAGGED_ADDR_CTRL 55 + #define PR_TAGGED_ADDR_ENABLE (1UL << 0) + + #define TAG_SHIFT 56 + + int main(void) + { + int tbi_enabled = 0; + unsigned long tag = 0; + char *ptr; + + /* check/enable the tagged address ABI */ + if (!prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE, 0, 0, 0)) + tbi_enabled = 1; + + /* memory allocation */ + ptr = mmap(NULL, sysconf(_SC_PAGE_SIZE), PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (ptr == MAP_FAILED) + return 1; + + /* set a non-zero tag if the ABI is available */ + if (tbi_enabled) + tag = rand() & 0xff; + ptr = (char *)((unsigned long)ptr | (tag << TAG_SHIFT)); + + /* memory access to a tagged address */ + strcpy(ptr, "tagged pointer\n"); + + /* syscall with a tagged pointer */ + write(1, ptr, strlen(ptr)); + + return 0; + }
Re: [PATCH v9 2/3] arm64: Define Documentation/arm64/tagged-address-abi.rst
In reply to Catalin MarinasQuoted 15 lines · Catalin Marinas
From: Vincenzo Frascino <[email protected]>
On AArch64 the TCR_EL1.TBI0 bit is set by default, allowing userspace (EL0) to perform memory accesses through 64-bit pointers with a non-zero top byte. Introduce the document describing the relaxation of the syscall ABI that allows userspace to pass certain tagged pointers to kernel syscalls.
Cc Will Deacon <[email protected]>Cc Andrey Konovalov <[email protected]>Cc Szabolcs Nagy <[email protected]>Cc Kevin Brodsky <[email protected]>Signed-off-by Vincenzo Frascino <[email protected]>Co-developed-by Catalin Marinas <[email protected]>Signed-off-by Catalin Marinas <[email protected]>
Quoted 4 lines
--- Documentation/arm64/tagged-address-abi.rst | 156 +++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 Documentation/arm64/tagged-address-abi.rst
Thanks, I'll pick this on up.
Will
PATCH 1/1 arm64: Add tagged-address-abi.rst to index.rst
In reply to Catalin MarinasDocumentation/arm64/tagged-address-abi.rst introduces the relaxation of the syscall ABI that allows userspace to pass certain tagged pointers to kernel syscalls.
Add the document to index.rst for a correct generation of the table of content.
--- Documentation/arm64/index.rst | 1 + 1 file changed, 1 insertion(+)
Documentation/arm64/index.rst +1 -0
@@ -16,6 +16,7 @@ ARM64 Architecture pointer-authentication silicon-errata sve + tagged-address-abi tagged-pointers .. only:: subproject and html
Signature · 7 lines
2.22.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v9 3/3 arm64: Relax Documentation/arm64/tagged-pointers.rst
In reply to Catalin MarinasFrom: Vincenzo Frascino <[email protected]>
On AArch64 the TCR_EL1.TBI0 bit is set by default, allowing userspace (EL0) to perform memory accesses through 64-bit pointers with a non-zero top byte. However, such pointers were not allowed at the user-kernel syscall ABI boundary.
With the Tagged Address ABI patchset, it is now possible to pass tagged pointers to the syscalls. Relax the requirements described in tagged-pointers.rst to be compliant with the behaviours guaranteed by the AArch64 Tagged Address ABI.
--- Documentation/arm64/tagged-pointers.rst | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-)
Documentation/arm64/tagged-pointers.rst +16 -7
@@ -20,7 +20,9 @@ Passing tagged addresses to the kernel -------------------------------------- All interpretation of userspace memory addresses by the kernel assumes -an address tag of 0x00. +an address tag of 0x00, unless the application enables the AArch64 +Tagged Address ABI explicitly +(Documentation/arm64/tagged-address-abi.rst). This includes, but is not limited to, addresses found in:
@@ -33,13 +35,15 @@ This includes, but is not limited to, addresses found in: - the frame pointer (x29) and frame records, e.g. when interpreting them to generate a backtrace or call graph. -Using non-zero address tags in any of these locations may result in an -error code being returned, a (fatal) signal being raised, or other modes -of failure. +Using non-zero address tags in any of these locations when the +userspace application did not enable the AArch64 Tagged Address ABI may +result in an error code being returned, a (fatal) signal being raised, +or other modes of failure. -For these reasons, passing non-zero address tags to the kernel via -system calls is forbidden, and using a non-zero address tag for sp is -strongly discouraged. +For these reasons, when the AArch64 Tagged Address ABI is disabled, +passing non-zero address tags to the kernel via system calls is +forbidden, and using a non-zero address tag for sp is strongly +discouraged. Programs maintaining a frame pointer and frame records that use non-zero address tags may suffer impaired or inaccurate debug and profiling
@@ -59,6 +63,11 @@ be preserved. The architecture prevents the use of a tagged PC, so the upper byte will be set to a sign-extension of bit 55 on exception return. +This behaviour is maintained when the AArch64 Tagged Address ABI is +enabled. In addition, with the exceptions above, the kernel will +preserve any non-zero tags passed by the user via syscalls and stored in +kernel data structures (e.g. ``set_robust_list()``, ``sigaltstack()``). + Other considerations --------------------
Re: [PATCH v9 3/3] arm64: Relax Documentation/arm64/tagged-pointers.rst
Quoted 61 lines · Catalin Marinas
From: Vincenzo Frascino <[email protected]>
On AArch64 the TCR_EL1.TBI0 bit is set by default, allowing userspace (EL0) to perform memory accesses through 64-bit pointers with a non-zero top byte. However, such pointers were not allowed at the user-kernel syscall ABI boundary.
With the Tagged Address ABI patchset, it is now possible to pass tagged pointers to the syscalls. Relax the requirements described in
tagged-pointers.rstto be compliant with the behaviours guaranteed by the AArch64 Tagged Address ABI.Cc Will Deacon <[email protected]>Cc Szabolcs Nagy <[email protected]>Cc Kevin Brodsky <[email protected]>Acked-by Andrey Konovalov <[email protected]>Signed-off-by Vincenzo Frascino <[email protected]>Co-developed-by Catalin Marinas <[email protected]>Signed-off-by Catalin Marinas <[email protected]>--- Documentation/arm64/tagged-pointers.rst | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-)Documentation/arm64/tagged-pointers.rst +11
-7@@ -20,7 +20,9 @@ Passing tagged addresses to the kernel -------------------------------------- All interpretation of userspace memory addresses by the kernel assumes -an address tag of 0x00. +an address tag of 0x00, unless the application enables the AArch64 +Tagged Address ABI explicitly +(Documentation/arm64/tagged-address-abi.rst). This includes, but is not limited to, addresses found in:@@ -33,13 +35,15 @@ This includes, but is not limited to, addresses found in: - the frame pointer (x29) and frame records, e.g. when interpreting them to generate a backtrace or call graph. -Using non-zero address tags in any of these locations may result in an -error code being returned, a (fatal) signal being raised, or other modes -of failure. +Using non-zero address tags in any of these locations when the +userspace application did not enable the AArch64 Tagged Address ABI may +result in an error code being returned, a (fatal) signal being raised, +or other modes of failure. -For these reasons, passing non-zero address tags to the kernel via -system calls is forbidden, and using a non-zero address tag for sp is -strongly discouraged. +For these reasons, when the AArch64 Tagged Address ABI is disabled, +passing non-zero address tags to the kernel via system calls is +forbidden, and using a non-zero address tag for sp is strongly +discouraged. Programs maintaining a frame pointer and frame records that use non-zero address tags may suffer impaired or inaccurate debug and profiling
Documentation/arm64/tagged-pointers.rst be preserved. · line 69
Quoted 7 lines
Documentation/arm64/tagged-pointers.rst +4
-0@@ -59,6 +63,11 @@ be preserved. The architecture prevents the use of a tagged PC, so the upper byte will be set to a sign-extension of bit 55 on exception return. +This behaviour is maintained when the AArch64 Tagged Address ABI is +enabled. In addition, with the exceptions above, the kernel will +preserve any non-zero tags passed by the user via syscalls and stored in +kernel data structures (e.g. ``set_robust_list()``, ``sigaltstack()``).
Hmm. I can see the need to provide this guarantee for things like set_robust_list(), but the problem is that the statement above is too broad and isn't strictly true: for example, mmap() doesn't propagate the tag of its address parameter into the VMA.
So I think we need to nail this down a bit more, but I'm having a really hard time coming up with some wording :(
Will
Re: [PATCH v9 3/3] arm64: Relax Documentation/arm64/tagged-pointers.rst
Quoted 65 lines · Will Deacon
Quoted 64 lines · Catalin Marinas
From: Vincenzo Frascino <[email protected]>
On AArch64 the TCR_EL1.TBI0 bit is set by default, allowing userspace (EL0) to perform memory accesses through 64-bit pointers with a non-zero top byte. However, such pointers were not allowed at the user-kernel syscall ABI boundary.
With the Tagged Address ABI patchset, it is now possible to pass tagged pointers to the syscalls. Relax the requirements described in
tagged-pointers.rstto be compliant with the behaviours guaranteed by the AArch64 Tagged Address ABI.Cc Will Deacon <[email protected]>Cc Szabolcs Nagy <[email protected]>Cc Kevin Brodsky <[email protected]>Acked-by Andrey Konovalov <[email protected]>Signed-off-by Vincenzo Frascino <[email protected]>Co-developed-by Catalin Marinas <[email protected]>Signed-off-by Catalin Marinas <[email protected]>--- Documentation/arm64/tagged-pointers.rst | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-)Documentation/arm64/tagged-pointers.rst +11
-7@@ -20,7 +20,9 @@ Passing tagged addresses to the kernel -------------------------------------- All interpretation of userspace memory addresses by the kernel assumes -an address tag of 0x00. +an address tag of 0x00, unless the application enables the AArch64 +Tagged Address ABI explicitly +(Documentation/arm64/tagged-address-abi.rst). This includes, but is not limited to, addresses found in:@@ -33,13 +35,15 @@ This includes, but is not limited to, addresses found in: - the frame pointer (x29) and frame records, e.g. when interpreting them to generate a backtrace or call graph. -Using non-zero address tags in any of these locations may result in an -error code being returned, a (fatal) signal being raised, or other modes -of failure. +Using non-zero address tags in any of these locations when the +userspace application did not enable the AArch64 Tagged Address ABI may +result in an error code being returned, a (fatal) signal being raised, +or other modes of failure. -For these reasons, passing non-zero address tags to the kernel via -system calls is forbidden, and using a non-zero address tag for sp is -strongly discouraged. +For these reasons, when the AArch64 Tagged Address ABI is disabled, +passing non-zero address tags to the kernel via system calls is +forbidden, and using a non-zero address tag for sp is strongly +discouraged. Programs maintaining a frame pointer and frame records that use non-zero address tags may suffer impaired or inaccurate debug and profiling@@ -59,6 +63,11 @@ be preserved. The architecture prevents the use of a tagged PC, so the upper byte will be set to a sign-extension of bit 55 on exception return.
Quoted 4 lines
Documentation/arm64/tagged-pointers.rst be preserved. · line 69
Quoted 4 lines
Documentation/arm64/tagged-pointers.rst +4
-0+This behaviour is maintained when the AArch64 Tagged Address ABI is +enabled. In addition, with the exceptions above, the kernel will +preserve any non-zero tags passed by the user via syscalls and stored in +kernel data structures (e.g. ``set_robust_list()``, ``sigaltstack()``).
sigaltstack() is interesting, since we don't support tagged stacks.
Do we keep the ss_sp tag in the kernel, but squash it when delivering a signal to the alternate stack?
(I can't remember whether this would be compatible with the architectural tag checking semantics...)
Quoted 7 lines
Hmm. I can see the need to provide this guarantee for things like
set_robust_list(), but the problem is that the statement above is too broad and isn't strictly true: for example,mmap()doesn't propagate the tag of its address parameter into the VMA.So I think we need to nail this down a bit more, but I'm having a really hard time coming up with some wording :(
Time for some creative vagueness?
We can write a statement of our overall intent, along with examples of a few cases where the tag should and should not be expected to emerge intact.
There is no foolproof rule, unless we can rewrite history...
Cheers
---Dave
Re: [PATCH v9 3/3] arm64: Relax Documentation/arm64/tagged-pointers.rst
Quoted 6 lines · Dave P Martin
Quoted 5 lines · Will Deacon
Quoted 4 lines · Catalin Marinas
Documentation/arm64/tagged-pointers.rst +0
-0@@ -59,6 +63,11 @@ be preserved. The architecture prevents the use of a tagged PC, so the upper byte will be set to a sign-extension of bit 55 on exception return.
Quoted 6 lines
Quoted 4 lines
Documentation/arm64/tagged-pointers.rst be preserved. · line 69
Quoted 4 lines
Documentation/arm64/tagged-pointers.rst +4
-0+This behaviour is maintained when the AArch64 Tagged Address ABI is +enabled. In addition, with the exceptions above, the kernel will +preserve any non-zero tags passed by the user via syscalls and stored in +kernel data structures (e.g. ``set_robust_list()``, ``sigaltstack()``).
sigaltstack()is interesting, since we don't support tagged stacks.
We should support tagged SP with the new ABI as they'll be required for MTE. sigaltstack() and clone() are the two syscalls that come to mind here.
Quoted 2 lines
Do we keep the
ss_sptag in the kernel, but squash it when delivering a signal to the alternate stack?
We don't seem to be doing any untagging, so we just just use whatever the caller asked for. We may need a small test to confirm.
That said, on_sig_stack() probably needs some untagging as it does user pointer arithmetics with potentially different tags.
Quoted 8 lines
Quoted 7 lines
Hmm. I can see the need to provide this guarantee for things like
set_robust_list(), but the problem is that the statement above is too broad and isn't strictly true: for example,mmap()doesn't propagate the tag of its address parameter into the VMA.So I think we need to nail this down a bit more, but I'm having a really hard time coming up with some wording :(
Quoted 7 lines
Time for some creative vagueness?
We can write a statement of our overall intent, along with examples of a few cases where the tag should and should not be expected to emerge intact.
There is no foolproof rule, unless we can rewrite history...
I would expect the norm to be the preservation of tags with a few exceptions. The only ones I think where we won't preserve the tags are mmap, mremap, brk (apart from the signal stuff already mentioned in the current tagged-pointers.rst doc).
So I can remove this paragraph altogether and add a note in part 3 of the tagged-address-abi.rst document that mmap/mremap/brk do not preserve the tag information.
Signature · 1 line
Catalin
Re: [PATCH v9 3/3] arm64: Relax Documentation/arm64/tagged-pointers.rst
Quoted 18 lines · Catalin Marinas
Quoted 6 lines · Dave P Martin
Quoted 5 lines · Will Deacon
Quoted 4 lines · Catalin Marinas
Documentation/arm64/tagged-pointers.rst +0
-0@@ -59,6 +63,11 @@ be preserved. The architecture prevents the use of a tagged PC, so the upper byte will be set to a sign-extension of bit 55 on exception return.Quoted 6 lines
Quoted 4 lines
Documentation/arm64/tagged-pointers.rst be preserved. · line 69
Quoted 4 lines
Documentation/arm64/tagged-pointers.rst +4
-0+This behaviour is maintained when the AArch64 Tagged Address ABI is +enabled. In addition, with the exceptions above, the kernel will +preserve any non-zero tags passed by the user via syscalls and stored in +kernel data structures (e.g. ``set_robust_list()``, ``sigaltstack()``).
sigaltstack()is interesting, since we don't support tagged stacks.We should support tagged SP with the new ABI as they'll be required for MTE.
sigaltstack()andclone()are the two syscalls that come to mind here.
Quoted 5 lines
Quoted 2 lines
Do we keep the
ss_sptag in the kernel, but squash it when delivering a signal to the alternate stack?We don't seem to be doing any untagging, so we just just use whatever the caller asked for. We may need a small test to confirm.
If we want to support tagged SP, then I guess we shouldn't be squashing the tag anywhere. A test for that would be sensible to have.
Quoted 2 lines
That said,
on_sig_stack()probably needs some untagging as it does user pointer arithmetics with potentially different tags.
Good point.
Quoted 16 lines
Quoted 8 lines
Quoted 7 lines
Hmm. I can see the need to provide this guarantee for things like
set_robust_list(), but the problem is that the statement above is too broad and isn't strictly true: for example,mmap()doesn't propagate the tag of its address parameter into the VMA.So I think we need to nail this down a bit more, but I'm having a really hard time coming up with some wording :(
Quoted 7 lines
Time for some creative vagueness?
We can write a statement of our overall intent, along with examples of a few cases where the tag should and should not be expected to emerge intact.
There is no foolproof rule, unless we can rewrite history...
Quoted 8 lines
I would expect the norm to be the preservation of tags with a few exceptions. The only ones I think where we won't preserve the tags are mmap, mremap, brk (apart from the signal stuff already mentioned in the current
tagged-pointers.rstdoc).So I can remove this paragraph altogether and add a note in part 3 of the
tagged-address-abi.rstdocument that mmap/mremap/brk do not preserve the tag information.
Deleting text is always a good idea ;)
There are other cases like (non-)propagation of the tag to si_addr when a fault is reported via a signal, but I think we already have appropriate wording to cover that.
Cheers
---Dave
Re: [PATCH v9 3/3] arm64: Relax Documentation/arm64/tagged-pointers.rst
Quoted 19 lines · Dave P Martin
Quoted 18 lines · Catalin Marinas
Quoted 6 lines · Dave P Martin
Quoted 5 lines · Will Deacon
Quoted 4 lines · Catalin Marinas
Documentation/arm64/tagged-pointers.rst +0
-0@@ -59,6 +63,11 @@ be preserved. The architecture prevents the use of a tagged PC, so the upper byte will be set to a sign-extension of bit 55 on exception return.Quoted 6 lines
Quoted 4 lines
Documentation/arm64/tagged-pointers.rst be preserved. · line 69
Quoted 4 lines
Documentation/arm64/tagged-pointers.rst +4
-0+This behaviour is maintained when the AArch64 Tagged Address ABI is +enabled. In addition, with the exceptions above, the kernel will +preserve any non-zero tags passed by the user via syscalls and stored in +kernel data structures (e.g. ``set_robust_list()``, ``sigaltstack()``).
sigaltstack()is interesting, since we don't support tagged stacks.We should support tagged SP with the new ABI as they'll be required for MTE.
sigaltstack()andclone()are the two syscalls that come to mind here.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Do we keep the
ss_sptag in the kernel, but squash it when delivering a signal to the alternate stack?We don't seem to be doing any untagging, so we just just use whatever the caller asked for. We may need a small test to confirm.
If we want to support tagged SP, then I guess we shouldn't be squashing the tag anywhere. A test for that would be sensible to have.
I hacked the sas.c kselftest to use a tagged stack and works fine, the SP register has a tagged address on the signal handler.
Quoted 21 lines
Quoted 21 lines
Quoted 8 lines
Quoted 7 lines
Hmm. I can see the need to provide this guarantee for things like
set_robust_list(), but the problem is that the statement above is too broad and isn't strictly true: for example,mmap()doesn't propagate the tag of its address parameter into the VMA.So I think we need to nail this down a bit more, but I'm having a really hard time coming up with some wording :(
Quoted 7 lines
Time for some creative vagueness?
We can write a statement of our overall intent, along with examples of a few cases where the tag should and should not be expected to emerge intact.
There is no foolproof rule, unless we can rewrite history...
I would expect the norm to be the preservation of tags with a few exceptions. The only ones I think where we won't preserve the tags are mmap, mremap, brk (apart from the signal stuff already mentioned in the current
tagged-pointers.rstdoc).
Quoted 5 lines
Quoted 3 lines
So I can remove this paragraph altogether and add a note in part 3 of the
tagged-address-abi.rstdocument that mmap/mremap/brk do not preserve the tag information.Deleting text is always a good idea ;)
I'm going this route ;).
Signature · 1 line
Catalin
Re: [PATCH v9 3/3] arm64: Relax Documentation/arm64/tagged-pointers.rst
Quoted 3 lines · Catalin Marinas
Quoted 2 lines · Dave P Martin
Quoted 1 line · Catalin Marinas
On Wed, Aug 21, 2019 at 07:46:51PM +0100, Dave P Martin wrote:
[...]
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 1 line
sigaltstack()is interesting, since we don't support tagged stacks.We should support tagged SP with the new ABI as they'll be required for MTE.
sigaltstack()andclone()are the two syscalls that come to mind here.Quoted 2 lines
Do we keep the
ss_sptag in the kernel, but squash it when delivering a signal to the alternate stack?
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
We don't seem to be doing any untagging, so we just just use whatever the caller asked for. We may need a small test to confirm.
If we want to support tagged SP, then I guess we shouldn't be squashing the tag anywhere. A test for that would be sensible to have.
I hacked the
sas.ckselftest to use a tagged stack and works fine, the SP register has a tagged address on the signal handler.
Cool...
[...]
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
There is no foolproof rule, unless we can rewrite history...
I would expect the norm to be the preservation of tags with a few exceptions. The only ones I think where we won't preserve the tags are mmap, mremap, brk (apart from the signal stuff already mentioned in the current
tagged-pointers.rstdoc).
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
So I can remove this paragraph altogether and add a note in part 3 of the
tagged-address-abi.rstdocument that mmap/mremap/brk do not preserve the tag information.Deleting text is always a good idea ;)
I'm going this route ;).
[reply deleted]
Cheers
---Dave