2022-04-27 09:41:59

by Kees Cook

[permalink] [raw]
Subject: [PATCH] lkdtm: cfi: Fix type width for masking PAC bits

The masking for PAC bits wasn't handling 32-bit architectures correctly.
Replace the u64 cast with uintptr_t.

Reported-by: kernel test robot <[email protected]>
Reported-by: Geert Uytterhoeven <[email protected]>
Link: https://lore.kernel.org/lkml/[email protected]om
Fixes: 2e53b877dc12 ("lkdtm: Add CFI_BACKWARD to test ROP mitigations")
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Signed-off-by: Kees Cook <[email protected]>
---
drivers/misc/lkdtm/cfi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/misc/lkdtm/cfi.c b/drivers/misc/lkdtm/cfi.c
index 804965a480b7..666a7f4bc137 100644
--- a/drivers/misc/lkdtm/cfi.c
+++ b/drivers/misc/lkdtm/cfi.c
@@ -59,7 +59,7 @@ static void lkdtm_CFI_FORWARD_PROTO(void)
#endif

#define no_pac_addr(addr) \
- ((__force __typeof__(addr))((__force u64)(addr) | PAGE_OFFSET))
+ ((__force __typeof__(addr))((uintptr_t)(addr) | PAGE_OFFSET))

/* The ultimate ROP gadget. */
static noinline __no_ret_protection
--
2.32.0


2022-04-27 09:46:22

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH] lkdtm: cfi: Fix type width for masking PAC bits

Hi Kees,

On Wed, Apr 27, 2022 at 2:12 AM Kees Cook <[email protected]> wrote:
> The masking for PAC bits wasn't handling 32-bit architectures correctly.
> Replace the u64 cast with uintptr_t.
>
> Reported-by: kernel test robot <[email protected]>
> Reported-by: Geert Uytterhoeven <[email protected]>
> Link: https://lore.kernel.org/lkml/[email protected]om
> Fixes: 2e53b877dc12 ("lkdtm: Add CFI_BACKWARD to test ROP mitigations")
> Cc: Greg Kroah-Hartman <[email protected]>
> Cc: Arnd Bergmann <[email protected]>
> Signed-off-by: Kees Cook <[email protected]>

Thank you, that fixes the m68k allmodconfig build, so
Tested-by: Geert Uytterhoeven <[email protected]>

> --- a/drivers/misc/lkdtm/cfi.c
> +++ b/drivers/misc/lkdtm/cfi.c
> @@ -59,7 +59,7 @@ static void lkdtm_CFI_FORWARD_PROTO(void)
> #endif
>
> #define no_pac_addr(addr) \
> - ((__force __typeof__(addr))((__force u64)(addr) | PAGE_OFFSET))
> + ((__force __typeof__(addr))((uintptr_t)(addr) | PAGE_OFFSET))

Not related to this patch, but "| PAGE_OFFSET" is not identical
to "+ PAGE_OFFSET" for large kernel sizes.

More specifically, I'm thinking about platforms where "large" would
be >= 32 MiB:
arch/mips/include/asm/mach-ar7/spaces.h:#define PAGE_OFFSET
_AC(0x94000000, UL)
or >= 128 MiB:
arch/x86/Kconfig: default 0x78000000 if VMSPLIT_2G_OPT

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

2022-04-28 08:19:08

by Randy Dunlap

[permalink] [raw]
Subject: Re: [PATCH] lkdtm: cfi: Fix type width for masking PAC bits



On 4/26/22 17:12, Kees Cook wrote:
> The masking for PAC bits wasn't handling 32-bit architectures correctly.
> Replace the u64 cast with uintptr_t.
>
> Reported-by: kernel test robot <[email protected]>
> Reported-by: Geert Uytterhoeven <[email protected]>
> Link: https://lore.kernel.org/lkml/[email protected]om
> Fixes: 2e53b877dc12 ("lkdtm: Add CFI_BACKWARD to test ROP mitigations")
> Cc: Greg Kroah-Hartman <[email protected]>
> Cc: Arnd Bergmann <[email protected]>
> Signed-off-by: Kees Cook <[email protected]>

Tested-by: Randy Dunlap <[email protected]>
fwiw
Thanks.

> ---
> drivers/misc/lkdtm/cfi.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/misc/lkdtm/cfi.c b/drivers/misc/lkdtm/cfi.c
> index 804965a480b7..666a7f4bc137 100644
> --- a/drivers/misc/lkdtm/cfi.c
> +++ b/drivers/misc/lkdtm/cfi.c
> @@ -59,7 +59,7 @@ static void lkdtm_CFI_FORWARD_PROTO(void)
> #endif
>
> #define no_pac_addr(addr) \
> - ((__force __typeof__(addr))((__force u64)(addr) | PAGE_OFFSET))
> + ((__force __typeof__(addr))((uintptr_t)(addr) | PAGE_OFFSET))
>
> /* The ultimate ROP gadget. */
> static noinline __no_ret_protection

--
~Randy