Retrict the permisions of the CHERI specific auxv members as defined in the PCuABI specification.
Signed-off-by: Teo Couprie Diaz teo.coupriediaz@arm.com --- This is not complete by any mean and could be used as a starting point. This does work for restricting the permissions but I couldn't manage to restrict the bounds in a similar fashion.
fs/binfmt_elf.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 1d82465cb9e9..96b4e1794c6c 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -308,21 +308,29 @@ create_elf_tables(struct linux_binprm *bprm, const struct elfhdr *exec, } #if defined(CONFIG_CHERI_PURECAP_UABI) && (ELF_COMPAT == 0) /* - * TODO [PCuABI] - Restrict bounds/perms for AT_CHERI_* entries + * TODO [PCuABI] - Restrict bounds for AT_CHERI_* entries */ NEW_AUX_ENT(AT_CHERI_EXEC_RW_CAP, (exec_load_info->start_elf_rw != ~0UL ? - elf_uaddr_to_user_ptr(exec_load_info->start_elf_rw) : + cheri_perms_and(elf_uaddr_to_user_ptr(exec_load_info->start_elf_rw), + (CHERI_PERMS_ROOTCAP | CHERI_PERMS_READ | CHERI_PERMS_WRITE | + ARM_CAP_PERMISSION_BRANCH_SEALED_PAIR)) : NULL)); NEW_AUX_ENT(AT_CHERI_EXEC_RX_CAP, - elf_uaddr_to_user_ptr(exec_load_info->start_elf_rx)); + cheri_perms_and(elf_uaddr_to_user_ptr(exec_load_info->start_elf_rx), + (CHERI_PERMS_ROOTCAP | CHERI_PERMS_READ | CHERI_PERMS_EXEC | + ARM_CAP_PERMISSION_BRANCH_SEALED_PAIR))); NEW_AUX_ENT(AT_CHERI_INTERP_RW_CAP, ((interp_load_addr && interp_load_info->start_elf_rw != ~0UL) ? - elf_uaddr_to_user_ptr(interp_load_info->start_elf_rw) : + cheri_perms_and(elf_uaddr_to_user_ptr(interp_load_info->start_elf_rw), + (CHERI_PERMS_ROOTCAP | CHERI_PERMS_READ | CHERI_PERMS_WRITE | + ARM_CAP_PERMISSION_BRANCH_SEALED_PAIR)) : NULL)); NEW_AUX_ENT(AT_CHERI_INTERP_RX_CAP, (interp_load_addr ? - elf_uaddr_to_user_ptr(interp_load_info->start_elf_rx) : + cheri_perms_and(elf_uaddr_to_user_ptr(interp_load_info->start_elf_rx), + (CHERI_PERMS_ROOTCAP | CHERI_PERMS_READ | CHERI_PERMS_EXEC | + ARM_CAP_PERMISSION_BRANCH_SEALED_PAIR)) : NULL)); NEW_AUX_ENT(AT_CHERI_STACK_CAP, elf_uaddr_to_user_ptr(0)); NEW_AUX_ENT(AT_CHERI_SEAL_CAP, cheri_user_root_seal_cap);