Skip to content

Commit

Permalink
ARM: 9357/2: Reduce the number of #ifdef CONFIG_CPU_SW_DOMAIN_PAN
Browse files Browse the repository at this point in the history
This is a clean-up patch aimed at reducing the number of checks on
CONFIG_CPU_SW_DOMAIN_PAN, together with some empty lines for better
clarity once the CONFIG_CPU_TTBR0_PAN is introduced.

Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Tested-by: Florian Fainelli <florian.fainelli@broadcom.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
  • Loading branch information
Linus Walleij authored and Russell King (Oracle) committed Apr 18, 2024
1 parent 66abdd3 commit de7f60f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
16 changes: 12 additions & 4 deletions arch/arm/include/asm/uaccess-asm.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@
#endif
.endm

.macro uaccess_disable, tmp, isb=1
#ifdef CONFIG_CPU_SW_DOMAIN_PAN

.macro uaccess_disable, tmp, isb=1
/*
* Whenever we re-enter userspace, the domains should always be
* set appropriately.
Expand All @@ -50,11 +51,9 @@
.if \isb
instr_sync
.endif
#endif
.endm

.macro uaccess_enable, tmp, isb=1
#ifdef CONFIG_CPU_SW_DOMAIN_PAN
/*
* Whenever we re-enter userspace, the domains should always be
* set appropriately.
Expand All @@ -64,9 +63,18 @@
.if \isb
instr_sync
.endif
#endif
.endm

#else

.macro uaccess_disable, tmp, isb=1
.endm

.macro uaccess_enable, tmp, isb=1
.endm

#endif

#if defined(CONFIG_CPU_SW_DOMAIN_PAN) || defined(CONFIG_CPU_USE_DOMAINS)
#define DACR(x...) x
#else
Expand Down
21 changes: 15 additions & 6 deletions arch/arm/include/asm/uaccess.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,38 @@
* perform such accesses (eg, via list poison values) which could then
* be exploited for priviledge escalation.
*/
#ifdef CONFIG_CPU_SW_DOMAIN_PAN

static __always_inline unsigned int uaccess_save_and_enable(void)
{
#ifdef CONFIG_CPU_SW_DOMAIN_PAN
unsigned int old_domain = get_domain();

/* Set the current domain access to permit user accesses */
set_domain((old_domain & ~domain_mask(DOMAIN_USER)) |
domain_val(DOMAIN_USER, DOMAIN_CLIENT));

return old_domain;
#else
return 0;
#endif
}

static __always_inline void uaccess_restore(unsigned int flags)
{
#ifdef CONFIG_CPU_SW_DOMAIN_PAN
/* Restore the user access mask */
set_domain(flags);
#endif
}

#else

static inline unsigned int uaccess_save_and_enable(void)
{
return 0;
}

static inline void uaccess_restore(unsigned int flags)
{
}

#endif

/*
* These two are intentionally not defined anywhere - if the kernel
* code generates any references to them, that's a bug.
Expand Down

0 comments on commit de7f60f

Please sign in to comment.