RE: [PATCH 05/15] x86: Implement function_nocfi

2021-04-19 Thread David Laight
From: Rasmus Villemoes > Sent: 19 April 2021 09:40 > > On 17/04/2021 00.28, Kees Cook wrote: > > On Fri, Apr 16, 2021 at 03:06:17PM -0700, Andy Lutomirski wrote: > > >> The > >> foo symbol would point to whatever magic is needed. > > > > No, the symbol points to the jump table entry. Direct

Re: [PATCH 05/15] x86: Implement function_nocfi

2021-04-19 Thread Andy Lutomirski
> On Apr 19, 2021, at 8:26 AM, David Laight wrote: > > From: Andy Lutomirski >> Sent: 18 April 2021 01:12 > .. >> Slightly more complicated: >> >> struct opaque_symbol; >> extern struct opaque_symbol entry_SYSCALL_64; >> >> The opaque_symbol variant avoids any possible confusion over the

Re: [PATCH 05/15] x86: Implement function_nocfi

2021-04-19 Thread Joao Moreira
Why not? In particular, I'd really like somebody to answer the question "why not just store a cookie before each address-taken or external-linkage function?". FWIIW, this was done before (at least twice): First with grsecurity/PaX RAP (https://grsecurity.net/rap_faq) then with kCFI

RE: [PATCH 05/15] x86: Implement function_nocfi

2021-04-19 Thread David Laight
From: Andy Lutomirski > Sent: 18 April 2021 01:12 .. > Slightly more complicated: > > struct opaque_symbol; > extern struct opaque_symbol entry_SYSCALL_64; > > The opaque_symbol variant avoids any possible confusion over the weird > status of arrays in C, and it's hard to misuse, since struct >

Re: [PATCH 05/15] x86: Implement function_nocfi

2021-04-19 Thread Sami Tolvanen
On Sun, Apr 18, 2021 at 3:57 PM Andy Lutomirski wrote: > > On Sun, Apr 18, 2021 at 9:17 AM Thomas Gleixner wrote: > > > > On Sat, Apr 17 2021 at 17:11, Andy Lutomirski wrote: > > > On Sat, Apr 17, 2021 at 4:53 PM Thomas Gleixner > > > wrote: > > >> which works for > > >> > > >> foo =

Re: [PATCH 05/15] x86: Implement function_nocfi

2021-04-19 Thread Sami Tolvanen
On Sat, Apr 17, 2021 at 3:16 AM Thomas Gleixner wrote: > > On Sat, Apr 17 2021 at 01:02, Thomas Gleixner wrote: > > On Fri, Apr 16 2021 at 15:37, Kees Cook wrote: > > > >> On Fri, Apr 16, 2021 at 03:20:17PM -0700, Andy Lutomirski wrote: > >>> But obviously there is code that needs real function

Re: [PATCH 05/15] x86: Implement function_nocfi

2021-04-19 Thread Rasmus Villemoes
On 17/04/2021 00.28, Kees Cook wrote: > On Fri, Apr 16, 2021 at 03:06:17PM -0700, Andy Lutomirski wrote: >> The >> foo symbol would point to whatever magic is needed. > > No, the symbol points to the jump table entry. Direct calls get minimal > overhead and indirect calls can add the "is this

Re: [PATCH 05/15] x86: Implement function_nocfi

2021-04-18 Thread Andy Lutomirski
On Sun, Apr 18, 2021 at 9:17 AM Thomas Gleixner wrote: > > On Sat, Apr 17 2021 at 17:11, Andy Lutomirski wrote: > > On Sat, Apr 17, 2021 at 4:53 PM Thomas Gleixner wrote: > >> which works for > >> > >> foo = function_nocfi(bar); > > > > I agree in general. But right now, we have, in

Re: [PATCH 05/15] x86: Implement function_nocfi

2021-04-18 Thread Thomas Gleixner
On Sat, Apr 17 2021 at 17:11, Andy Lutomirski wrote: > On Sat, Apr 17, 2021 at 4:53 PM Thomas Gleixner wrote: >> which works for >> >> foo = function_nocfi(bar); > > I agree in general. But right now, we have, in asm/proto.h: > > void entry_SYSCALL_64(void); > > and that's pure nonsense.

Re: [PATCH 05/15] x86: Implement function_nocfi

2021-04-17 Thread Andy Lutomirski
On Sat, Apr 17, 2021 at 4:53 PM Thomas Gleixner wrote: > > On Sat, Apr 17 2021 at 16:19, Andy Lutomirski wrote: > > On Fri, Apr 16, 2021 at 4:40 PM Kees Cook wrote: > >> Okay, you're saying you want __builtin_gimme_body_p() to be a constant > >> expression for the compiler, not inline asm? > > >

Re: [PATCH 05/15] x86: Implement function_nocfi

2021-04-17 Thread Thomas Gleixner
On Sat, Apr 17 2021 at 16:19, Andy Lutomirski wrote: > On Fri, Apr 16, 2021 at 4:40 PM Kees Cook wrote: >> Okay, you're saying you want __builtin_gimme_body_p() to be a constant >> expression for the compiler, not inline asm? > > Yes. > > I admit that, in the trivial case where the asm code is

Re: [PATCH 05/15] x86: Implement function_nocfi

2021-04-17 Thread Andy Lutomirski
On Fri, Apr 16, 2021 at 4:40 PM Kees Cook wrote: > > > 1. I defined a function in asm. I want to tell clang that this > > function is defined in asm, and for clang to behave accordingly: > > > > .globl func > > func: > > ; do stuff > > > > later: > > > > extern void func(void) [something

Re: [PATCH 05/15] x86: Implement function_nocfi

2021-04-17 Thread Andy Lutomirski
> On Apr 17, 2021, at 7:20 AM, David Laight wrote: > > From: Kees Cook >> Sent: 16 April 2021 23:28 >> >>> On Fri, Apr 16, 2021 at 03:06:17PM -0700, Andy Lutomirski wrote: >>> On Fri, Apr 16, 2021 at 3:03 PM Borislav Petkov wrote: On Fri, Apr 16, 2021 at 02:49:23PM -0700, Sami

RE: [PATCH 05/15] x86: Implement function_nocfi

2021-04-17 Thread David Laight
From: Kees Cook > Sent: 16 April 2021 23:28 > > On Fri, Apr 16, 2021 at 03:06:17PM -0700, Andy Lutomirski wrote: > > On Fri, Apr 16, 2021 at 3:03 PM Borislav Petkov wrote: > > > > > > On Fri, Apr 16, 2021 at 02:49:23PM -0700, Sami Tolvanen wrote: > > > > __nocfi only disables CFI checking in a

Re: [PATCH 05/15] x86: Implement function_nocfi

2021-04-17 Thread Thomas Gleixner
On Sat, Apr 17 2021 at 01:02, Thomas Gleixner wrote: > On Fri, Apr 16 2021 at 15:37, Kees Cook wrote: > >> On Fri, Apr 16, 2021 at 03:20:17PM -0700, Andy Lutomirski wrote: >>> But obviously there is code that needs real function pointers. How >>> about making this a first-class feature, or at

Re: [PATCH 05/15] x86: Implement function_nocfi

2021-04-16 Thread Kees Cook
On Fri, Apr 16, 2021 at 03:52:44PM -0700, Andy Lutomirski wrote: > Maybe ABI is the wrong word, or maybe I'm not fully clued in. But, if I do: > > extern void call_it(void (*ptr)(void)); > > and I define call_it in one translation unit and call it from another, > the ABI effectively changed,

Re: [PATCH 05/15] x86: Implement function_nocfi

2021-04-16 Thread Thomas Gleixner
On Fri, Apr 16 2021 at 15:37, Kees Cook wrote: > On Fri, Apr 16, 2021 at 03:20:17PM -0700, Andy Lutomirski wrote: >> But obviously there is code that needs real function pointers. How >> about making this a first-class feature, or at least hacking around it >> more cleanly. For example, what

Re: [PATCH 05/15] x86: Implement function_nocfi

2021-04-16 Thread Kees Cook
On Fri, Apr 16, 2021 at 03:52:44PM -0700, Andy Lutomirski wrote: > > > char entry_whatever[]; > > > wrmsrl(..., (unsigned long)entry_whatever); > > > > This is just casting. It'll still resolve to the jump table entry. > > How? As far as clang is concerned, entry_whatever isn't a function at >

Re: [PATCH 05/15] x86: Implement function_nocfi

2021-04-16 Thread Andy Lutomirski
On Fri, Apr 16, 2021 at 3:28 PM Kees Cook wrote: > > On Fri, Apr 16, 2021 at 03:06:17PM -0700, Andy Lutomirski wrote: > > On Fri, Apr 16, 2021 at 3:03 PM Borislav Petkov wrote: > > > > > > On Fri, Apr 16, 2021 at 02:49:23PM -0700, Sami Tolvanen wrote: > > > > __nocfi only disables CFI checking

Re: [PATCH 05/15] x86: Implement function_nocfi

2021-04-16 Thread Kees Cook
On Fri, Apr 16, 2021 at 03:20:17PM -0700, Andy Lutomirski wrote: > But obviously there is code that needs real function pointers. How > about making this a first-class feature, or at least hacking around it > more cleanly. For example, what does this do: > > char entry_whatever[]; > wrmsrl(...,

Re: [PATCH 05/15] x86: Implement function_nocfi

2021-04-16 Thread Kees Cook
On Fri, Apr 16, 2021 at 03:06:17PM -0700, Andy Lutomirski wrote: > On Fri, Apr 16, 2021 at 3:03 PM Borislav Petkov wrote: > > > > On Fri, Apr 16, 2021 at 02:49:23PM -0700, Sami Tolvanen wrote: > > > __nocfi only disables CFI checking in a function, the compiler still > > > changes function

Re: [PATCH 05/15] x86: Implement function_nocfi

2021-04-16 Thread Andy Lutomirski
On Fri, Apr 16, 2021 at 3:14 PM Borislav Petkov wrote: > > On Fri, Apr 16, 2021 at 03:06:17PM -0700, Andy Lutomirski wrote: > > On Fri, Apr 16, 2021 at 3:03 PM Borislav Petkov wrote: > > > > > > On Fri, Apr 16, 2021 at 02:49:23PM -0700, Sami Tolvanen wrote: > > > > __nocfi only disables CFI

Re: [PATCH 05/15] x86: Implement function_nocfi

2021-04-16 Thread Kees Cook
On Sat, Apr 17, 2021 at 12:02:51AM +0200, Borislav Petkov wrote: > On Fri, Apr 16, 2021 at 02:49:23PM -0700, Sami Tolvanen wrote: > > __nocfi only disables CFI checking in a function, the compiler still > > changes function addresses to point to the CFI jump table, which is > > why we need

Re: [PATCH 05/15] x86: Implement function_nocfi

2021-04-16 Thread Borislav Petkov
On Fri, Apr 16, 2021 at 03:06:17PM -0700, Andy Lutomirski wrote: > On Fri, Apr 16, 2021 at 3:03 PM Borislav Petkov wrote: > > > > On Fri, Apr 16, 2021 at 02:49:23PM -0700, Sami Tolvanen wrote: > > > __nocfi only disables CFI checking in a function, the compiler still > > > changes function

Re: [PATCH 05/15] x86: Implement function_nocfi

2021-04-16 Thread Thomas Gleixner
On Fri, Apr 16 2021 at 14:49, Sami Tolvanen wrote: > On Fri, Apr 16, 2021 at 2:18 PM Borislav Petkov wrote: >> In file included from ./include/linux/ftrace.h:22:0, >> from ./include/linux/init_task.h:9, >> from init/init_task.c:2: >> ./include/linux/ftrace.h: In

Re: [PATCH 05/15] x86: Implement function_nocfi

2021-04-16 Thread Andy Lutomirski
On Fri, Apr 16, 2021 at 3:03 PM Borislav Petkov wrote: > > On Fri, Apr 16, 2021 at 02:49:23PM -0700, Sami Tolvanen wrote: > > __nocfi only disables CFI checking in a function, the compiler still > > changes function addresses to point to the CFI jump table, which is > > why we need

Re: [PATCH 05/15] x86: Implement function_nocfi

2021-04-16 Thread Borislav Petkov
On Fri, Apr 16, 2021 at 02:49:23PM -0700, Sami Tolvanen wrote: > __nocfi only disables CFI checking in a function, the compiler still > changes function addresses to point to the CFI jump table, which is > why we need function_nocfi(). So call it __func_addr() or get_function_addr() or so, so

Re: [PATCH 05/15] x86: Implement function_nocfi

2021-04-16 Thread Sami Tolvanen
On Fri, Apr 16, 2021 at 2:18 PM Borislav Petkov wrote: > > On Fri, Apr 16, 2021 at 01:38:34PM -0700, Sami Tolvanen wrote: > > With CONFIG_CFI_CLANG, the compiler replaces function addresses in > > instrumented C code with jump table addresses. This change implements > > the function_nocfi()

Re: [PATCH 05/15] x86: Implement function_nocfi

2021-04-16 Thread Borislav Petkov
On Fri, Apr 16, 2021 at 01:38:34PM -0700, Sami Tolvanen wrote: > With CONFIG_CFI_CLANG, the compiler replaces function addresses in > instrumented C code with jump table addresses. This change implements > the function_nocfi() macro, which returns the actual function address > instead. > >

[PATCH 05/15] x86: Implement function_nocfi

2021-04-16 Thread Sami Tolvanen
With CONFIG_CFI_CLANG, the compiler replaces function addresses in instrumented C code with jump table addresses. This change implements the function_nocfi() macro, which returns the actual function address instead. Signed-off-by: Sami Tolvanen --- arch/x86/include/asm/page.h | 14