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

From: Geert Uytterhoeven
Date: Wed Apr 27 2022 - 03:14:36 EST


Hi Kees,

On Wed, Apr 27, 2022 at 2:12 AM Kees Cook <keescook@xxxxxxxxxxxx> 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 <lkp@xxxxxxxxx>
> Reported-by: Geert Uytterhoeven <geert@xxxxxxxxxxxxxx>
> Link: https://lore.kernel.org/lkml/CAMuHMdVz-J-1ZQ08u0bsQihDkcRmEPrtX5B_oRJ+Ns5jrasnUw@xxxxxxxxxxxxxx
> Fixes: 2e53b877dc12 ("lkdtm: Add CFI_BACKWARD to test ROP mitigations")
> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
> Cc: Arnd Bergmann <arnd@xxxxxxxx>
> Signed-off-by: Kees Cook <keescook@xxxxxxxxxxxx>

Thank you, that fixes the m68k allmodconfig build, so
Tested-by: Geert Uytterhoeven <geert@xxxxxxxxxxxxxx>

> --- 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 -- geert@xxxxxxxxxxxxxx

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