Syscalls operating on memory mappings manage their address space via
owning capabilities. They must adhere to a certain set of rules[1] in
order to ensure memory safety. Address space management syscalls are
only allowed to manipulate mappings that are within the range of the
owning capability and have the appropriate permissions. Tests to
vailidate the parameters being passed to the syscall, check its bounds,
range as well as permissions have been added. Additionally, a signal
handler has been registered to handle invalid memory access. Finally, as
certain flags and syscalls conflict with the reservation model or lack
implementation, a check to verify appropriate handling of the same has
also been added.
Review branch:
https://git.morello-project.org/chaitanya_prakash/linux/-/tree/review/mmap_…
This patch series has been tested on:
https://git.morello-project.org/amitdaniel/linux/-/tree/review/extern_reser…
[1] https://git.morello-project.org/morello/kernel/linux/-/wikis/Morello-pure-c…
Changes in V2:
- Added link to the review branch
- Removed unnecessary whitespace
Changes in V1:
https://op-lists.linaro.org/archives/list/linux-morello@op-lists.linaro.org…
Chaitanya S Prakash (8):
kselftests/arm64/morello: Add necessary support for mmap testcases
kselftests/arm64/morello: Add MAP_GROWSDOWN testcase
kselftests/arm64/morello: Add parameter check testcases
kselftests/arm64/morello: Add capability range testcases
kselftests/arm64/morello: Add mmap() bounds check testcases
kselftests/arm64/morello: Add mremap() bounds check testcases
kselftests/arm64/morello: Add mremap() permission testcases
kselftests/arm64/morello: Add brk() testcase
.../testing/selftests/arm64/morello/Makefile | 1 +
.../selftests/arm64/morello/freestanding.h | 62 ++-
tools/testing/selftests/arm64/morello/mmap.c | 479 +++++++++++++++++-
3 files changed, 535 insertions(+), 7 deletions(-)
--
2.25.1
This series of patches enables nfs rootfs
support on the Morello board.
Patch 01 is fixing the inital kernel build error
associated with a wrong function pointer type within
the sunrpc modules due to the unlocked_ioctl fp,
the error occurs upon enabling nfs within the defconfig.
Patch 02 deals with the fallout caused by changes
inferred by patches 01. See details in the description
of the patch.
Patch 03 is enabling nfs rootfs by default in the kernel.
It was confirmed that the kernel can boot with a nfs rootfs.
V3 changes:
- fix commit title @ patch 2
- align the change in proc.c
Pawel Zalewski (3):
net: sunrpc: fix unlocked_ioctl handler signature
proc: change proc_ops.proc_ioct handler signature
arm64: morello: enable nfs rootfs by default
arch/arm64/configs/morello_transitional_pcuabi_defconfig | 2 ++
drivers/pci/proc.c | 4 ++--
include/linux/proc_fs.h | 2 +-
net/sunrpc/cache.c | 6 +++---
net/sunrpc/rpc_pipe.c | 2 +-
5 files changed, 9 insertions(+), 7 deletions(-)
--
2.34.1
This series makes it possible for purecap apps to use the aio_ring
shared memory region to bypass the io_getevents syscall's overhead.
This functionality is also used in libaio.
With these patches, all io_* LTP tests pass in both Purecap and
plain AArch64 modes. Note that the LTP tests only address the basic
functionality of the aio system and a significant portion of the
functionality is untested in LTP.
For a more comprehensive testing, libaio has been updated with the new
uAPI and ported. All the tests in libaio pass accordingly, in both
Purecap and plain AArch64 modes.
v4..v3:
- Restore flush_dcache_page in all places with the exception of one
where is replaced with flush_kernel_vmap_range
- Use ifdef instead of IS_ENABLED in a few places
- Improve formatting
v3..v2:
- Improve the commit messages
- Revert a few unrelated changes
- Change compat_aio_context_t to compat_uptr_t
- Remove io_events_compat union member
- Improve code formatting
- Add copy_to_user_with_ptr in copy_io_events_to_user
- Split copy_from_user_with_ptr for struct __aio_sigset into a
different patch
v2..v1:
- Add Patch 1 that fixes a parameter type for the compat handler
- Split the change the types to user pointers into two patches: one
for aio_context_t, and the other for io_event struct fields.
- vmap all the ring pages at the beginning and cache them in the ctx
- Don't remap the pages while allowing tag access to the shared
memory. Setting the VM flags is enough.
- Change aio_context_t to a void __user *.
- Improve commit messages.
- Refactor some of the functions for compat handling.
- Create valid user pointers ctx_id when received from a compat task
Gitlab issue:
https://git.morello-project.org/morello/kernel/linux/-/issues/49
Review branch:
https://git.morello-project.org/tudcre01/linux/-/commits/morello/aio_v4
Tudor Cretu (7):
aio: Fix type of nr parameter in compat handler of io_submit
aio: Use copy_from_user_with_ptr for struct __aio_sigset
aio: vmap entire aio_ring instead of kmapping each page
aio: Implement compat handling for the io_event struct
aio: Allow capability tag access on the shared memory
aio: Change aio_context_t to a user pointer
aio: Use user pointer type in the io_event struct
fs/aio.c | 283 ++++++++++++++++++++++-------------
include/asm-generic/compat.h | 4 +-
include/uapi/linux/aio_abi.h | 12 +-
3 files changed, 186 insertions(+), 113 deletions(-)
--
2.34.1
PCuABI enablement entails providing support for userspace
capability pointers which are 128-bit long instead of 64-bit.
This commit implements the support for the futex_waitv syscall
while maintaining the 64-bit compatibility.
Signed-off-by: Luca Vizzarro <Luca.Vizzarro(a)arm.com>
---
Hello!
Sending in patch v3 for issue #48:
https://git.morello-project.org/morello/kernel/linux/-/issues/48
Here you can find a branch with this patch:
https://git.morello-project.org/Sevenarth/linux/-/commits/morello/futex_wai…
LTP fully passes. For the CI this fails only on the purecap tests since
there has been a change in the linux headers. Therefore LTP would need
to be recompiled against this for it to work.
v3:
- updated the copy_from_user function to copy_from_user_with_ptr for
purecap
v2 changes:
- fixes bug where the offset of the futex_waitv list was always
dependent on the size of the purecap struct instead of adapting
to the compat one accordingly.
- fixes the pointer cast in compat appropriately. It was mistakenly
using __kernel_uintcap_t instead of __kernel_uintptr_t.
Best,
Luca
---
include/uapi/linux/futex.h | 2 +-
kernel/futex/syscalls.c | 32 +++++++++++++++++++++++++++++++-
kernel/futex/waitwake.c | 4 ++--
3 files changed, 34 insertions(+), 4 deletions(-)
diff --git a/include/uapi/linux/futex.h b/include/uapi/linux/futex.h
index 71a5df8d2689..93f701d89401 100644
--- a/include/uapi/linux/futex.h
+++ b/include/uapi/linux/futex.h
@@ -63,7 +63,7 @@
*/
struct futex_waitv {
__u64 val;
- __u64 uaddr;
+ __kernel_uintptr_t uaddr;
__u32 flags;
__u32 __reserved;
};
diff --git a/kernel/futex/syscalls.c b/kernel/futex/syscalls.c
index ad4ae797bb84..771cfb51a38d 100644
--- a/kernel/futex/syscalls.c
+++ b/kernel/futex/syscalls.c
@@ -190,6 +190,36 @@ SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val,
/* Mask of available flags for each futex in futex_waitv list */
#define FUTEXV_WAITER_MASK (FUTEX_32 | FUTEX_PRIVATE_FLAG)
+struct compat_futex_waitv {
+ __u64 val;
+ __u64 uaddr;
+ __u32 flags;
+ __u32 __reserved;
+};
+
+static int copy_futex_waitv_from_user(struct futex_waitv *aux,
+ const struct futex_waitv __user *uwaitv,
+ unsigned int i)
+{
+ if (IS_ENABLED(CONFIG_COMPAT64) && in_compat_syscall()) {
+ const struct compat_futex_waitv __user *compat_uwaitv =
+ (const struct compat_futex_waitv __user *)uwaitv;
+ struct compat_futex_waitv compat_aux;
+
+ if (copy_from_user(&compat_aux, &compat_uwaitv[i], sizeof(compat_aux)))
+ return -EFAULT;
+
+ aux->val = compat_aux.val;
+ aux->uaddr = (__kernel_uintptr_t)compat_ptr(compat_aux.uaddr);
+ aux->flags = compat_aux.flags;
+ aux->__reserved = compat_aux.__reserved;
+
+ return 0;
+ }
+
+ return copy_from_user_with_ptr(aux, &uwaitv[i], sizeof(*aux));
+}
+
/**
* futex_parse_waitv - Parse a waitv array from userspace
* @futexv: Kernel side list of waiters to be filled
@@ -206,7 +236,7 @@ static int futex_parse_waitv(struct futex_vector *futexv,
unsigned int i;
for (i = 0; i < nr_futexes; i++) {
- if (copy_from_user(&aux, &uwaitv[i], sizeof(aux)))
+ if (copy_futex_waitv_from_user(&aux, uwaitv, i))
return -EFAULT;
if ((aux.flags & ~FUTEXV_WAITER_MASK) || aux.__reserved)
diff --git a/kernel/futex/waitwake.c b/kernel/futex/waitwake.c
index 1ab5640e7f84..d6b050356f81 100644
--- a/kernel/futex/waitwake.c
+++ b/kernel/futex/waitwake.c
@@ -422,7 +422,7 @@ static int futex_wait_multiple_setup(struct futex_vector *vs, int count, int *wo
if ((vs[i].w.flags & FUTEX_PRIVATE_FLAG) && retry)
continue;
- ret = get_futex_key(u64_to_user_ptr(vs[i].w.uaddr),
+ ret = get_futex_key((u32 __user *)vs[i].w.uaddr,
!(vs[i].w.flags & FUTEX_PRIVATE_FLAG),
&vs[i].q.key, FUTEX_READ);
@@ -433,7 +433,7 @@ static int futex_wait_multiple_setup(struct futex_vector *vs, int count, int *wo
set_current_state(TASK_INTERRUPTIBLE|TASK_FREEZABLE);
for (i = 0; i < count; i++) {
- u32 __user *uaddr = uaddr_to_user_ptr(vs[i].w.uaddr);
+ u32 __user *uaddr = (u32 __user *)vs[i].w.uaddr;
struct futex_q *q = &vs[i].q;
u32 val = (u32)vs[i].w.val;
--
2.34.1
PCuABI enablement entails providing support for userspace
capability pointers which are 128-bit long instead of 64-bit.
This commit implements the support for the futex_waitv syscall
while maintaining the 64-bit compatibility.
Signed-off-by: Luca Vizzarro <Luca.Vizzarro(a)arm.com>
---
Hello!
Sending in patch v2 for issue #48:
https://git.morello-project.org/morello/kernel/linux/-/issues/48
Here you can find a branch with this patch:
https://git.morello-project.org/Sevenarth/linux/-/commits/morello/futex_wai…
LTP fully passes. For the CI this fails only on the purecap tests since
there has been a change in the linux headers. Therefore LTP would need
to be recompiled against this for it to work.
v2 changes:
- fixes bug where the offset of the futex_waitv list was always
dependent on the size of the purecap struct instead of adapting
to the compat one accordingly.
- fixes the pointer cast in compat appropriately. It was mistakenly
using __kernel_uintcap_t instead of __kernel_uintptr_t.
Best,
Luca
---
include/uapi/linux/futex.h | 2 +-
kernel/futex/syscalls.c | 32 +++++++++++++++++++++++++++++++-
kernel/futex/waitwake.c | 4 ++--
3 files changed, 34 insertions(+), 4 deletions(-)
diff --git a/include/uapi/linux/futex.h b/include/uapi/linux/futex.h
index 71a5df8d2689..93f701d89401 100644
--- a/include/uapi/linux/futex.h
+++ b/include/uapi/linux/futex.h
@@ -63,7 +63,7 @@
*/
struct futex_waitv {
__u64 val;
- __u64 uaddr;
+ __kernel_uintptr_t uaddr;
__u32 flags;
__u32 __reserved;
};
diff --git a/kernel/futex/syscalls.c b/kernel/futex/syscalls.c
index ad4ae797bb84..c2e4529083a3 100644
--- a/kernel/futex/syscalls.c
+++ b/kernel/futex/syscalls.c
@@ -190,6 +190,36 @@ SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val,
/* Mask of available flags for each futex in futex_waitv list */
#define FUTEXV_WAITER_MASK (FUTEX_32 | FUTEX_PRIVATE_FLAG)
+struct compat_futex_waitv {
+ __u64 val;
+ __u64 uaddr;
+ __u32 flags;
+ __u32 __reserved;
+};
+
+static int copy_futex_waitv_from_user(struct futex_waitv *aux,
+ const struct futex_waitv __user *uwaitv,
+ unsigned int i)
+{
+ if (IS_ENABLED(CONFIG_COMPAT64) && in_compat_syscall()) {
+ const struct compat_futex_waitv __user *compat_uwaitv =
+ (const struct compat_futex_waitv __user *)uwaitv;
+ struct compat_futex_waitv compat_aux;
+
+ if (copy_from_user(&compat_aux, &compat_uwaitv[i], sizeof(compat_aux)))
+ return -EFAULT;
+
+ aux->val = compat_aux.val;
+ aux->uaddr = (__kernel_uintptr_t)compat_ptr(compat_aux.uaddr);
+ aux->flags = compat_aux.flags;
+ aux->__reserved = compat_aux.__reserved;
+
+ return 0;
+ }
+
+ return copy_from_user(aux, &uwaitv[i], sizeof(*aux));
+}
+
/**
* futex_parse_waitv - Parse a waitv array from userspace
* @futexv: Kernel side list of waiters to be filled
@@ -206,7 +236,7 @@ static int futex_parse_waitv(struct futex_vector *futexv,
unsigned int i;
for (i = 0; i < nr_futexes; i++) {
- if (copy_from_user(&aux, &uwaitv[i], sizeof(aux)))
+ if (copy_futex_waitv_from_user(&aux, uwaitv, i))
return -EFAULT;
if ((aux.flags & ~FUTEXV_WAITER_MASK) || aux.__reserved)
diff --git a/kernel/futex/waitwake.c b/kernel/futex/waitwake.c
index 1ab5640e7f84..d6b050356f81 100644
--- a/kernel/futex/waitwake.c
+++ b/kernel/futex/waitwake.c
@@ -422,7 +422,7 @@ static int futex_wait_multiple_setup(struct futex_vector *vs, int count, int *wo
if ((vs[i].w.flags & FUTEX_PRIVATE_FLAG) && retry)
continue;
- ret = get_futex_key(u64_to_user_ptr(vs[i].w.uaddr),
+ ret = get_futex_key((u32 __user *)vs[i].w.uaddr,
!(vs[i].w.flags & FUTEX_PRIVATE_FLAG),
&vs[i].q.key, FUTEX_READ);
@@ -433,7 +433,7 @@ static int futex_wait_multiple_setup(struct futex_vector *vs, int count, int *wo
set_current_state(TASK_INTERRUPTIBLE|TASK_FREEZABLE);
for (i = 0; i < count; i++) {
- u32 __user *uaddr = uaddr_to_user_ptr(vs[i].w.uaddr);
+ u32 __user *uaddr = (u32 __user *)vs[i].w.uaddr;
struct futex_q *q = &vs[i].q;
u32 val = (u32)vs[i].w.val;
--
2.34.1
kselftest.rst states that flags must be specified before including lib.mk,
but the vDSO selftest Makefile does not follow this order. As a result,
changes made by lib.mk to flags and other variables are overwritten by the
Makefile. For example, it is impossible to pass CFLAGS to the compiler via
Make. Rectify this by including lib.mk after assigning flag values.
Also change the paths of the generated programs from absolute to relative
paths as lib.mk will now correctly prepend the output directory path to
the program name as intended.
Signed-off-by: Aditya Deshpande <aditya.deshpande(a)arm.com>
---
Changes in v2:
Removed the line all: $(TEST_GEN_PROGS) as it is redundant (as Kevin
pointed out).
---
tools/testing/selftests/vDSO/Makefile | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/tools/testing/selftests/vDSO/Makefile b/tools/testing/selftests/vDSO/Makefile
index d53a4d8008f9..19145210d044 100644
--- a/tools/testing/selftests/vDSO/Makefile
+++ b/tools/testing/selftests/vDSO/Makefile
@@ -1,16 +1,15 @@
# SPDX-License-Identifier: GPL-2.0
-include ../lib.mk
-
uname_M := $(shell uname -m 2>/dev/null || echo not)
ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/)
-TEST_GEN_PROGS := $(OUTPUT)/vdso_test_gettimeofday $(OUTPUT)/vdso_test_getcpu
-TEST_GEN_PROGS += $(OUTPUT)/vdso_test_abi
-TEST_GEN_PROGS += $(OUTPUT)/vdso_test_clock_getres
+TEST_GEN_PROGS := vdso_test_gettimeofday
+TEST_GEN_PROGS += vdso_test_getcpu
+TEST_GEN_PROGS += vdso_test_abi
+TEST_GEN_PROGS += vdso_test_clock_getres
ifeq ($(ARCH),$(filter $(ARCH),x86 x86_64))
-TEST_GEN_PROGS += $(OUTPUT)/vdso_standalone_test_x86
+TEST_GEN_PROGS += vdso_standalone_test_x86
endif
-TEST_GEN_PROGS += $(OUTPUT)/vdso_test_correctness
+TEST_GEN_PROGS += vdso_test_correctness
CFLAGS := -std=gnu99
CFLAGS_vdso_standalone_test_x86 := -nostdlib -fno-asynchronous-unwind-tables -fno-stack-protector
@@ -19,7 +18,8 @@ ifeq ($(CONFIG_X86_32),y)
LDLIBS += -lgcc_s
endif
-all: $(TEST_GEN_PROGS)
+include ../lib.mk
+
$(OUTPUT)/vdso_test_gettimeofday: parse_vdso.c vdso_test_gettimeofday.c
$(OUTPUT)/vdso_test_getcpu: parse_vdso.c vdso_test_getcpu.c
$(OUTPUT)/vdso_test_abi: parse_vdso.c vdso_test_abi.c
--
2.25.1
kselftest.rst states that flags must be specified before including lib.mk,
but the vDSO selftest Makefile does not follow this order. As a result,
changes made by lib.mk to flags and other variables are overwritten by the
Makefile. For example, it is impossible to pass CFLAGS to the compiler via
Make. Rectify this by including lib.mk after assigning flag values.
Also change the paths of the generated programs from absolute to relative
paths as lib.mk will now correctly prepend the output directory path to
the program name as intended.
Signed-off-by: Aditya Deshpande <aditya.deshpande(a)arm.com>
---
Hello,
This patch fixes the vDSO Makefile so that we can pass flags to it
via the command line. This lets us build the vDSO selftests for
Morello by exporting USERCFLAGS with the appropriate flags. Note that
this patch is based off kernel version 6.4, as it relies on features
added to lib.mk in the 6.2 release by:
Commit de3ee3f63400a23954e7 ("selftests: Use optional USERCFLAGS and
USERLDFLAGS").
Sending for review here before sending to the main kernel list.
Changes available at:
https://git.morello-project.org/aditya/linux-kevin-fork/-/commit/3025e6659e…
---
tools/testing/selftests/vDSO/Makefile | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/tools/testing/selftests/vDSO/Makefile b/tools/testing/selftests/vDSO/Makefile
index d53a4d8008f9..9bf048498313 100644
--- a/tools/testing/selftests/vDSO/Makefile
+++ b/tools/testing/selftests/vDSO/Makefile
@@ -1,16 +1,15 @@
# SPDX-License-Identifier: GPL-2.0
-include ../lib.mk
-
uname_M := $(shell uname -m 2>/dev/null || echo not)
ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/)
-TEST_GEN_PROGS := $(OUTPUT)/vdso_test_gettimeofday $(OUTPUT)/vdso_test_getcpu
-TEST_GEN_PROGS += $(OUTPUT)/vdso_test_abi
-TEST_GEN_PROGS += $(OUTPUT)/vdso_test_clock_getres
+TEST_GEN_PROGS := vdso_test_gettimeofday
+TEST_GEN_PROGS += vdso_test_getcpu
+TEST_GEN_PROGS += vdso_test_abi
+TEST_GEN_PROGS += vdso_test_clock_getres
ifeq ($(ARCH),$(filter $(ARCH),x86 x86_64))
-TEST_GEN_PROGS += $(OUTPUT)/vdso_standalone_test_x86
+TEST_GEN_PROGS += vdso_standalone_test_x86
endif
-TEST_GEN_PROGS += $(OUTPUT)/vdso_test_correctness
+TEST_GEN_PROGS += vdso_test_correctness
CFLAGS := -std=gnu99
CFLAGS_vdso_standalone_test_x86 := -nostdlib -fno-asynchronous-unwind-tables -fno-stack-protector
@@ -19,6 +18,8 @@ ifeq ($(CONFIG_X86_32),y)
LDLIBS += -lgcc_s
endif
+include ../lib.mk
+
all: $(TEST_GEN_PROGS)
$(OUTPUT)/vdso_test_gettimeofday: parse_vdso.c vdso_test_gettimeofday.c
$(OUTPUT)/vdso_test_getcpu: parse_vdso.c vdso_test_getcpu.c
--
2.25.1
Syscalls operating on memory mappings manage their address space via
owning capabilities. They must adhere to a certain set of rules[1] in
order to ensure memory safety. Address space management syscalls are
only allowed to manipulate mappings that are within the range of the
owning capability and have the appropriate permissions. Tests to
vailidate the parameters being passed to the syscall, check its bounds,
range as well as permissions have been added. Additionally, a signal
handler has been registered to handle invalid memory access. Finally, as
certain flags and syscalls conflict with the reservation model or lack
implementation, a check to verify appropriate handling of the same has
also been added.
This patch series has been tested on:
https://git.morello-project.org/amitdaniel/linux/-/tree/review/extern_reser…
[1] https://git.morello-project.org/morello/kernel/linux/-/wikis/Morello-pure-c…
Chaitanya S Prakash (8):
kselftests/arm64/morello: Add necessary support for mmap testcases
kselftests/arm64/morello: Add MAP_GROWSDOWN testcase
kselftests/arm64/morello: Add parameter check testcases
kselftests/arm64/morello: Add capability range testcases
kselftests/arm64/morello: Add mmap() bounds check testcases
kselftests/arm64/morello: Add mremap() bounds check testcases
kselftests/arm64/morello: Add mremap() permission testcases
kselftests/arm64/morello: Add brk() testcase
.../testing/selftests/arm64/morello/Makefile | 1 +
.../selftests/arm64/morello/freestanding.h | 62 ++-
tools/testing/selftests/arm64/morello/mmap.c | 480 +++++++++++++++++-
3 files changed, 536 insertions(+), 7 deletions(-)
--
2.25.1