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
On some architectures, modules (and the kernel itself) may have
different ELF properties than native userspace executables. On arm64
hybrid PCuABI kernels, userspace executables have the purecap
EF_AARCH64_CHERI_PURECAP ELF flag, while modules do not. This means that
elf_check_arch() cannot be used for modules.
For the time being, work around this by skipping elf_check_arch() for
modules when CONFIG_CHERI_PURECAP_UABI=y, and do the entire ELF check in
module_elf_check_arch(). This enables modules to be loaded on a PCuABI
kernel.
Signed-off-by: Kristina Martsenko <kristina.martsenko(a)arm.com>
---
Changes in v2:
- Use ARCH_MODULE_SKIP_ELF_CHECK to work around changes in the 6.4 kernel
- v1: https://op-lists.linaro.org/archives/list/linux-morello@op-lists.linaro.org…
arch/arm64/include/asm/elf.h | 9 +--------
arch/arm64/kernel/module.c | 8 ++++++++
kernel/module/main.c | 2 ++
3 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h
index 6189c8614dd6..f01f1f99cf03 100644
--- a/arch/arm64/include/asm/elf.h
+++ b/arch/arm64/include/asm/elf.h
@@ -95,16 +95,9 @@
* This is used to ensure we don't load something for the wrong architecture.
*/
#ifdef CONFIG_CHERI_PURECAP_UABI
-/*
- * TODO [PCuABI] - elf_check_arch() is also used by the kernel module loader to
- * verify the ELF headers. However, kernel modules, just like the kernel, are
- * currently hybrid binaries and therefore do not have the
- * EF_AARCH64_CHERI_PURECAP flag. As a result elf_check_arch() currently fails
- * for kernel modules. This could be solved by introducing a new macro to check
- * kernel modules.
- */
#define elf_check_arch(x) ((x)->e_machine == EM_AARCH64 && \
(x)->e_flags & EF_AARCH64_CHERI_PURECAP)
+#define ARCH_MODULE_SKIP_ELF_CHECK
#else
#define elf_check_arch(x) ((x)->e_machine == EM_AARCH64)
#endif
diff --git a/arch/arm64/kernel/module.c b/arch/arm64/kernel/module.c
index 5af4975caeb5..46f5f161fc0a 100644
--- a/arch/arm64/kernel/module.c
+++ b/arch/arm64/kernel/module.c
@@ -22,6 +22,14 @@
#include <asm/scs.h>
#include <asm/sections.h>
+#ifdef CONFIG_CHERI_PURECAP_UABI
+bool module_elf_check_arch(Elf_Ehdr *hdr)
+{
+ return hdr->e_machine == EM_AARCH64 &&
+ !(hdr->e_flags & EF_AARCH64_CHERI_PURECAP);
+}
+#endif
+
void *module_alloc(unsigned long size)
{
u64 module_alloc_end = module_alloc_base + MODULES_VSIZE;
diff --git a/kernel/module/main.c b/kernel/module/main.c
index 4e2cf784cf8c..076ba5f21ac9 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -1688,11 +1688,13 @@ static int elf_validity_cache_copy(struct load_info *info, int flags)
info->hdr->e_type, ET_REL);
goto no_exec;
}
+#ifndef ARCH_MODULE_SKIP_ELF_CHECK
if (!elf_check_arch(info->hdr)) {
pr_err("Invalid architecture in ELF header: %u\n",
info->hdr->e_machine);
goto no_exec;
}
+#endif
if (!module_elf_check_arch(info->hdr)) {
pr_err("Invalid module architecture in ELF header: %u\n",
info->hdr->e_machine);
--
2.30.2
---------- Forwarded message ---------
From: Menna Mahmoud <eng.mennamahmoud.mm(a)gmail.com>
Date: Sun, 2 Jul 2023 at 02:23
Subject: Re: [linux-morello-distros] Morello kernel development - Ask for
help
To: Kevin Brodsky <kevin.brodsky(a)arm.com>
Hi Kevin,
On Thu, 29 Jun 2023 at 14:53, Kevin Brodsky <kevin.brodsky(a)arm.com> wrote:
> On 26/06/2023 12:06, Menna Mahmoud wrote:
> > Hi All,
> >
> > I am Menna, a Linux kernel intern- Outreahy internship. I worked on a
> > project related to the Morello kernel. I checked the user guides and
> > followed this: https://git.morello-project.org/morello/morello-linux,
> > but I have a problem I couldn't create my own FVP kernel image and run
> > it, I want to develop the kernel and update the FVP image and run it
> > but I don't know how to do that.
> >
> > Could you please help me?
>
> Hi Menna,
>
> Welcome to Morello! I apologise for getting back to you only now. We'll
> be happy to help you get started.
>
> I understand that you have already managed to build the kernel using the
> SDK [1]. Running it on FVP using the environment provided in [2] is
> unfortunately not as straightforward at the moment. That said, we have
> put together some instructions that should allow you to do this fairly
> easily.
>
> Assuming you already have an SDK environment looking like this (with the
> kernel built under workspace/linux-out):
> |-> workspace/
> |-> linux/
> |-> linux-out/
> |-> docker-compose.yml
>
> You can combine this with the morello-linux environment by adding it to
> docker-compose.yml; for reference I copied the docker-compose.yml I used
> at the end of this email.
>
> You should then be able to use the following instructions:
>
> 1. Start the containers:
>
> $ docker-compose up -d
>
> 2. Still on the host, download this package for later use:
>
> $ curl -O --output-dir workspace
>
> http://deb.debian.org/debian/pool/main/k/kexec-tools/kexec-tools_2.0.20-2.1…
I got an error with this, so I downloaded `kexec-tools_2.0.20-2.1_arm64.deb
<http://deb.debian.org/debian/pool/main/k/kexec-tools/kexec-tools_2.0.20-2.1…>`
in the workspace directory, Is it right?
>
> 3. Enter the morello-linux container:
>
> $ docker exec -it -u 1000 morello-linux /bin/bash
>
> 4. Using an editor like vim, open /usr/bin/morello and append on the
> last line "-v /morello", it should now look like this:
>
> morello-run.sh -f distro -i
> /usr/share/morello/images/morello-fvp/morello-fvp.img -v /morello
>
> (This specifies that /morello should be made available to be mounted as
> a 9P filesystem in FVP, see step 6.)
>
> 5. Start FVP:
>
> # morello
>
> 6. Once FVP has booted, mount the 9P filesystem to access the /morello
> directory in the container:
>
> # mkdir /mnt/9p
> # mount -t 9p -o trans=virtio,version=9p2000.L FM /mnt/9p
>
> 7. Install the previously downloaded kexec-tools package:
>
> # dpkg -i /mnt/9p/kexec-tools_2.0.20-2.1_arm64.deb
>
> 8. You should now be able to boot your own kernel image using kexec [3]:
>
> # kexec -l /mnt/9p/linux-out/arch/arm64/boot/Image --reuse-cmdline
>
I got this after this step:
```
root@morello:~# kexec -l /mnt/9p/linux-out/arch/arm64/boot/Image
--reuse-cmdline
Can't open (/proc/kcore).
Can't open (/proc/kcore).
```
any advise, please?
> # systemctl kexec
>
> The system will shut down and then reboot using the provided image. To
> make development easier, you could automate the mounting of the 9P
> filesystem, for instance by adding it to /etc/fstab.
>
> I hope this will work well for you, let us know otherwise. We are
> working on improving the environments to remove the need for some of the
> steps above, and generally make it easier to run custom kernels.
>
> Do not hesitate to ask any further question on the linux-morello list -
> this is the best place for any question related to Morello kernel
> development.
>
> Cheers,
> Kevin
>
> [1] https://sdk.morello-project.org/docs/linux/
> [2] https://linux.morello-project.org/docs/intro/
> [3] https://man7.org/linux/man-pages/man8/kexec.8.html
>
> ------8<------
>
> docker-compose.yml
>
> # Docker composer file for Morello Linux
> version: '3.8'
> services:
> linux-morello-sdk:
> image:
> "git.morello-project.org:5050/morello/morello-sdk/morello-sdk:latest"
> container_name: "linux-morello-sdk"
> volumes:
> - ./workspace:/home/morello/workspace
> tty: true
> restart: unless-stopped
> morello-linux:
> image:
> "git.morello-project.org:5050/morello/morello-linux/morello-linux:latest"
> container_name: "morello-linux"
> environment:
> - UID=1000
> - GID=1000
> volumes:
> - ./workspace:/morello
> tty: true
> restart: unless-stopped
>
>
Thanks in advance,
Menna
According to the documentation of fcntl, some commands take an int as
argument. In practice not all of them enforce this behaviour, as they
instead accept a more permissive long and in most cases not even a
range check is performed.
An issue could possibly arise from a combination of the handling of the
varargs in user space and the ABI rules of the target, which may result
in the top bits of an int argument being non-zero.
This issue was originally raised and detailed in the following thread:
https://lore.kernel.org/linux-api/Y1%2FDS6uoWP7OSkmd@arm.com/
And was discovered during the porting of Linux to Morello [1].
This series modifies the interested commands so that they explicitly
take an int argument. It also propagates this change down to helper and
related functions as necessary.
This series is also available on my fork at:
https://git.morello-project.org/Sevenarth/linux/-/commits/fcntl-int-handlin…
Best regards,
Luca Vizzarro
[1] https://git.morello-project.org/morello/kernel/linux
Luca Vizzarro (5):
fcntl: Cast commands with int args explicitly
fs: Pass argument to fcntl_setlease as int
pipe: Pass argument of pipe_fcntl as int
memfd: Pass argument of memfd_fcntl as int
dnotify: Pass argument of fcntl_dirnotify as int
fs/cifs/cifsfs.c | 2 +-
fs/fcntl.c | 29 +++++++++++++++--------------
fs/libfs.c | 2 +-
fs/locks.c | 20 ++++++++++----------
fs/nfs/nfs4_fs.h | 2 +-
fs/nfs/nfs4file.c | 2 +-
fs/nfs/nfs4proc.c | 4 ++--
fs/notify/dnotify/dnotify.c | 4 ++--
fs/pipe.c | 6 +++---
include/linux/dnotify.h | 4 ++--
include/linux/filelock.h | 12 ++++++------
include/linux/fs.h | 6 +++---
include/linux/memfd.h | 4 ++--
include/linux/pipe_fs_i.h | 4 ++--
mm/memfd.c | 6 +-----
15 files changed, 52 insertions(+), 55 deletions(-)
--
2.34.1