Hi,
This series switches all uaccess routines to operate directly on the
user-provided capability pointer in PCuABI, instead of making the access
via the extracted 64-bit address. This means that all forms of uaccess
now enforce the capability metadata, through the use of capability-based
loads and stores, and will fail with -EFAULT following a failed
(hardware) capability check. The impacted routines are:
- *get_user* (including get_user_ptr)
- *put_user* (including put_user_ptr)
- *copy_from_user* (including copy_from_user_with_ptr)
- *copy_to_user* (including copy_to_user_with_ptr)
(Note that futex operations are already checked thanks to Luca's work [1].)
Enabling capability checks in uaccess exposed a variety of issues, both
in the kernel and in userspace. This series addresses the fallout in the
kernel before making the switch:
- Patch 1-3 overhaul strnlen_user() to prevent it from reading
beyond the bounds of the user pointer, while leaving its
implementation unchanged in !PCuABI.
- Patch 4-6 fixes various capability propagation issues (surprisingly
few of those!).
- Patch 7 fixes a bug in a Morello kselftest, detected through
capability checking in copy_from_user().
Finally, the switch to capability-based accesses is made:
- Patch 8-10 switch {get,put}_user and variants.
- Patch 11-12 switch copy_{from,to}_user and variants.
After this series, the Morello kselftests and Musl tests still pass, and
so do the liburing tests, however the LTP syscalls suite doesn't because
of various issues in LTP itself. I have addressed a number of them
upstream [2] (series already merged), and will post the remaining fixes
to linux-morello-ltp.
Because this precise uaccess checking cannot be achieved with most
existing sanitisers or hardware memory safety mechanisms, further bugs
are likely to be identified in low-level libraries and test suites
running in purecap (I have spotted a couple in the Bionic tests).
Issue:
https://git.morello-project.org/morello/kernel/linux/-/issues/5
Review branch:
https://git.morello-project.org/kbrodsky-arm/linux/-/commits/morello/checke…
Cheers,
Kevin
[1] https://op-lists.linaro.org/archives/list/linux-morello@op-lists.linaro.org…
[2] https://lore.kernel.org/ltp/20231023135647.2157030-1-kevin.brodsky@arm.com/
Kevin Brodsky (12):
linux/user_ptr.h: Introduce user_ptr_{base,limit}
lib: Refactor do_strnlen_user()
lib: Make strnlen_user() PCuABI-friendly
block: Eliminate invalid user pointer casts
tty: Convert another ioctl helper to take arg as user_uintptr_t
seccomp: Preserve pointers when reading sock_fprog from userspace
kselftests/arm64: morello: Fix message size in mmap test
arm64: morello: Implement user capability accessors inline
arm64: uaccess: Move macros from futex.h to uaccess.h
arm64: uaccess: Switch to capability-based {get,put}_user in PCuABI
arm64: lib: Simplify copy_*_user register allocation
arm64: lib: Switch to capability-based copy_*_user in PCuABI
Documentation/core-api/user_ptr.rst | 13 ++
arch/arm64/include/asm/assembler.h | 8 +
arch/arm64/include/asm/futex.h | 20 +--
arch/arm64/include/asm/gpr-num.h | 6 +-
arch/arm64/include/asm/morello.h | 4 -
arch/arm64/include/asm/uaccess.h | 49 +++++-
arch/arm64/lib/copy_from_user.S | 33 +++-
arch/arm64/lib/copy_template.S | 14 +-
arch/arm64/lib/copy_to_user.S | 17 +-
arch/arm64/lib/morello.S | 23 ---
block/blk-zoned.c | 6 +-
block/ioctl.c | 22 +--
drivers/tty/tty_ioctl.c | 2 +-
include/linux/blkdev.h | 8 +-
include/linux/tty.h | 2 +-
include/linux/user_ptr.h | 44 +++++
kernel/seccomp.c | 2 +-
lib/strnlen_user.c | 163 +++++++++++++++----
tools/testing/selftests/arm64/morello/mmap.c | 2 +-
19 files changed, 319 insertions(+), 119 deletions(-)
--
2.38.1
Hi All,
This patch series introduces the mm reservation interface to manage
the owning capability of the allocated addresses. As compared to the RFC
v1, this series adds reservation details in the VMA structure. Looking for
feedback regarding interface names, interface directory structure etc.
Patch [1-11] manages capability bounds via reservation interface. Patch [12-19]
adds support for managing capability permissions.
Details about several rules implemented can be found in PCuABI spec here [1].
Changes in RFC v2:
1) Removed separate maple tree structures for the reservation interface
and modified the vma structure to add the reservation details. As most of
the mmap/munmap operations happen per-vma so this reduced the code
churnings. However this approach will increase time-complexity of syscalls
which operate across vma's such as mlock, madvise etc. get_unmapped_area()
which generated free unmapped virtual address may now need more iterations.
2) Added Cheri base representability and length representability
modifications. Now get_unmapped_area() will generate CHERI
representable addresses.
3) Added new PCuABI changes for mincore() syscall.
4) Added changes for compat64.
Future works:
1) Users of vm_mmap/vm_munmap() i.e. filesystems, loaders, kexec etc to be
modified to preserve capability addresses.
2) Cover remaining memory addressing syscalls.
Testing:
1) All tests by Chaitanya in v4 selftests [2] passes.
2) Purecap/Compat Busybox boot passes after adding [WIP] patches present in [3].
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/purecap_mmap_testcases
[3]: https://git.morello-project.org/amitdaniel/linux.git review/purecap_mm_reservation_v2
Thanks,
Amit Daniel
Amit Daniel Kachhap (19):
uapi: errno.h: Introduce PCuABI memory reservation error
arm64: morello: Add VM_PCUABI_RESERVE flags
mm: Add capability reservation interfaces in vma for PCuABI
mm/cap_addr_mgmt: Add capability bound helpers for PCuABI
mm/mmap: Modify unmapped address space management code for PCuABI
mm/mmap: Use the PCuABI reservations in mmap/munmap
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/msync: Add the PCuABI reservation interfaces
uapi: mman-common.h: Macros for maximum capability permissions
mm/cap_addr_mgmt: Add capability permission helpers for PCuABI
mm/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
mm/mincore: Add capability constraints for PCuABI
arch/arm64/include/asm/cap_addr_mgmt.h | 22 ++
include/linux/cap_addr_mgmt.h | 168 +++++++++++++
include/linux/cheri.h | 3 +
include/linux/mm.h | 29 ++-
include/linux/mm_types.h | 5 +
include/uapi/asm-generic/errno.h | 2 +
include/uapi/asm-generic/mman-common.h | 6 +
io_uring/advise.c | 2 +-
mm/Makefile | 2 +-
mm/cap_addr_mgmt.c | 314 +++++++++++++++++++++++++
mm/damon/vaddr.c | 2 +-
mm/madvise.c | 27 ++-
mm/mincore.c | 46 +++-
mm/mlock.c | 38 ++-
mm/mmap.c | 182 ++++++++++++--
mm/mprotect.c | 21 +-
mm/mremap.c | 109 +++++++--
mm/msync.c | 15 +-
mm/util.c | 10 +-
19 files changed, 919 insertions(+), 84 deletions(-)
create mode 100644 arch/arm64/include/asm/cap_addr_mgmt.h
create mode 100644 include/linux/cap_addr_mgmt.h
create mode 100644 mm/cap_addr_mgmt.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 check
the capability's tag, bounds, range as well as permissions have been
added. 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.
The mincore() tests are expected to fail in this iteration as they are
not fully supported. The next iterations will contain representability
testcases.
Review branch:
https://git.morello-project.org/chaitanya_prakash/linux/-/tree/review/purec…
This patch series has been tested on:
https://git.morello-project.org/amitdaniel/linux/-/tree/review/purecap_mm_r…
[1] https://git.morello-project.org/morello/kernel/linux/-/wikis/Morello-pure-c…
Changes in V4:
- Corrected subject of cover letter
Changes in V3:
https://op-lists.linaro.org/archives/list/linux-morello@op-lists.linaro.org…
- Added get_pagesize() function and VERRIFY_ERRNO() macro
- Added LoadCap and StoreCap permissions testcase
- Added validity_tag_check testcases
- Added reservation tests
- Renamed variable "addr" to "ptr" to avoid confusion when manipulating
both addresses and capabilities
- Cleaned up syscall_mmap and syscall_mmap2 testcases
- Restructured code into testcases that check tags, range, bounds
and permissions
- Improved range_check testcases
- Improved commit messages
- Removed helper functions, tests directly written in testcase functions
- Removed signal handling and ddc register testcases
Changes in V2:
https://op-lists.linaro.org/archives/list/linux-morello@op-lists.linaro.org…
- 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 (11):
kselftests/arm64: morello: Create wrapper functions for frequently
invoked syscalls
kselftests/arm64: morello: Add get_pagesize() function
kselftests/arm64: morello: Add VERIFY_ERRNO() macro
kselftests/arm64: morello: mmap: Clean up existing testcases
kselftests/arm64: morello: mmap: Add MAP_GROWSDOWN testcase
kselftests/arm64: morello: mmap: Add validity tag check testcases
kselftests/arm64: morello: mmap: Add capability range testcases
kselftests/arm64: morello: mmap: Add mmap() bounds check testcases
kselftests/arm64: morello: mmap: Add mremap() bounds check testcases
kselftests/arm64: morello: mmap: Add permission check testcases
kselftests/arm64: morello: mmap: Add brk() testcase
.../selftests/arm64/morello/bootstrap.c | 13 -
.../selftests/arm64/morello/freestanding.c | 16 +-
.../selftests/arm64/morello/freestanding.h | 74 ++-
tools/testing/selftests/arm64/morello/mmap.c | 547 +++++++++++++++++-
4 files changed, 606 insertions(+), 44 deletions(-)
--
2.25.1
Hi,
Here's v4 of the bpf syscall patches, following on from the RFC[1],
v1[2], v2[3] and v3[4].
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 (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 further nested/multiplexed options.
Another 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. To retain compatibility with the aarch64 ABI and add
Morello support, special compat64 conversion and handling is
implemented.
Inbound (userspace->kernel) conversion between compat64/native struct
layouts is handled upfront on entry to the syscall (with the exception
of bpf_xyz_info structs). 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[5]. It enables BPF_PROG_TYPE_TRACEPOINT which many eBPF
kselftests use.
Patches 5,6,8 implement the core compat64 handling. Each commit compiles
cleanly but relevant parts will be broken inbetween.
Patch 9 fixes the CHECK_ATTR macro to also check configs passed in via
compat64.
Patch 11 finally enables capabilities in the kernel.
Patches 12,13 handles uaccess that occurs in two eBPF helper functions.
The rest are setup/helper functions.
Testing wise, see associated LTP changes below as posted to LTP mailing
list[6]. The eBPF LTP tests are fairly minimal and test only a small
part of the changes here. There's a new test to test CHECK_ATTR from
patch 9.
The kernel kselftests contain many more extensive eBPF tests. They can
be built fairly easily natively on aarch64 which is useful for testing
compat64. More work needs to be done here though to:
a) enable out-of-tree cross-compilation for purecap as well as
x86->aarch64
b) replace ptr_to_u64() with casts to uintptr_t in tests
c) general libbpf/bpftool enablement and fixes since many tests rely
on this
d) 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 would be 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_v4
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 00/10] update bpf syscall for PCuABI/compat64
https://op-lists.linaro.org/archives/list/linux-morello@op-lists.linaro.org…
[3] [PATCH v2 00/12] update bpf syscall for PCuABI/compat64
https://op-lists.linaro.org/archives/list/linux-morello@op-lists.linaro.org…
[4] [PATCH v3 00/12] update bpf syscall for PCuABI/compat64
https://op-lists.linaro.org/archives/list/linux-morello@op-lists.linaro.org…
[5] [PATCH v3 0/5] Restore syscall tracing on Morello
https://op-lists.linaro.org/archives/list/linux-morello@op-lists.linaro.org…
[6] [PATCH 0/3] add eBPF support
https://op-lists.linaro.org/archives/list/linux-morello-ltp@op-lists.linaro…
-----------------------------------------------------------------------
v4:
- Return EFAULT in bpf_{prog,link}_get_info_by_fd, not err
- Fix multiline comment formatting
- Reduce number of in_compat_syscall() in copy_bpf_attr_from_user() + copy_bpf_{btf,prog,link}_from_user()
- copy_bpf_{btf,prog,link}_to_user() remains the same but s/target_info/src_info
- bpf_copy_from_user_with_ptr() helper removed
v3:
- Renamed all {is,in}_32bit_... to compat32, e.g. is_32bit_compat_task
-> is_compat32 task, same for 64bit versions
- Removed dispatch_bpf() + bpf_check_perms() and merged back into
__sys_bpf - they no longer need to be split now we have no separate
compat64 handler
- Ensured we memset(0)/zero initialise all compat/non-compat structs for
bpf_attr, bpf_{prog,link,btf}_info as appropriate when copying in/out
from userspace
- Switched order of first two arguments of bpf_put_uattr() to align with
bpfptr_put_uattr() and more closely match put_user()
- Moved #include <linux/bpf_compat.h> into bpf.h
- Moved bpf_copy_{to,from}_user_with_ptr to bpf.h
- Renamed bpf_uattr_compat_ptr macro to bpf_compat_ptr_field
- Removed const arguments for bpf_copy_from_user(_task) helpers
- Fixed pointer type mismatch warnings in void *ptr =
in_compat64_syscall() ? type1 : type2; pattern
- Replace temporary #define bpfptr_copy with in_compat64_syscall
conditional in bpfptr.h:copy_from_bpfptr_with_ptr - only use _with_ptr
in purecap
v2:
- Fixed copy_from_bpfptr_offset_with_ptr - this no longer uses sockptr
as of 6.1 (see patch 9)
- Rebase on 6.4 - new struct members need conversion/handling:
- New BPF_PROG_TYPE_NETFILTER + associated bpf_attr BPF_LINK_CREATE
members
- New bpf_link_info types BPF_LINK_TYPE_NETFILTER +
BPF_LINK_TYPE_STRUCT_OPS
- Renamed in_32bit_compat_syscall() to in_compat32_syscall() and added
in_compat64_syscall()
- Handled uaccess from bpf helper programs
bpf/helpers.c:bpf_copy_from_user + bpf_copy_from_user_task
- Added new stddef.h macro copy_field() to simplify conversion
assignments
- bpf: compat64: add handler and convert bpf_attr in
- Replaced #ifdef CONFIG_COMPAT64 with in_compat64_syscall() + use
copy_bpf_attr_from_user() helper function for inbound compat
conversion
- This removes the __sys_compat_bpf compat64 handler, now using the
existing __sys_bpf + in_compat64_syscall() for reduced diff size,
less duplication and clearer code
- Conversion now happens in copy_bpf_attr_from_user() for better
encapsulation + stack usage
- bpf: compat64: bpf_attr convert out
- Renamed PUT_USER_ATTR() to bpf_put_uattr() + moved to bpf.h
- Introduced bpfptr_put_uattr() in bpfptr.h
- Originally missed handling cases writing out to userspace with
copy_to_bpfptr_offset() - now replaced with new bpfptr_put_uattr()
macro
- 6.4 now has a new field showing what log size will be needed - see
47a71c1f9af0 ("bpf: Add log_true_size output field to return
necessary log buffer size")
- This also requires new macro bpf_field_exists() to handle compat64
when checking that userspace supports this new field
- bpf: compat64: handle bpf_xyz_info
- Simplified bpf_link_info conversion handling using memcpy
- Removed bpf_map_info patch since struct is the same in
compat64/native (no ptrs)
- Replaced #ifdef CONFIG_COMPAT64 with in_compat64_syscall() + use
copy_bpf_xyz_info_{from,to}_user() helper functions for compat
conversions
- Merged bpf_{btf,prog,link}_info into a single patch
- bpf: use user pointer types in uAPI structs
- Added new compat_uptr_to_kern() macro to simplify casting/converting
in compat ptrs
- Usage of copy_{to,from}_user_with_ptr variants now correctly applied
with new helpers
-----------------------------------------------------------------------
Zachary Leaf (13):
arm64: morello: enable syscall tracing
arch: rename 32bit_compat to compat32
arch: add compat helpers specific to 64-bit
stddef: introduce copy_field helper
bpf: compat64: add handler and convert bpf_attr in
bpf: compat64: bpf_attr convert out
bpf/btf: move zero check into btf.c
bpf: compat64: handle bpf_{btf,prog,link}_info
bpf: compat64: support CHECK_ATTR macro
bpf: copy_{to,from}_user_with_ptr helpers
bpf: use user pointer types in uAPI structs
bpf: use addr for bpf_copy_from_user_with_task
bpf: use addr for bpf_copy_from_user
.../morello_transitional_pcuabi_defconfig | 2 +-
arch/arm64/include/asm/compat.h | 11 +-
arch/arm64/include/asm/ftrace.h | 2 +-
arch/arm64/include/asm/mmu_context.h | 2 +-
arch/arm64/include/asm/syscall.h | 6 +-
arch/arm64/kernel/fpsimd.c | 6 +-
arch/arm64/kernel/hw_breakpoint.c | 2 +-
arch/arm64/kernel/perf_regs.c | 2 +-
arch/arm64/kernel/pointer_auth.c | 6 +-
arch/arm64/kernel/process.c | 16 +-
arch/arm64/kernel/ptrace.c | 10 +-
arch/arm64/kernel/signal.c | 2 +-
arch/arm64/kernel/syscall.c | 2 +-
arch/mips/include/asm/compat.h | 2 +-
arch/parisc/include/asm/compat.h | 2 +-
arch/powerpc/include/asm/compat.h | 2 +-
arch/s390/include/asm/compat.h | 2 +-
arch/sparc/include/asm/compat.h | 4 +-
arch/x86/include/asm/compat.h | 2 +-
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 2 +-
drivers/gpu/drm/amd/amdkfd/kfd_process.c | 2 +-
drivers/input/input.c | 2 +-
drivers/media/rc/bpf-lirc.c | 6 +-
fs/ext4/dir.c | 2 +-
fs/nfs/dir.c | 2 +-
include/linux/bpf.h | 18 +
include/linux/bpf_compat.h | 415 +++++++++
include/linux/bpfptr.h | 28 +-
include/linux/compat.h | 16 +-
include/linux/stddef.h | 3 +
include/uapi/linux/bpf.h | 94 +-
kernel/bpf/bpf_iter.c | 2 +-
kernel/bpf/btf.c | 104 ++-
kernel/bpf/cgroup.c | 9 +-
kernel/bpf/hashtab.c | 12 +-
kernel/bpf/helpers.c | 9 +-
kernel/bpf/net_namespace.c | 6 +-
kernel/bpf/offload.c | 2 +-
kernel/bpf/syscall.c | 865 ++++++++++++++----
kernel/bpf/verifier.c | 20 +-
kernel/time/time.c | 2 +-
kernel/trace/bpf_trace.c | 6 +-
mm/util.c | 2 +-
net/bpf/bpf_dummy_struct_ops.c | 8 +-
net/bpf/test_run.c | 31 +-
net/core/sock_map.c | 6 +-
46 files changed, 1415 insertions(+), 342 deletions(-)
create mode 100644 include/linux/bpf_compat.h
--
2.34.1
Hello all,
Here is the v3 of the patch adding capability support for argv and envp
strings.
This has mostly refinement and fixes compared to v2.
This time around the one thing I am unsure of is the *_put_user* part in
fs/binfmt_elf.c:put_str_ptr().
I tried using the same code for both paths in PC-uABI, but there was a mismatch
in expected pointer/capabilities, so I resorted to keeping a section in
#if (ELF_COMPAT == 0) .
I must be missing something, so open to suggestions.
Happy to take suggestions for any names as well, especially with a new function
and a change in behavior in another.
Thanks in advance for your comments,
Best regards
Téo
# Changes from v2-v3[0]
- Commit message clarified
- Fixed some typing and use issues
- Updated the stack alignment to use a define depending on the build type
- Changed the put_str_array function to only put one string pointer,
the looping over all strings is restored to be handled in create_elf_tables.
- Moved the padding calculations to a separate function that returns the
updated value of bprm->p rather than the padding.
- Reduced the amount of code not shared between purecap/compat
- Removed nonsensical check before alignment computation
# Changes from v1-v2[1]
- Rebased on top of the last release
- Update to make use of the properly derived stack capability in binfmt_elf
- Move the copying of argv and envp strings in binfmt_elf to a helper function
- Check for padding after an arg only
- Greatly simplify the change in exec by completely skipping the padding,
rather than looping through it and allocating pages in exec
- Add more details to the comments explaining the padding process
- Rename most variables. I'm not great with names so hopefully they are OK,
otherwise feel free to suggest new ones !
- Proper COMPAT handling, but with a slight loss compared to a regular kernel
- Detail trade-off in comments and in commit message
- Force a greater stack alignment in exec to mitigate issues during relocation
- Simplify accesses and use `get_user()` rather than `copy_from_user()`
- Use wrappers provided by <cheriintrin.h> rather than builtins
- Get rid of the elf_stack_put_user_cap macro
Gitlab patch for review :
https://git.morello-project.org/Teo-CD/linux/-/commit/b92f2f777a327b9e49fea…
[0]: https://op-lists.linaro.org/archives/list/linux-morello@op-lists.linaro.org…
[1]: https://op-lists.linaro.org/archives/list/linux-morello@op-lists.linaro.org…
Teo Couprie Diaz (1):
fs: Handle exact bounds for argv and envp
fs/binfmt_elf.c | 101 +++++++++++++++++++++++++++++++++++++++++-------
fs/exec.c | 58 +++++++++++++++++++++++++--
2 files changed, 142 insertions(+), 17 deletions(-)
--
2.34.1
Hi everyone,
This patch aims to enable purecap applications to make use of the MMC block
driver by adding PCuABI support to the MMC_IOC_CMD and MMC_IOC_MULTI_CMD
ioctls. This also includes compat64 support for the ioctls.
V4 -> V5: Improvement to readability and fix to user-space macro.
V3 -> V4: Minor corrections and improvements to readability of code.
- Remove unnecessary explicit checks on capabilities.
- Revert modification to struct mmc_ioc_multi_cmd.
- Remove unnecessary parentheses.
V2 -> V3:
- Implement support for capabilities in the ioctls.
- Correct formatting errors in patches.
- Correct formatting and syntax errors in code.
V1 -> V2: Various improvements to the code including:
- Preference for native structs over (void __user *)
- Complying with code styling guidelines
- Improvement in code readability via removing unnecessary casts
GitLab Issue:
https://git.morello-project.org/morello/kernel/linux/-/issues/51
Review branch:
https://git.morello-project.org/arkamnite/linux/-/commits/morello%2Fmmc_v5
Many thanks,
Akram
Akram Ahmad (2):
mmc: Implement compat handling for struct mmc_ioc_{multi_}cmd
mmc: Support capabilities in MMC_IOC_{MULTI_}CMD ioctls
drivers/mmc/core/block.c | 100 ++++++++++++++++++++++++++++++---
include/uapi/linux/mmc/ioctl.h | 7 ++-
2 files changed, 97 insertions(+), 10 deletions(-)
--
2.34.1
Hi everyone,
This patch aims to enable purecap applications to make use of the MMC block
driver by adding PCuABI support to the MMC_IOC_CMD and MMC_IOC_MULTI_CMD
ioctls. This also includes compat64 support for the ioctls.
V3 -> V4: Minor corrections and improvements to readability of code.
- Remove unnecessary explicit checks on capabilities.
- Revert modification to struct mmc_ioc_multi_cmd.
- Remove unnecessary parentheses.
V2 -> V3:
- Implement support for capabilities in the ioctls.
- Correct formatting errors in patches.
- Correct formatting and syntax errors in code.
V1 -> V2: Various improvements to the code including:
- Preference for native structs over (void __user *)
- Complying with code styling guidelines
- Improvement in code readability via removing unnecessary casts
GitLab Issue:
https://git.morello-project.org/morello/kernel/linux/-/issues/51
Review branch:
https://git.morello-project.org/arkamnite/linux/-/commits/morello%2Fmmc_v4
Many thanks,
Akram
Akram Ahmad (2):
mmc: Implement compat handling for struct mmc_ioc_{multi_}cmd
mmc: Support capabilities in MMC_IOC_{MULTI_}CMD ioctls
drivers/mmc/core/block.c | 100 ++++++++++++++++++++++++++++++---
include/uapi/linux/mmc/ioctl.h | 2 +-
2 files changed, 93 insertions(+), 9 deletions(-)
--
2.34.1
Hi,
Here's v3 of the bpf syscall patches, following on from the RFC[1],
v1[2] and v2[3].
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 (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. To retain compatibility with the aarch64 ABI and add
Morello support, special compat64 conversion and handling is
implemented.
Inbound (userspace->kernel) conversion between compat64/native struct
layouts is handled upfront on entry to the syscall (with the exception
of bpf_xyz_info structs). 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[4]. It enables BPF_PROG_TYPE_TRACEPOINT which many eBPF
kselftests use.
Patches 5,6,8 implement the core compat64 handling. Each commit compiles
cleanly but relevant parts will be broken inbetween.
Patch 9 fixes the CHECK_ATTR macro to also check configs passed in via
compat64.
Patch 11 finally enables capabilities in the kernel.
Patches 12,13 handles uaccess that occurs in two eBPF helper functions.
The rest are setup/helper functions.
Testing wise, see associated LTP changes below as posted to LTP mailing
list[5]. The eBPF LTP tests are fairly minimal and test only a small
part of the changes here. There's a new test to test CHECK_ATTR from
patch 9.
The kernel kselftests contain many more extensive eBPF tests. They can
be built fairly easily natively on aarch64 which is useful for testing
compat64. More work needs to be done here though to:
a) enable out-of-tree cross-compilation for purecap as well as
x86->aarch64
b) replace ptr_to_u64() with casts to uintptr_t in tests
c) general libbpf/bpftool enablement and fixes since many tests rely
on this
d) 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 would be 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_v3
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 00/10] update bpf syscall for PCuABI/compat64
https://op-lists.linaro.org/archives/list/linux-morello@op-lists.linaro.org…
[3] [PATCH v2 00/12] update bpf syscall for PCuABI/compat64
https://op-lists.linaro.org/archives/list/linux-morello@op-lists.linaro.org…
[4] [PATCH v3 0/5] Restore syscall tracing on Morello
https://op-lists.linaro.org/archives/list/linux-morello@op-lists.linaro.org…
[5] [PATCH 0/3] add eBPF support
https://op-lists.linaro.org/archives/list/linux-morello-ltp@op-lists.linaro…
-----------------------------------------------------------------------
v3:
- Renamed all {is,in}_32bit_... to compat32, e.g. is_32bit_compat_task
-> is_compat32 task, same for 64bit versions
- Removed dispatch_bpf() + bpf_check_perms() and merged back into
__sys_bpf - they no longer need to be split now we have no separate
compat64 handler
- Ensured we memset(0)/zero initialise all compat/non-compat structs for
bpf_attr, bpf_{prog,link,btf}_info as appropriate when copying in/out
from userspace
- Switched order of first two arguments of bpf_put_uattr() to align with
bpfptr_put_uattr() and more closely match put_user()
- Moved #include <linux/bpf_compat.h> into bpf.h
- Moved bpf_copy_{to,from}_user_with_ptr to bpf.h
- Renamed bpf_uattr_compat_ptr macro to bpf_compat_ptr_field
- Removed const arguments for bpf_copy_from_user(_task) helpers
- Fixed pointer type mismatch warnings in void *ptr =
in_compat64_syscall() ? type1 : type2; pattern
- Replace temporary #define bpfptr_copy with in_compat64_syscall
conditional in bpfptr.h:copy_from_bpfptr_with_ptr - only use _with_ptr
in purecap
v2:
- Fixed copy_from_bpfptr_offset_with_ptr - this no longer uses sockptr
as of 6.1 (see patch 9)
- Rebase on 6.4 - new struct members need conversion/handling:
- New BPF_PROG_TYPE_NETFILTER + associated bpf_attr BPF_LINK_CREATE
members
- New bpf_link_info types BPF_LINK_TYPE_NETFILTER +
BPF_LINK_TYPE_STRUCT_OPS
- Renamed in_32bit_compat_syscall() to in_compat32_syscall() and added
in_compat64_syscall()
- Handled uaccess from bpf helper programs
bpf/helpers.c:bpf_copy_from_user + bpf_copy_from_user_task
- Added new stddef.h macro copy_field() to simplify conversion
assignments
- bpf: compat64: add handler and convert bpf_attr in
- Replaced #ifdef CONFIG_COMPAT64 with in_compat64_syscall() + use
copy_bpf_attr_from_user() helper function for inbound compat
conversion
- This removes the __sys_compat_bpf compat64 handler, now using the
existing __sys_bpf + in_compat64_syscall() for reduced diff size,
less duplication and clearer code
- Conversion now happens in copy_bpf_attr_from_user() for better
encapsulation + stack usage
- bpf: compat64: bpf_attr convert out
- Renamed PUT_USER_ATTR() to bpf_put_uattr() + moved to bpf.h
- Introduced bpfptr_put_uattr() in bpfptr.h
- Originally missed handling cases writing out to userspace with
copy_to_bpfptr_offset() - now replaced with new bpfptr_put_uattr()
macro
- 6.4 now has a new field showing what log size will be needed - see
47a71c1f9af0 ("bpf: Add log_true_size output field to return
necessary log buffer size")
- This also requires new macro bpf_field_exists() to handle compat64
when checking that userspace supports this new field
- bpf: compat64: handle bpf_xyz_info
- Simplified bpf_link_info conversion handling using memcpy
- Removed bpf_map_info patch since struct is the same in
compat64/native (no ptrs)
- Replaced #ifdef CONFIG_COMPAT64 with in_compat64_syscall() + use
copy_bpf_xyz_info_{from,to}_user() helper functions for compat
conversions
- Merged bpf_{btf,prog,link}_info into a single patch
- bpf: use user pointer types in uAPI structs
- Added new compat_uptr_to_kern() macro to simplify casting/converting
in compat ptrs
- Usage of copy_{to,from}_user_with_ptr variants now correctly applied
with new helpers
-----------------------------------------------------------------------
Zachary Leaf (13):
arm64: morello: enable syscall tracing
arch: rename to 32bit_compat to compat32
arch: add compat helpers specific to 64-bit
stddef: introduce copy_field helper
bpf: compat64: add handler and convert bpf_attr in
bpf: compat64: bpf_attr convert out
bpf/btf: move zero check into btf.c
bpf: compat64: handle bpf_{btf,prog,link}_info
bpf: compat64: support CHECK_ATTR macro
bpf: copy_{to,from}_user_with_ptr helpers
bpf: use user pointer types in uAPI structs
bpf: use addr for bpf_copy_from_user_with_task
bpf: use addr for bpf_copy_from_user
.../morello_transitional_pcuabi_defconfig | 2 +-
arch/arm64/include/asm/compat.h | 11 +-
arch/arm64/include/asm/ftrace.h | 2 +-
arch/arm64/include/asm/mmu_context.h | 2 +-
arch/arm64/include/asm/syscall.h | 6 +-
arch/arm64/kernel/fpsimd.c | 6 +-
arch/arm64/kernel/hw_breakpoint.c | 2 +-
arch/arm64/kernel/perf_regs.c | 2 +-
arch/arm64/kernel/pointer_auth.c | 6 +-
arch/arm64/kernel/process.c | 16 +-
arch/arm64/kernel/ptrace.c | 10 +-
arch/arm64/kernel/signal.c | 2 +-
arch/arm64/kernel/syscall.c | 2 +-
arch/mips/include/asm/compat.h | 2 +-
arch/parisc/include/asm/compat.h | 2 +-
arch/powerpc/include/asm/compat.h | 2 +-
arch/s390/include/asm/compat.h | 2 +-
arch/sparc/include/asm/compat.h | 4 +-
arch/x86/include/asm/compat.h | 2 +-
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 2 +-
drivers/gpu/drm/amd/amdkfd/kfd_process.c | 2 +-
drivers/input/input.c | 2 +-
drivers/media/rc/bpf-lirc.c | 6 +-
fs/ext4/dir.c | 2 +-
fs/nfs/dir.c | 2 +-
include/linux/bpf.h | 22 +
include/linux/bpf_compat.h | 415 +++++++++
include/linux/bpfptr.h | 30 +-
include/linux/compat.h | 16 +-
include/linux/stddef.h | 3 +
include/uapi/linux/bpf.h | 94 +-
kernel/bpf/bpf_iter.c | 2 +-
kernel/bpf/btf.c | 105 ++-
kernel/bpf/cgroup.c | 9 +-
kernel/bpf/hashtab.c | 12 +-
kernel/bpf/helpers.c | 9 +-
kernel/bpf/net_namespace.c | 6 +-
kernel/bpf/offload.c | 2 +-
kernel/bpf/syscall.c | 871 ++++++++++++++----
kernel/bpf/verifier.c | 20 +-
kernel/time/time.c | 2 +-
kernel/trace/bpf_trace.c | 6 +-
mm/util.c | 2 +-
net/bpf/bpf_dummy_struct_ops.c | 8 +-
net/bpf/test_run.c | 31 +-
net/core/sock_map.c | 6 +-
46 files changed, 1425 insertions(+), 345 deletions(-)
create mode 100644 include/linux/bpf_compat.h
--
2.34.1
Hello,
This patch series implements a pure-capability vDSO which purecap
userspace applications can directly use. It also fixes the vDSO
selftests so that they can be built as purecap binaries, therefore
allowing the new purecap vDSO to be tested. The existing aarch64 vDSO
implementation is unchanged - it has simply been redefined as the compat
vDSO. Therefore, processes using both the standard and purecap ABIs
will have a vDSO to use.
I have tested both vDSOs using the patched versions of the selftests.
I have tested the selftests by by feeding it broken vDSOs and seeing
ensuring they fail appropriately.
The first patch fixes the tests, the second patch builds the purecap
vDSO, and the third patch sets up the mapping for it and makes it
available for use. If you think the patches should be ordered
differently, and/or if we should possibly combine the building and mapping
patches into one vDSO implementation patch, please let me know.
Thanks,
Aditya
GitLab Issue:
- https://git.morello-project.org/morello/kernel/linux/-/issues/24
GitLab Review Branch:
- https://git.morello-project.org/aditya/linux/-/tree/purecap_vdso?ref_type=h…
Aditya Deshpande (3):
selftests/vDSO: Add support for purecap vDSO testing
arm64: vdso: Build a pure-capability vDSO
arm64: vDSO: Map the purecap vDSO into userspace application address
space
arch/arm64/Makefile | 6 +
arch/arm64/include/asm/elf.h | 16 ++-
arch/arm64/include/asm/vdso.h | 1 +
arch/arm64/include/asm/vdso/gettimeofday.h | 92 ++++++++++++++
arch/arm64/kernel/Makefile | 4 +-
arch/arm64/kernel/vdso-purecap-wrap.S | 22 ++++
arch/arm64/kernel/vdso-purecap/.gitignore | 2 +
arch/arm64/kernel/vdso-purecap/Makefile | 101 ++++++++++++++++
arch/arm64/kernel/vdso-purecap/note.S | 23 ++++
arch/arm64/kernel/vdso-purecap/sigreturn.S | 80 ++++++++++++
arch/arm64/kernel/vdso-purecap/vdso.lds.S | 114 ++++++++++++++++++
.../arm64/kernel/vdso-purecap/vgettimeofday.c | 25 ++++
arch/arm64/kernel/vdso.c | 58 ++++++++-
fs/compat_binfmt_elf.c | 16 +++
include/linux/compiler.h | 9 ++
include/linux/elf.h | 2 +-
include/linux/user_ptr.h | 1 +
tools/testing/selftests/vDSO/Makefile | 16 +--
tools/testing/selftests/vDSO/vdso_config.h | 11 ++
tools/testing/selftests/vDSO/vdso_test_abi.c | 4 +-
.../selftests/vDSO/vdso_test_gettimeofday.c | 6 +-
21 files changed, 587 insertions(+), 22 deletions(-)
create mode 100644 arch/arm64/kernel/vdso-purecap-wrap.S
create mode 100644 arch/arm64/kernel/vdso-purecap/.gitignore
create mode 100644 arch/arm64/kernel/vdso-purecap/Makefile
create mode 100644 arch/arm64/kernel/vdso-purecap/note.S
create mode 100644 arch/arm64/kernel/vdso-purecap/sigreturn.S
create mode 100644 arch/arm64/kernel/vdso-purecap/vdso.lds.S
create mode 100644 arch/arm64/kernel/vdso-purecap/vgettimeofday.c
--
2.25.1
This patch aims to enable purecap applications to make use of the MMC block
driver by adding PCuABI support to the MMC_IOC_CMD and MMC_IOC_MULTI_CMD
ioctls. This also includes compat64 support for the ioctls.
V2 -> V3:
- Implement support for capabilities in the ioctls.
- Correct formatting errors in patches.
- Correct formatting and syntax errors in code.
V1 -> V2: Various improvements to the code including:
- Preference for native structs over (void __user *)
- Complying with code styling guidelines
- Improvement in code readability via removing unnecessary casts
GitLab Issue:
https://git.morello-project.org/morello/kernel/linux/-/issues/51
Review branch:
https://git.morello-project.org/arkamnite/linux/-/commits/morello%2Fmmc_v3
Akram Ahmad (1):
mmc: Implement compat handling for struct mmc_ioc_{multi_}cmd
mmc: Support capabilities in MMC_IOC_{MULTI_}CMD ioctls
drivers/mmc/core/block.c | 108 ++++++++++++++++++++++++++++++---
include/uapi/linux/mmc/ioctl.h | 4 +-
2 files changed, 102 insertions(+), 10 deletions(-)
--
2.34.1