linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sami Tolvanen <samitolvanen@google.com>
To: Padmanabha Srinivasaiah <treasure4paddy@gmail.com>
Cc: Jessica Yu <jeyu@kernel.org>, Kees Cook <keescook@chromium.org>,
	Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Miroslav Benes <mbenes@suse.cz>,
	Stephen Boyd <swboyd@chromium.org>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	Joe Perches <joe@perches.com>,
	LKML <linux-kernel@vger.kernel.org>,
	clang-built-linux <clang-built-linux@googlegroups.com>
Subject: Re: [PATCH v3] kallsyms: strip CLANG CFI postfix ".cfi_jt"
Date: Tue, 3 Aug 2021 09:28:23 -0700	[thread overview]
Message-ID: <CABCJKuei==gaaKw0qH1WkshcRyUbqdS_WGRWr6anYAew1HHT2w@mail.gmail.com> (raw)
In-Reply-To: <20210729205317.25685-1-treasure4paddy@gmail.com>

Hi,

On Thu, Jul 29, 2021 at 1:54 PM Padmanabha Srinivasaiah
<treasure4paddy@gmail.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@gmail.com>
> ---
>
> Change in v3:
>   - Modified commit message to indicate fix is for Clang CFI postfix
>   - Rebased on recent patch from ndesaulniers@google.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.

>                 return false;
>
>         res = strstr(s, ".llvm.");

However, we should probably check for ".llvm." only with LTO_CLANG_THIN.

> @@ -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.

> +        *
> +        * 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.

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

Sami

  reply	other threads:[~2021-08-03 16:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20210727131853.GA18032@pswork>
2021-07-27 14:06 ` [PATCH v2] kallsyms: strip ThinLTO " Padmanabha Srinivasaiah
2021-07-28 20:57   ` Sami Tolvanen
2021-07-29 15:29     ` Padmanabha Srinivasaiah
2021-07-29 20:53     ` [PATCH v3] kallsyms: strip CLANG CFI " Padmanabha Srinivasaiah
2021-08-03 16:28       ` Sami Tolvanen [this message]
2021-08-04 17:17         ` Padmanabha Srinivasaiah
2021-08-05 23:27         ` [PATCH v4] " Padmanabha Srinivasaiah
2021-08-12 23:05           ` Sami Tolvanen
2021-08-14 12:15             ` Padmanabha Srinivasaiah
2021-08-14 12:42             ` [PATCH v5] " Padmanabha Srinivasaiah
2021-10-01 18:29               ` Nick Desaulniers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CABCJKuei==gaaKw0qH1WkshcRyUbqdS_WGRWr6anYAew1HHT2w@mail.gmail.com' \
    --to=samitolvanen@google.com \
    --cc=clang-built-linux@googlegroups.com \
    --cc=gustavoars@kernel.org \
    --cc=jeyu@kernel.org \
    --cc=joe@perches.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mbenes@suse.cz \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=swboyd@chromium.org \
    --cc=treasure4paddy@gmail.com \
    --subject='Re: [PATCH v3] kallsyms: strip CLANG CFI postfix ".cfi_jt"' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).