linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nick Desaulniers <ndesaulniers@google.com>
To: Padmanabha Srinivasaiah <treasure4paddy@gmail.com>
Cc: jeyu@kernel.org, keescook@chromium.org, nathan@kernel.org,
	samitolvanen@google.com, Miroslav Benes <mbenes@suse.cz>,
	Stephen Boyd <swboyd@chromium.org>, Joe Perches <joe@perches.com>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com,
	Fangrui Song <maskray@google.com>
Subject: Re: [PATCH v5] kallsyms: strip CLANG CFI postfix ".cfi_jt"
Date: Fri, 1 Oct 2021 11:29:45 -0700	[thread overview]
Message-ID: <CAKwvOdmXtTE15mUb5x7Lq==emFwba7OGLfx9skayP-G9NqeiNQ@mail.gmail.com> (raw)
In-Reply-To: <20210814124224.8551-1-treasure4paddy@gmail.com>

On Sat, Aug 14, 2021 at 5:43 AM Padmanabha Srinivasaiah
<treasure4paddy@gmail.com> wrote:
>
> Clang CFI adds a postfix ".cfi_jt" to a symbols of extern functions.
> For e.g. this breaks syscall tracer that doesn't expect such postfix,
> so strip out the postfix from the expanded symbol.

$ llvm-nm vmlinux | grep -e 'T ' -e 't '
...
ffff800010cce56c t xhci_map_urb_for_dma
ffff800010cce56c t xhci_map_urb_for_dma.86d975cb70058c10e8ae4c2960627264
ffff800011227f28 t xhci_map_urb_for_dma.86d975cb70058c10e8ae4c2960627264.cfi_jt
...

so I think it's not just the `.cfi_jt` that we want to truncate.  Sami
asked me about sending a v5 for
https://lore.kernel.org/lkml/20210707181814.365496-1-ndesaulniers@google.com/;
I was looking to rebase your v5 on my patch, but Sami also noted that
here https://lore.kernel.org/lkml/CABCJKue5Ay6_+8sibzh5wRh3gPzV1g72gJ9m2ot4E1ezj8bpHA@mail.gmail.com/
that the separator was changed from $ to . for other CFI symbols in
clang-13.

So I think I'm going to "combine" our patches to truncate after the
first `.` as long as CONFIG_LTO_CLANG is enabled, but still check for
`$` for clang-12 for CONFIG_CFI_CLANG.  I will credit you with the
Suggested-by tag; stay tuned.

>
> Signed-off-by: Padmanabha Srinivasaiah <treasure4paddy@gmail.com>
> ---
> Change in v5:
>   - Also remove explcit config check for postfix ".llvm." as LLVM
>     renames even in full LTO case
>
> Change in v4:
>   - Remove redundant check; irrespective of LTO type (THIN/FULL),
>     LTO_CLANG will be always enabled. Hence will be used as entry flag
>     to check various postfix patterns.
>   - And prior to stripping postfix ".cfi_jt", added a comment to
>     justify why we are doing so.
>
> Change in v3:
>   - Modified commit message to indicate fix is for Clang CFI postfix
>   - Rebased on recent patch from ndesaulniers@google.com.
>     https://lore.kernel.org/lkml/
>         20210707181814.365496-1-ndesaulniers@google.com/#t
>   - 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 | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
> index 5cabe4dd3ff4..c8ef618e2a71 100644
> --- a/kernel/kallsyms.c
> +++ b/kernel/kallsyms.c
> @@ -174,7 +174,7 @@ 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))
>                 return false;
>
>         res = strstr(s, ".llvm.");
> @@ -194,6 +194,17 @@ static bool cleanup_symbol_name(char *s)
>                 return false;
>
>         res = strrchr(s, '$');
> +       if (!res) {
> +               /*
> +                * In case of non static function symbol <funcsym>,
> +                * the local jump table will have entry as <funcsym>.cfi_jt.
> +                *
> +                * Such expansion breaks some built-in components,
> +                * e.g. syscall tracer. Hence remove postfix ".cfi_jt".
> +                */
> +               res = strstr(s, ".cfi_jt");
> +       }
> +
>         if (res) {
>                 *res = '\0';
>                 return true;
> --
> 2.17.1
>


-- 
Thanks,
~Nick Desaulniers

      reply	other threads:[~2021-10-01 18:30 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 postfix ".cfi_jt" 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
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 [this message]

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='CAKwvOdmXtTE15mUb5x7Lq==emFwba7OGLfx9skayP-G9NqeiNQ@mail.gmail.com' \
    --to=ndesaulniers@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=maskray@google.com \
    --cc=mbenes@suse.cz \
    --cc=nathan@kernel.org \
    --cc=samitolvanen@google.com \
    --cc=swboyd@chromium.org \
    --cc=treasure4paddy@gmail.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).