lkml.org 
[lkml]   [2020]   [Nov]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH] samples/ftrace: mark my_tramp[12]? global
On Mon, Nov 16, 2020 at 12:38 PM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> On Mon, 16 Nov 2020 12:10:10 -0800
> Sami Tolvanen <samitolvanen@google.com> wrote:
>
> > On Mon, Nov 16, 2020 at 8:39 AM Steven Rostedt <rostedt@goodmis.org> wrote:
> > >
> > > On Fri, 13 Nov 2020 10:34:14 -0800
> > > Sami Tolvanen <samitolvanen@google.com> wrote:
> > >
> > > > my_tramp[12]? are declared as global functions in C, but they are not
> > > > marked global in the inline assembly definition. This mismatch confuses
> > > > Clang's Control-Flow Integrity checking. Fix the definitions by adding
> > > > .globl.
> > > >
> > >
> > > Actually, since that function is not really global, would it work if you
> > > removed the "extern" from the my_tramp declaration?
> >
> > Unfortunately not, removing the "extern" doesn't seem to change anything.
> >
> > > In other words, is there a way to tell C that a function is declared in an
> > > inline assembly block?
> >
> > I'm not sure if there's a way to tell C that a static function is
> > declared in inline assembly. At least I couldn't find a way that would
> > make the compiler happy.
>
> I'm trying to see the warning. What option makes clang trigger a warning on
> this?

Clang doesn't warn about this as we're building a module, it just
generates a reference to a non-existing global "my_tramp" symbol,
because the one defined in inline assembly has a local binding:

$ readelf --symbols --wide ftrace-direct.lto.o | grep my_tramp
16: 0000000000000000 13 FUNC LOCAL DEFAULT 1 my_tramp
33: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND my_tramp
42: 0000000000000000 8 FUNC GLOBAL HIDDEN 8 my_tramp.cfi_jt

This would prevent the module from loading, which modpost catches:

ERROR: modpost: "my_tramp" [samples/ftrace/ftrace-direct.ko] undefined!

> From user space, I'm just using the following file:

As this error happens only with Control-Flow Integrity, we need to
take the address of the "test" function to force the compiler to
generate a jump table entry for it. Here's a slightly tweaked
stand-alone reproducer:

https://godbolt.org/z/GnzjE4

Sami

\
 
 \ /
  Last update: 2020-11-16 22:12    [W:0.053 / U:0.236 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site