kallsyms: strip ThinLTO postfix ".cfi_jt"
A message that is not in the archive (sent off-list or not yet received): 20210727131853.GA18032@pswork
PATCH v2 1/1 kallsyms: strip ThinLTO postfix ".cfi_jt"
Clang ThinLTO 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 output.
---
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 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
kernel/kallsyms.c +8 -4
@@ -166,16 +166,20 @@ static unsigned long kallsyms_sym_address(int idx)#if defined(CONFIG_CFI_CLANG ) && defined(CONFIG_LTO_CLANG_THIN )/* -* 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 and just ".cfi_jt" postfix +* for non-static functions when both ThinLTO and CFI are enabled, +* i.e. for example foo() becomes foo$707af9a22804d33c81801f27dcfe489b. +* This causes confusion and potentially breaks user space tools and +* built-in components, so we strip the suffix from expanded symbol names. */ static inline bool cleanup_symbol_name (char *s) {char *res; res =strrchr (s,'$' ); +if (!res) + res =strstr (s,".cfi_jt" ); +if (res) *res ='\0' ;
Signature · 1 line
2.17.1
Hi,
Quoted 2 lines · Padmanabha Srinivasaiah
Clang ThinLTO adds a postfix ".cfi_jt" to a symbols of extern functions.
These symbols are added with CONFIG_CFI_CLANG no matter which LTO mode is selected, so talking about ThinLTO here isn't quite correct.
Quoted 18 lines
For example this breaks syscall tracer that doesn't expect such postfix, so strip out the postfix from the output.
Signed-off-by Padmanabha Srinivasaiah <[email protected]>---
Change in v2:
- Use existing routine in kallsyms to strip postfix ".cfi_jt" from extern function name.
- Modified the commit message accordinglykernel/kallsyms.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)kernel/kallsyms.c +0
-0
kernel/kallsyms.c static unsigned long kallsyms_sym_address(int idx) · line 170
Quoted 9 lines
kernel/kallsyms.c +2
-4@@ -166,16 +166,20 @@ static unsigned long kallsyms_sym_address(int idx)#if defined(CONFIG_CFI_CLANG ) && defined(CONFIG_LTO_CLANG_THIN )/* -* 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 and just ".cfi_jt" postfix +* for non-static functions when both ThinLTO and CFI are enabled,
Functions aren't technically speaking renamed to add a .cfi_jt postfix. Instead, these are separate symbols that point to the CFI jump table. Perhaps the comment should just say that we want to strip .cfi_jt from CFI jump table symbols?
Quoted 4 lines
kernel/kallsyms.c +3
-0+* i.e. for example foo() becomes foo$707af9a22804d33c81801f27dcfe489b. +* This causes confusion and potentially breaks user space tools and +* built-in components, so we strip the suffix from expanded symbol names. */
kernel/kallsyms.c static unsigned long kallsyms_sym_address(int idx) · line 184
Quoted 10 lines
kernel/kallsyms.c +3
-0static inline bool cleanup_symbol_name (char *s) {char *res; res =strrchr (s,'$' ); +if (!res) + res =strstr (s,".cfi_jt" ); +if (res) *res ='\0' ;
This looks otherwise fine to me, but it's going to conflict with Nick's earlier patch:
https://lore.kernel.org/lkml/[email protected]/
Could you please rebase this on top of that, and take into account that we should do this when CONFIG_LTO_CLANG is enabled, not only with LTO_CLANG_THIN?
Sami
Quoted 10 lines · Sami Tolvanen
Hi,
Quoted 2 lines · Padmanabha Srinivasaiah
Clang ThinLTO adds a postfix ".cfi_jt" to a symbols of extern functions.
These symbols are added with
CONFIG_CFI_CLANGno matter which LTO mode is selected, so talking about ThinLTO here isn't quite correct.
Yes, checked irrespective of the LTO mode choosen ".cfi_jt" postfix is added with CONFIG_CFI_CLANG flag. Thanks for correcting out, will make neccessary changes.
Quoted 19 lines
Quoted 19 lines
For example this breaks syscall tracer that doesn't expect such postfix, so strip out the postfix from the output.
Signed-off-by Padmanabha Srinivasaiah <[email protected]>---
Change in v2:
- Use existing routine in kallsyms to strip postfix ".cfi_jt" from extern function name.
- Modified the commit message accordinglykernel/kallsyms.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)kernel/kallsyms.c +0
-0@@ -166,16 +166,20 @@ static unsigned long kallsyms_sym_address(int idx)
Quoted 14 lines
kernel/kallsyms.c static unsigned long kallsyms_sym_address(int idx) · line 170
Quoted 8 lines
kernel/kallsyms.c +2
-4#if defined(CONFIG_CFI_CLANG ) && defined(CONFIG_LTO_CLANG_THIN )/* -* 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 and just ".cfi_jt" postfix +* for non-static functions when both ThinLTO and CFI are enabled, Functions aren't technically speaking renamed to add a .cfi_jt postfix. Instead, these are separate symbols that point to the CFI jump table. Perhaps the comment should just say that we want to strip .cfi_jt from CFI jump table symbols?
Agree, in jest modified existing comment. Will address same.
Quoted 15 lines
Quoted 4 lines
kernel/kallsyms.c +3
-0+* i.e. for example foo() becomes foo$707af9a22804d33c81801f27dcfe489b. +* This causes confusion and potentially breaks user space tools and +* built-in components, so we strip the suffix from expanded symbol names. */ kernel/kallsyms.c static unsigned long kallsyms_sym_address(int idx) · line 184
Quoted 10 lines
kernel/kallsyms.c +3
-0static inline bool cleanup_symbol_name (char *s) {char *res; res =strrchr (s,'$' ); +if (!res) + res =strstr (s,".cfi_jt" ); +if (res) *res ='\0' ;
Quoted 9 lines
This looks otherwise fine to me, but it's going to conflict with Nick's earlier patch:
https://lore.kernel.org/lkml/[email protected]/
Could you please rebase this on top of that, and take into account that we should do this when
CONFIG_LTO_CLANGis enabled, not only withLTO_CLANG_THIN?
Thanks Sami for pointing out the link, will rebase and refactor the change.
Quoted 1 line
Sami
PATCH v3 1/1 kallsyms: strip CLANG CFI postfix ".cfi_jt"
In reply to Sami TolvanenClang 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.
---
Change in v3:
- Modified commit message to indicate fix is for Clang CFI postfix
- Rebased on recent patch from [email protected].
- 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(-)
kernel/kallsyms.c +15 -6
@@ -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 )))return false; res =strstr (s,".llvm." );
@@ -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. +* +* 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" ); +if (res) { *res ='\0' ;return true;
Signature · 1 line
2.17.1
Re: [PATCH v3] kallsyms: strip CLANG CFI postfix ".cfi_jt"
Hi,
Quoted 26 lines · Padmanabha Srinivasaiah
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 <[email protected]>---
Change in v3:
- Modified commit message to indicate fix is for Clang CFI postfix
- Rebased on recent patch from [email protected].
- Fix is enabled even forCONFIG_LTO_CLANGChange in v2:
- Use existing routine in kallsyms to strip postfix ".cfi_jt" from extern function name.
- Modified the commit message accordinglykernel/kallsyms.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)kernel/kallsyms.c +0
-0
kernel/kallsyms.c static bool cleanup_symbol_name(char *s) · line 178
Quoted 6 lines
kernel/kallsyms.c +2
-1@@ -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.
kernel/kallsyms.c static bool cleanup_symbol_name(char *s) · line 181
Quoted 3 lines
kernel/kallsyms.c +0
-0return false; res =strstr (s,".llvm." );
However, we should probably check for ".llvm." only with LTO_CLANG_THIN.
kernel/kallsyms.c static bool cleanup_symbol_name(char *s) · line 190
Quoted 12 lines
kernel/kallsyms.c +3
-5@@ -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.
Quoted 4 lines
kernel/kallsyms.c +4
-0+* +* In case of non static function symbol <funcsym>, +* the local jump table will have entry as <funcsym>.cfi_jt. +*
kernel/kallsyms.c static bool cleanup_symbol_name(char *s) · line 204
Quoted 10 lines
kernel/kallsyms.c +5
-0+* 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.
Quoted 7 lines
kernel/kallsyms.c +1
-1+if (res) { *res ='\0' ;return true; --2.17.1
Sami
Re: [PATCH v3] kallsyms: strip CLANG CFI postfix ".cfi_jt"
Quoted 25 lines · Sami Tolvanen
Hi,
Quoted 21 lines · Padmanabha Srinivasaiah
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 <[email protected]>---
Change in v3:
- Modified commit message to indicate fix is for Clang CFI postfix
- Rebased on recent patch from [email protected].
- Fix is enabled even forCONFIG_LTO_CLANGChange in v2:
- Use existing routine in kallsyms to strip postfix ".cfi_jt" from extern function name.
- Modified the commit message accordinglykernel/kallsyms.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
Quoted 15 lines
kernel/kallsyms.c static bool cleanup_symbol_name(char *s) · line 178
Quoted 11 lines
kernel/kallsyms.c +2
-1@@ -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_CLANGis selected for both LTO modes, so there's no need to also check forLTO_CLANG_THINhere.
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"
Quoted 6 lines
kernel/kallsyms.c static bool cleanup_symbol_name(char *s) · line 181
Quoted 3 lines
kernel/kallsyms.c +0
-0return 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
Quoted 16 lines
kernel/kallsyms.c static bool cleanup_symbol_name(char *s) · line 190
Quoted 12 lines
kernel/kallsyms.c +3
-5@@ -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.
Quoted 11 lines
Quoted 11 lines
kernel/kallsyms.c +7
-0+* +* 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;
Quoted 7 lines
kernel/kallsyms.c static bool cleanup_symbol_name(char *s) · line 204
Quoted 3 lines
kernel/kallsyms.c +2
-0res =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
Quoted 9 lines
Quoted 7 lines
kernel/kallsyms.c +1
-1+if (res) { *res ='\0' ;return true; --2.17.1
Sami
PATCH v4 1/1 kallsyms: strip CLANG CFI postfix ".cfi_jt"
In reply to Sami TolvanenClang 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.
---
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 [email protected].
https://lore.kernel.org/lkml/ [email protected]/#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 | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)
kernel/kallsyms.c +18 -5
@@ -174,13 +174,15 @@ 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." ); -if (res) { - *res ='\0' ; -return true; +if (IS_ENABLED (CONFIG_LTO_CLANG_THIN )) { + res =strstr (s,".llvm." ); +if (res) { + *res ='\0' ; +return true; + } }/*
@@ -194,6 +196,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;
Signature · 1 line
2.17.1
Re: [PATCH v4] kallsyms: strip CLANG CFI postfix ".cfi_jt"
Quoted 42 lines · Padmanabha Srinivasaiah
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.
Signed-off-by Padmanabha Srinivasaiah <[email protected]>---
Change in v4:
- Remove redundant check; irrespective of LTO type (THIN/FULL),LTO_CLANGwill 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 [email protected].https://lore.kernel.org/lkml/ [email protected]/#t- Fix is enabled even for
CONFIG_LTO_CLANGChange in v2:
- Use existing routine in kallsyms to strip postfix ".cfi_jt" from extern function name.
- Modified the commit message accordinglykernel/kallsyms.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)kernel/kallsyms.c +1
-2@@ -174,13 +174,15 @@ 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." );
kernel/kallsyms.c static bool cleanup_symbol_name(char *s) · line 186
Quoted 10 lines
kernel/kallsyms.c +6
-3-if (res) { - *res ='\0' ; -return true; +if (IS_ENABLED (CONFIG_LTO_CLANG_THIN )) { + res =strstr (s,".llvm." ); +if (res) { + *res ='\0' ; +return true; + } }
I confirmed that LLVM renames these also with full LTO, so the config check can be dropped here.
Quoted 10 lines
kernel/kallsyms.c +4
-0/* @@ -194,6 +196,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.
kernel/kallsyms.c static bool cleanup_symbol_name(char *s) · line 212
Quoted 10 lines
kernel/kallsyms.c +7
-0+* +* 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;
Otherwise, the logic looks pretty good to me. Nick, are you planning to resend your earlier patch? Should this be just folded into the next version?
Sami
Re: [PATCH v4] kallsyms: strip CLANG CFI postfix ".cfi_jt"
Quoted 43 lines · Sami Tolvanen
Quoted 41 lines · Padmanabha Srinivasaiah
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.
Signed-off-by Padmanabha Srinivasaiah <[email protected]>---
Change in v4:
- Remove redundant check; irrespective of LTO type (THIN/FULL),LTO_CLANGwill 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 [email protected].https://lore.kernel.org/lkml/ [email protected]/#t- Fix is enabled even for
CONFIG_LTO_CLANGChange in v2:
- Use existing routine in kallsyms to strip postfix ".cfi_jt" from extern function name.
- Modified the commit message accordinglykernel/kallsyms.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)kernel/kallsyms.c +1
-1@@ -174,13 +174,15 @@ 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;
Quoted 15 lines
kernel/kallsyms.c static bool cleanup_symbol_name(char *s) · line 186
Quoted 11 lines
kernel/kallsyms.c +6
-4- res =strstr (s,".llvm." ); -if (res) { - *res ='\0' ; -return true; +if (IS_ENABLED (CONFIG_LTO_CLANG_THIN )) { + res =strstr (s,".llvm." ); +if (res) { + *res ='\0' ; +return true; + } }I confirmed that LLVM renames these also with full LTO, so the config check can be dropped here.
Thank you sami for the input I missread your earlier review commit, will re-genrate the patch
Quoted 26 lines
Quoted 10 lines
kernel/kallsyms.c +4
-0/* @@ -194,6 +196,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. kernel/kallsyms.c static bool cleanup_symbol_name(char *s) · line 212
Quoted 10 lines
kernel/kallsyms.c +7
-0+* +* 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;Otherwise, the logic looks pretty good to me. Nick, are you planning to resend your earlier patch? Should this be just folded into the next version?
Sami
PATCH v5 1/1 kallsyms: strip CLANG CFI postfix ".cfi_jt"
In reply to Sami TolvanenClang 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.
---
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 [email protected].
https://lore.kernel.org/lkml/ [email protected]/#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(-)
kernel/kallsyms.c +12 -1
@@ -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;
Signature · 1 line
2.17.1
Re: [PATCH v5] kallsyms: strip CLANG CFI postfix ".cfi_jt"
Quoted 4 lines · Padmanabha Srinivasaiah
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/[email protected]/;
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.
Quoted 63 lines
Signed-off-by Padmanabha Srinivasaiah <[email protected]>---
Change in v5:
- Also remove explcit config check for postfix ".llvm." as LLVM renames even in full LTO caseChange in v4:
- Remove redundant check; irrespective of LTO type (THIN/FULL),LTO_CLANGwill 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 [email protected].https://lore.kernel.org/lkml/ [email protected]/#t- Fix is enabled even for
CONFIG_LTO_CLANGChange in v2:
- Use existing routine in kallsyms to strip postfix ".cfi_jt" from extern function name.
- Modified the commit message accordinglykernel/kallsyms.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)kernel/kallsyms.c +12
-2@@ -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
Signature · 2 lines
Thanks, ~Nick Desaulniers