Hi,
This short series refactors the way pointers to the stack are
manipulated in binfmt_elf. The changes are generic and arguably improve
binfmt_elf, but the main objective is to eliminate unnecessary creation
of capabilities in PCuABI (through calls to uaddr_to_user_ptr_safe()).
This is done by using an actual user pointer to keep track of the
current position on the stack, and writing all data through that
pointer, instead of using an addresss and creating a new user pointer
for every access. This is what patch 1 does. Patch 2 simplifies the
elf_stack_put_user* macros we previously introduced, as we do not need
them to do something special in PCuABI any more.
This series should help with further work on restricting initial
capabilities [1]. It does not have any user-visible effect itself
however. The new "root stack capability" is still unrestricted, but the
fact that all capabilities to the stack are derived from it means that
any later narrowing of its bounds or permissions will automatically
propagate.
Note that these changes are mostly orthogonal to Téo's series [2] that
partially addresses [1]; it just means that using
uaddr_to_user_ptr_safe() is no longer necessary to derive the argv /
envp capabilities.
Review branch:
https://git.morello-project.org/kbrodsky-arm/linux/-/commits/morello/binfmt…
Thanks,
Kevin
[1] https://git.morello-project.org/morello/kernel/linux/-/issues/19
[2] https://op-lists.linaro.org/archives/list/linux-morello@op-lists.linaro.org…
Kevin Brodsky (2):
fs/binfmt_elf: Improve SP manipulation in PCuABI
fs/binfmt_elf: Simplify elf_stack_put_user*
fs/binfmt_elf.c | 85 +++++++++++++++++++++++-------------------
fs/compat_binfmt_elf.c | 9 +----
include/linux/elf.h | 12 +-----
3 files changed, 48 insertions(+), 58 deletions(-)
--
2.38.1
Hi,
After getting side tracked by eBPF libraries/tools (libbpf/bpftool) and
kselftest cross-compilation, here's the core kernel changes following on
from the RFC[1] posted late last year.
The bpf syscall is updated to propagate user pointers as capabilities in
the pure-capability kernel-user ABI (PCuABI). It also includes an
approach to support the existing aarch64 ABI as a compatibility layer
(compat64).
One complication here is from the fact this syscall supports many
multiplexed sub-commands, some of which are themselves multiplexed with
a number of nested multiplexed options.
A further complication is that the existing syscall uses a trick of
storing user pointers as u64 to avoid needing a compat handler for
32-bit systems (see patch 3). To retain compatibility with the aarch64
ABI and add Morello support, a compat layer is added here only for the
compat64 case, guarded by #ifdef CONFIG_COMPAT64. Normal compat32
operation is therefore unchanged.
Compared to the original RFC, inbound (userspace->kernel) conversion
between compat64/native struct layouts is now handled upfront. This
minimises changes to subcommand handlers. Some subcommands require
conversion back out to userspace and that is by necessity handled where
it occurs.
Patch 1 is not essential to this series but it's a nice debug feature to
have and works[2]. It enables BPF_PROG_TYPE_TRACEPOINT which many eBPF
kselftests use.
Patch 2 is required setup for the rest of the patches.
Patches 3-8 implement the core compat64 handling. Each commit compiles
cleanly but relevant parts will be broken inbetween. They're split
mainly to make review here easier.
Patch 9 fixes a check to also check configs passed in via compat64.
Patch 10 finally enables capabilities in the kernel.
Testing wise, see associated LTP changes below which will be posted to
linux-morello-ltp mailing list. The eBPF LTP tests are fairly minimal
and test only a small part of the changes here. There's a new test to
test patch 9.
The kernel kselftests contain much more extensive eBPF tests. The
kselftests have been used to test many parts of the compat64 handling
but overall more work needs to be done here:
a) enable cross-compilation for purecap as well as x86->aarch64
b) replace ptr_to_u64() with casts to uintptr_t in tests
b) general libbpf/bpftool enablement and fixes since many tests rely
on this
c) CONFIG_DEBUG_INFO_BTF required for many tests but this requires
the build system to have a recent version of pahole tool
Next steps once we have the core kernel support is porting libbpf and
bpftool for purecap plus work on enabling kselftests as above.
Kernel branch available at:
https://git.morello-project.org/zdleaf/linux/-/tree/morello/bpf
Associated LTP test/changes at:
https://git.morello-project.org/zdleaf/morello-linux-test-project/-/tree/mo…
Thanks,
Zach
[1] [RFC PATCH 0/9] update bpf syscall for PCuABI/compat64
https://op-lists.linaro.org/archives/list/linux-morello@op-lists.linaro.org…
[2] [PATCH v3 0/5] Restore syscall tracing on Morello
https://op-lists.linaro.org/archives/list/linux-morello@op-lists.linaro.org…
Zachary Leaf (10):
arm64: morello: enable syscall tracing
bpf/net: copy ptrs from user with bpf/sockptr_t
bpf: compat64: add handler and convert bpf_attr in
bpf: compat64: bpf_attr convert out
bpf: compat64: handle bpf_btf_info
bpf: compat64: handle bpf_prog_info
bpf: compat64: handle bpf_map_info
bpf: compat64: handle bpf_link_info
bpf: compat64: support CHECK_ATTR macro
bpf: use user pointer types in uAPI structs
.../morello_transitional_pcuabi_defconfig | 2 +-
arch/arm64/kernel/sys_compat64.c | 4 +
drivers/media/rc/bpf-lirc.c | 7 +-
include/linux/bpf_compat.h | 413 ++++++
include/linux/bpfptr.h | 18 +-
include/linux/sockptr.h | 9 +
include/uapi/linux/bpf.h | 94 +-
kernel/bpf/bpf_iter.c | 2 +-
kernel/bpf/btf.c | 97 +-
kernel/bpf/cgroup.c | 10 +-
kernel/bpf/hashtab.c | 13 +-
kernel/bpf/net_namespace.c | 7 +-
kernel/bpf/offload.c | 2 +-
kernel/bpf/syscall.c | 1136 +++++++++++++----
kernel/bpf/verifier.c | 2 +-
kernel/trace/bpf_trace.c | 6 +-
net/bpf/bpf_dummy_struct_ops.c | 3 +-
net/bpf/test_run.c | 32 +-
net/core/sock_map.c | 7 +-
19 files changed, 1534 insertions(+), 330 deletions(-)
create mode 100644 include/linux/bpf_compat.h
--
2.34.1
Hello!
Here is patch series v5 incoming for the explicit capability checking
series for issue #7[1].
This patch series can be found on my fork[2].
Kind regards,
Luca
[1] https://git.morello-project.org/morello/kernel/linux/-/issues/7
[2] https://git.morello-project.org/Sevenarth/linux/-/commits/morello/gup-check…
v5:
- rephrased commit descriptions
- changed explicit checks for the USB code to be performed only when
performing DMA transfers
v4:
- rebased onto morello/next
- rephrased commit descriptions and notes left in the code
- signature of first_iovec_segment has been updated to return a pointer
instead of an address and the appropriate changes have been made
- read+write checks have been combined together in the same if statement
- unlikely check has been removed where appropriate
- the USB User Request Block buffer is now checked against both write and
read permissions according to the transfer direction as indicated by
is_in
- a leftover from v2 at io_uring/rsrc.c:1249 has been reverted back to
original
v3:
- rebased onto morello/next
- amended commit description for "gup: Add explicit capability checks"
- refactored mm/gup.c
- refactored lib/iov_iter.c
- removed bpf patch
- moved USB Request Block explicit check to proc_do_submiturb
- removed explicit check in get_futex_key
- changed prototype of io_uring_cmd_import_fixed and io_import_fixed to
use a pointer type and adjusted the relevant castings
- fixed io_uring_cmd_import_fixed prototype for !defined(CONFIG_IO_URING)
- refactored explicit check in io_uring/kbuf.c:io_register_pbuf_ring(..)
- removed explicit check from io_uring/kbuf.c:io_add_buffers(..)
- rephrased the no explicit check needed note in io_sqe_buffer_register
- reverted "struct io_mapped_ubuf" to use u64
- removed explicit check from io_uring_cmd_prep
- updated TODO for the NVMe driver
Luca Vizzarro (7):
gup: Add explicit capability checks
iov_iter: Add explicit capability checks
usb: core: Fix copy of URB from userspace
usb: core: Add explicit capability checks
futex: Add explicit capability checks
io_uring: Add explicit capability checks
nvme: Add TODO for PCuABI implementation
drivers/nvme/host/ioctl.c | 1 +
drivers/usb/core/devio.c | 10 ++++++++--
include/linux/io_uring.h | 6 +++---
include/linux/pagemap.h | 2 +-
io_uring/kbuf.c | 26 +++++++++++++-------------
io_uring/net.c | 3 +--
io_uring/rsrc.c | 14 ++++++++++++--
io_uring/rsrc.h | 2 +-
io_uring/rw.c | 3 +--
io_uring/uring_cmd.c | 2 +-
kernel/futex/core.c | 11 ++++++++---
lib/iov_iter.c | 31 ++++++++++++++++++++++++-------
mm/gup.c | 6 ++++--
13 files changed, 78 insertions(+), 39 deletions(-)
--
2.34.1
Hello!
Here is patch series v4 incoming for the explicit capability checking
series for issue #7[1].
This patch series will be found on my fork at the link in the
footnotes[2], as soon as GitLab is fixed.
Kind regards,
Luca
[1] https://git.morello-project.org/morello/kernel/linux/-/issues/7
[2] https://git.morello-project.org/Sevenarth/linux/-/commits/morello/gup-check…
v4:
- rebased onto morello/next
- rephrased commit descriptions and notes left in the code
- signature of first_iovec_segment has been updated to return a pointer
instead of an address and the appropriate changes have been made
- read+write checks have been combined together in the same if statement
- unlikely check has been removed where appropriate
- the USB User Request Block buffer is now checked against both write and
read permissions according to the transfer direction as indicated by
is_in
- a leftover from v2 at io_uring/rsrc.c:1249 has been reverted back to
original
v3:
- rebased onto morello/next
- amended commit description for "gup: Add explicit capability checks"
- refactored mm/gup.c
- refactored lib/iov_iter.c
- removed bpf patch
- moved USB Request Block explicit check to proc_do_submiturb
- removed explicit check in get_futex_key
- changed prototype of io_uring_cmd_import_fixed and io_import_fixed to
use a pointer type and adjusted the relevant castings
- fixed io_uring_cmd_import_fixed prototype for !defined(CONFIG_IO_URING)
- refactored explicit check in io_uring/kbuf.c:io_register_pbuf_ring(..)
- removed explicit check from io_uring/kbuf.c:io_add_buffers(..)
- rephrased the no explicit check needed note in io_sqe_buffer_register
- reverted "struct io_mapped_ubuf" to use u64
- removed explicit check from io_uring_cmd_prep
- updated TODO for the NVMe driver
Luca Vizzarro (7):
gup: Add explicit capability checks
iov_iter: Add explicit capability checks
usb: core: Fix copy of URB from userspace
usb: core: Add explicit capability checks
futex: Add explicit capability checks
io_uring: Add explicit capability checks
nvme: Add TODO for PCuABI implementation
drivers/nvme/host/ioctl.c | 1 +
drivers/usb/core/devio.c | 8 ++++++--
include/linux/io_uring.h | 6 +++---
include/linux/pagemap.h | 2 +-
io_uring/kbuf.c | 26 +++++++++++++-------------
io_uring/net.c | 3 +--
io_uring/rsrc.c | 14 ++++++++++++--
io_uring/rsrc.h | 2 +-
io_uring/rw.c | 3 +--
io_uring/uring_cmd.c | 2 +-
kernel/futex/core.c | 11 ++++++++---
lib/iov_iter.c | 31 ++++++++++++++++++++++++-------
mm/gup.c | 6 ++++--
13 files changed, 76 insertions(+), 39 deletions(-)
--
2.34.1
Signal handlers that intend to set PCC to a new value need to be
careful not to use a sealed function pointer (sentry) directly. In
purecap, function pointers are typically sentries and therefore need
to be explicitly unsealed and their LSB cleared (as per the bullet
point above).
Reported-by: Yury Khrustalev <yury.khrustalev(a)arm.com>
Signed-off-by: Kevin Brodsky <kevin.brodsky(a)arm.com>
---
Documentation/arm64/morello.rst | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/Documentation/arm64/morello.rst b/Documentation/arm64/morello.rst
index 3452f4fe4fa9..0a76bbf06290 100644
--- a/Documentation/arm64/morello.rst
+++ b/Documentation/arm64/morello.rst
@@ -552,6 +552,11 @@ Note: modifying the saved Morello context
to modify the ISA of the interrupted context by writing to the C64
bit of the saved PSTATE in ``sigcontext``.
+ * RB-sealed capabilities. The saved PCC should not be RB-sealed; unlike
+ capability-based branch instructions, exception return uses the target
+ capability as-is, without automatic unsealing. Explicit unsealing is
+ therefore required to avoid a capability sealed fault.
+
C64 ISA support
---------------
--
2.38.1
Hi All,
This patch series introduces the mm reservation interface to manage
the owning capability of the allocated addresses. Looking for feedback
regarding interface names, interface directory structure, reservation layer
outside the VMA(current approach) vs reservation layer inside the VMA etc.
Below are the implemented features in brief:
1) Reservation interface to implement the different PCuABI reservation rules.
This reservations sits outside the VMA layer and can be used before and after
the VMA updates. Currently all interfaces supports only mmap_lock locked version.
2) The reservation interfaces and owning capability helpers are created as a library
so that they can be used by different components (i.e. mm, elf loaders etc.).
3) munmap() syscall allows shrinking the mappings but reservation range remains fixed
so they cannot be mapped again until the last mapping in the reservation range is unmapped.
4) mremap() trying to remap new size lesser then old size behaves same as munmap. mremap()
with new size larger than old size and with MREMAP_MAYMOVE flag will move the reservation
also if the mapped range is same as reservation range.
4) Reservation bound constraint checks added for mprotect, madvise,
mlock, mincore and msync syscall.
5) Helpers added to validate the capability address permission constraints.
6) Capability permission constraint checks added for mmap, mremap and mprotect syscall.
7) Details about several rules implemented can be found in PCuABI spec here [1].
Limitations/Unimplemented works:
1) Users of vm_mmap/vm_munmap() i.e. filesystems, loaders etc are not
modified to preserve capability addresses so patch 6
"mm/(mmap, munmap): Limit reservation for only syscalls" added to
limit reservation to syscalls.
2) Patch 15 "lib/cap_addr_mgmt: Reduce the maximum protection check impact"
added to boot in the busybox.
3) Cover remaning memory addressing syscalls.
Testing:
1) Chaitanya v2 selftests [2].
2) Busybox boot.
The whole series can be found here [3].
[1]: https://git.morello-project.org/morello/kernel/linux/-/wikis/Morello-pure-c…
[2]: https://git.morello-project.org/chaitanya_prakash/linux.git review/mmap_testcase
[3]: https://git.morello-project.org/amitdaniel/linux.git review/purecap_mm_reservation_v1
Thanksm,
Amit Daniel
Amit Daniel Kachhap (19):
uapi: errno.h: Introduce PCuABI memory reservation error
mm: Add capability reservation interfaces for PCuABI
lib/cap_addr_mgmt: Add capability bound helpers for PCuABI
mm/(mmap, mremap): Add flags to ignore reservation in unmap functions
mm/mmap: Use the PCuABI reservations in mmap/munmap
mm/(mmap, munmap): Limit reservation for only syscalls
mm/mremap: Add the PCuABI reservation interfaces
mm/mprotect: Add the PCuABI reservation interfaces
mm/madvise: Add the PCuABI reservation interfaces
mm/mlock: Add the PCuABI reservation interfaces
mm/mincore: Add the PCuABI reservation interfaces
mm/msync: Add the PCuABI reservation interfaces
uapi: mman-common.h: Helpers for maximum capability permissions
lib/cap_addr_mgmt: Add capability permission helpers for PCuABI
lib/cap_addr_mgmt: Reduce the maximum protection check impact
mm/mmap: Disable MAP_GROWSDOWN mapping flag for PCuABI
mm/mmap: Add capability permission constraints for PCuABI
mm/mremap: Add capability permission constraints for PCuABI
mm/mprotect: Add capability permission constraints for PCuABI
arch/arm64/include/asm/cap_addr_mgmt.h | 22 +++
fs/aio.c | 2 +-
include/linux/cap_addr_mgmt.h | 167 +++++++++++++++++
include/linux/cheri.h | 3 +
include/linux/mm.h | 20 +-
include/linux/mm_types.h | 3 +
include/uapi/asm-generic/errno.h | 2 +
include/uapi/asm-generic/mman-common.h | 6 +
io_uring/advise.c | 2 +-
ipc/shm.c | 2 +-
kernel/fork.c | 8 +
lib/Makefile | 1 +
lib/cap_addr_mgmt.c | 250 +++++++++++++++++++++++++
mm/damon/vaddr.c | 2 +-
mm/internal.h | 4 +-
mm/madvise.c | 27 ++-
mm/mincore.c | 18 +-
mm/mlock.c | 37 +++-
mm/mmap.c | 134 +++++++++++--
mm/mprotect.c | 22 ++-
mm/mremap.c | 117 ++++++++++--
mm/msync.c | 17 +-
mm/nommu.c | 2 +-
mm/util.c | 16 +-
24 files changed, 808 insertions(+), 76 deletions(-)
create mode 100644 arch/arm64/include/asm/cap_addr_mgmt.h
create mode 100644 include/linux/cap_addr_mgmt.h
create mode 100644 lib/cap_addr_mgmt.c
--
2.25.1
Hi All,
I am glad to inform you on the availability of a new version of our SDK and
base rootfs images for Morello (1.6.1). After months of hard work we are happy
to share with you what we put together.
Honoring our motto "Let Linux developers focus on the porting of their own
application", we feel that this is another steps in the right direction.
[Morello SDK]
In less than 10 minutes you should be able to setup a docker container with
everything you need to build an application for Morello.
- Documentation: https://sdk.morello-project.org/
- Code repository: https://git.morello-project.org/morello/morello-sdk
New in 1.6.1:
- Dynamic linking support for llvm/musl.
- Experimental C++ support for llvm/musl.
- Initial version of GCC/GLibC (with static linking).
If you want to try a demo of the SDK that runs on a Morello FVP (for more
information on what is an FVP: www.morello-project.org) please have a look below:
[Morello Linux]
In less than 10 minutes you should be able to setup a docker container with
everything you need to build and boot into a Morello Debian environment.
- Documentation: https://linux.morello-project.org/
- Code repository: https://git.morello-project.org/morello/morello-linux
Note: The documentation covers the instructions for Linux but if you know what
you are doing and are familiar with docker no one stops you from running our
solution on Windows or Mac.
New in 1.6.1:
- New kernel based on Linux 6.4.
- Graphic environment support with 3D acceleration (compat mode only).
- Shared folders support on FVP to simplify development.
Note: This release does not include a new version of the Android environment.
Further Android releases are now deprecated. Ongoing releases will focus on
the Morello Linux Environment.
Are we done with it?
No, by any mean. This is just the beginning and we need your help and
collaboration to make sure that we improve our solution to meet developers
needs: your needs!
So why don't you try it and let us know your thoughts?
Thanks and Regards,
Vincenzo
Hi,
The top of the master branch has been tagged [1] as part of the
integration drop 1.6.1.
Below is the changelog for kernel users, since the previous integration
drop (1.6).
PCuABI-related changes
----------------------
An important milestone has been reached regarding the support for the
pure-capability kernel-user ABI (PCuABI). So far, our efforts have been
focused on functional support for the ABI, and we have reached a
satisfactory level of compliance. We are now progressively shifting
towards the security aspects of the ABI, in other words checking
capabilities provided by userspace and narrowing the bounds and
permissions of those provided to userspace, as per the PCuABI
specification [2]. A few aspects have now been implemented, see the last
two items below.
* The io_uring and AIO subsystems have been modified to operate on full
capabilities in PCuABI. See the PCuABI specification [3] for further
details concerning io_uring (update for AIO coming soon).
* The futex_waitv syscall has been modified to read full capabilities in
PCuABI. Updated struct definitions are available in the PCuABI
specification [4] (in addition to the relevant uapi headers).
* The bounds of all user capabilities have been narrowed to the user
address space (48-bit by default), in both PCuABI and the standard
AArch64 ABI.
* Capabilities passed to the futex syscall are now checked for validity
by directly using them to access memory.
Other changes
-------------
* All CHERI/Morelo-related documentation can now be found under
Documentation/cheri [5] (or linked from there).
* Support for kernel modules has been enabled.
* The following drivers have been enabled in
morello_transitional_pcuabi_defconfig: NFS (including NFS rootfs),
TUN, TAP, CoreSight.
* The Morello kselftests can now be built with GCC.
* The branch has been rebased on the 6.4 upstream release. No
Morello-related user-visible change is expected, see this email [6]
for details.
Bug fixes
---------
* The fcntl syscall used to treat its optional third argument as a
64-bit integer, where the command expects an integer, instead of the
documented 32-bit. In certain cases, it also assumed that the upper 32
bits are zeroes. This cannot be guaranteed in general, especially not
in the Morello purecap variadic PCS. fnctl now always treats an
integer argument as 32-bit. This issue has also been fixed
upstream [7].
* In a standard AArch64 process (compat64), a stale SP value could be
set when delivering two signal consecutively. Additionally, if the
interrupted context was running in Restricted, the signal was
incorrectly delivered on the Restricted stack (instead of Executive).
Both of these issues have been fixed.
Contributions
-------------
Kudos to everyone who has contributed to Morello Linux! Here are the
contributors and number of patches since the previous integration drop:
28 Kevin Brodsky <kevin.brodsky(a)arm.com>
20 Tudor Cretu <tudor.cretu(a)arm.com>
13 Amit Daniel Kachhap <amit.kachhap(a)arm.com>
11 Luca Vizzarro <Luca.Vizzarro(a)arm.com>
3 Pawel Zalewski <pzalewski(a)thegoodpenguin.co.uk>
2 Harrison Marcks <hmarcks(a)thegoodpenguin.co.uk>
2 Kristina Martsenko <kristina.martsenko(a)arm.com>
2 Vincenzo Frascino <vincenzo.frascino(a)arm.com>
1 Harry Ramsey <harry.ramsey(a)arm.com>
Special thanks are also extended to everyone who has assisted in
reviewing these patches.
Cheers,
Kevin
[1]
https://git.morello-project.org/morello/kernel/linux/-/commits/morello-rele…
[2]
https://git.morello-project.org/morello/kernel/linux/-/wikis/Morello-pure-c…
[3]
https://git.morello-project.org/morello/kernel/linux/-/wikis/Morello-pure-c…
[4]
https://git.morello-project.org/morello/kernel/linux/-/wikis/Morello-pure-c…
[5]
https://git.morello-project.org/morello/kernel/linux/-/tree/morello-release…
[6]
https://op-lists.linaro.org/archives/list/linux-morello@op-lists.linaro.org…
[7]
https://lore.kernel.org/linux-fsdevel/20230414152459.816046-1-Luca.Vizzarro…