lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210804171749.GA5563@pswork>
Date:   Wed, 4 Aug 2021 19:17:49 +0200
From:   Padmanabha Srinivasaiah <treasure4paddy@...il.com>
To:     Sami Tolvanen <samitolvanen@...gle.com>
Cc:     Jessica Yu <jeyu@...nel.org>, Kees Cook <keescook@...omium.org>,
        Nathan Chancellor <nathan@...nel.org>,
        Nick Desaulniers <ndesaulniers@...gle.com>,
        Miroslav Benes <mbenes@...e.cz>,
        Stephen Boyd <swboyd@...omium.org>,
        "Gustavo A. R. Silva" <gustavoars@...nel.org>,
        Joe Perches <joe@...ches.com>,
        LKML <linux-kernel@...r.kernel.org>,
        clang-built-linux <clang-built-linux@...glegroups.com>
Subject: Re: [PATCH v3] kallsyms: strip CLANG CFI postfix ".cfi_jt"

On Tue, Aug 03, 2021 at 09:28:23AM -0700, Sami Tolvanen wrote:
> Hi,
> 
> On Thu, Jul 29, 2021 at 1:54 PM Padmanabha Srinivasaiah
> <treasure4paddy@...il.com> wrote:
> >
> > Clang CFI adds a postfix ".cfi_jt" to a symbols of extern functions.
> > For example this breaks syscall tracer that doesn't expect such postfix,
> > so strip out the postfix from the expanded symbol.
> >
> > Signed-off-by: Padmanabha Srinivasaiah <treasure4paddy@...il.com>
> > ---
> >
> > Change in v3:
> >   - Modified commit message to indicate fix is for Clang CFI postfix
> >   - Rebased on recent patch from ndesaulniers@...gle.com.
> >   - Fix is enabled even for CONFIG_LTO_CLANG
> >
> > Change in v2:
> >   - Use existing routine in kallsyms to strip postfix ".cfi_jt" from
> >     extern function name.
> >   - Modified the commit message accordingly
> >
> >  kernel/kallsyms.c | 21 +++++++++++++++------
> >  1 file changed, 15 insertions(+), 6 deletions(-)
> >
> > diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
> > index 5cabe4dd3ff4..67d015854cbd 100644
> > --- a/kernel/kallsyms.c
> > +++ b/kernel/kallsyms.c
> > @@ -174,7 +174,8 @@ static bool cleanup_symbol_name(char *s)
> >          * foo.llvm.974640843467629774. This can break hooking of static
> >          * functions with kprobes.
> >          */
> > -       if (!IS_ENABLED(CONFIG_LTO_CLANG_THIN))
> > +       if (!(IS_ENABLED(CONFIG_LTO_CLANG) ||
> > +             IS_ENABLED(CONFIG_LTO_CLANG_THIN)))
> 
> This is redundant. LTO_CLANG is selected for both LTO modes, so
> there's no need to also check for LTO_CLANG_THIN here.
>

As my setup is little endian, couldn't verify for below condition and 
was the reason to add such check. Sure will remove it.

       " select ARCH_SUPPORTS_LTO_CLANG if CPU_LITTLE_ENDIAN
	 select ARCH_SUPPORTS_LTO_CLANG_THIN"

> >                 return false;
> >
> >         res = strstr(s, ".llvm.");
> 
> However, we should probably check for ".llvm." only with LTO_CLANG_THIN.
>

Thank you for the input, will regenrate the patch with suggested check

> > @@ -184,16 +185,24 @@ static bool cleanup_symbol_name(char *s)
> >         }
> >
> >         /*
> > -        * LLVM appends a hash to static function names when ThinLTO and CFI
> > -        * are both enabled, i.e. foo() becomes
> > -        * foo$707af9a22804d33c81801f27dcfe489b. This causes confusion and
> > -        * potentially breaks user space tools, so we strip the suffix from
> > -        * expanded symbol names.
> > +        * LLVM appends a hash to static function names when both
> > +        * (Thin/FULL) LTO and CFI are enabled, i.e. foo() becomes
> > +        * foo$707af9a22804d33c81801f27dcfe489b.
> 
> That's not quite right, the hash is only appended with ThinLTO. I
> would leave this comment untouched.
>

sure, will revert it.

> > +        *
> > +        * In case of non static function symbol <funcsym>,
> > +        * the local jump table will have entry as <funcsym>.cfi_jt.
> > +        *
> > +        * This causes confusion and potentially breaks
> > +        * user space tools and some built-in components.
> > +        * So we strip the suffix from expanded symbol names.
> >          */
> >         if (!IS_ENABLED(CONFIG_CFI_CLANG))
> >                 return false;
> >
> >         res = strrchr(s, '$');
> > +       if (!res)
> > +               res = strstr(s, ".cfi_jt");
> 
> And add a comment about stripping .cfi_jt from jump table symbols
> before this part.
>

sure, will add it

> > +
> >         if (res) {
> >                 *res = '\0';
> >                 return true;
> > --
> > 2.17.1
> >
> 
> Sami

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ