* [PATCH 1/2] string: move __compiletime_strlen() to string.h @ 2026-02-05 10:05 Xie Yuanbin 2026-02-05 10:05 ` [PATCH 2/2] powerpc/text-patching: Fix possible stringop-overread compilation error Xie Yuanbin 0 siblings, 1 reply; 9+ messages in thread From: Xie Yuanbin @ 2026-02-05 10:05 UTC (permalink / raw) To: maddy, mpe, npiggin, chleroy, kees, andy Cc: linuxppc-dev, linux-kernel, linux-hardening, lilinjie8, liaohua4, xieyuanbin1 Move __compiletime_strlen() to string.h, so that others can use. Signed-off-by: Xie Yuanbin <xieyuanbin1@huawei.com> --- include/linux/fortify-string.h | 15 --------------- include/linux/string.h | 15 +++++++++++++++ lib/tests/fortify_kunit.c | 3 ++- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/include/linux/fortify-string.h b/include/linux/fortify-string.h index 171982e53c9a..c181dac26353 100644 --- a/include/linux/fortify-string.h +++ b/include/linux/fortify-string.h @@ -58,21 +58,6 @@ void __read_overflow2_field(size_t avail, size_t wanted) __compiletime_warning(" void __write_overflow(void) __compiletime_error("detected write beyond size of object (1st parameter)"); void __write_overflow_field(size_t avail, size_t wanted) __compiletime_warning("detected write beyond size of field (1st parameter); maybe use struct_group()?"); -#define __compiletime_strlen(p) \ -({ \ - char *__p = (char *)(p); \ - size_t __ret = SIZE_MAX; \ - const size_t __p_size = __member_size(p); \ - if (__p_size != SIZE_MAX && \ - __builtin_constant_p(*__p)) { \ - size_t __p_len = __p_size - 1; \ - if (__builtin_constant_p(__p[__p_len]) && \ - __p[__p_len] == '\0') \ - __ret = __builtin_strlen(__p); \ - } \ - __ret; \ -}) - #if defined(__SANITIZE_ADDRESS__) #if !defined(CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX) && !defined(CONFIG_GENERIC_ENTRY) diff --git a/include/linux/string.h b/include/linux/string.h index 1b564c36d721..fbae7d99bb6f 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -19,6 +19,21 @@ extern void *memdup_user(const void __user *, size_t) __realloc_size(2); extern void *vmemdup_user(const void __user *, size_t) __realloc_size(2); extern void *memdup_user_nul(const void __user *, size_t); +#define __compiletime_strlen(p) \ +({ \ + char *__p = (char *)(p); \ + size_t __ret = SIZE_MAX; \ + const size_t __p_size = __member_size(p); \ + if (__p_size != SIZE_MAX && \ + __builtin_constant_p(*__p)) { \ + size_t __p_len = __p_size - 1; \ + if (__builtin_constant_p(__p[__p_len]) && \ + __p[__p_len] == '\0') \ + __ret = __builtin_strlen(__p); \ + } \ + __ret; \ +}) + /** * memdup_array_user - duplicate array from user space * @src: source address in user space diff --git a/lib/tests/fortify_kunit.c b/lib/tests/fortify_kunit.c index fc9c76f026d6..86181e3bd994 100644 --- a/lib/tests/fortify_kunit.c +++ b/lib/tests/fortify_kunit.c @@ -49,7 +49,8 @@ void fortify_add_kunit_error(int write); #include <linux/vmalloc.h> /* Handle being built without CONFIG_FORTIFY_SOURCE */ -#ifndef __compiletime_strlen +#if defined(__NO_FORTIFY) || !defined(__OPTIMIZE__) || !defined(CONFIG_FORTIFY_SOURCE) +# undef __compiletime_strlen # define __compiletime_strlen __builtin_strlen #endif -- 2.51.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/2] powerpc/text-patching: Fix possible stringop-overread compilation error 2026-02-05 10:05 [PATCH 1/2] string: move __compiletime_strlen() to string.h Xie Yuanbin @ 2026-02-05 10:05 ` Xie Yuanbin 2026-02-05 16:40 ` Andy Shevchenko 2026-02-06 18:26 ` Kees Cook 0 siblings, 2 replies; 9+ messages in thread From: Xie Yuanbin @ 2026-02-05 10:05 UTC (permalink / raw) To: maddy, mpe, npiggin, chleroy, kees, andy Cc: linuxppc-dev, linux-kernel, linux-hardening, lilinjie8, liaohua4, xieyuanbin1 For strnlen(), if the compiler detects that the maxlen argument exceeds the valid memory size of the input string object, a compilation error may occur. For lastest linux-next source, changing ppc_kallsyms_lookup_name() to __always_inline, using default ppc64_defconfig, and setting CONFIG_EXPERT=y, CONFIG_PPC64_BIG_ENDIAN_ELF_ABI_V2=n, CONFIG_CC_OPTIMIZE_FOR_SIZE=y. Then, when using gcc-15 for compilation, the following error will be triggered: ```log CC arch/powerpc/kernel/optprobes.o In file included from ./arch/powerpc/include/asm/kprobes.h:24, from ./include/linux/kprobes.h:31, from arch/powerpc/kernel/optprobes.c:8: In function ‘ppc_kallsyms_lookup_name’, inlined from ‘arch_prepare_optimized_kprobe’ at arch/powerpc/kernel/optprobes.c:209:21: ./arch/powerpc/include/asm/text-patching.h:232:13: error: ‘strnlen’ specified bound 512 exceeds source size 19 [-Werror=stringop-overread] 232 | if (strnlen(name, KSYM_NAME_LEN) >= KSYM_NAME_LEN) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ In function ‘ppc_kallsyms_lookup_name’, inlined from ‘arch_prepare_optimized_kprobe’ at arch/powerpc/kernel/optprobes.c:210:22: ./arch/powerpc/include/asm/text-patching.h:232:13: error: ‘strnlen’ specified bound 512 exceeds source size 13 [-Werror=stringop-overread] 232 | if (strnlen(name, KSYM_NAME_LEN) >= KSYM_NAME_LEN) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors ``` Refer to the implementation of fortify's strnlen(). If the string length is a compile-time constant, do not call the strnlen() function. Signed-off-by: Xie Yuanbin <xieyuanbin1@huawei.com> --- arch/powerpc/include/asm/text-patching.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/include/asm/text-patching.h b/arch/powerpc/include/asm/text-patching.h index e7f14720f630..ce1b2131980a 100644 --- a/arch/powerpc/include/asm/text-patching.h +++ b/arch/powerpc/include/asm/text-patching.h @@ -228,8 +228,13 @@ static inline unsigned long ppc_kallsyms_lookup_name(const char *name) /* check for dot variant */ char dot_name[1 + KSYM_NAME_LEN]; bool dot_appended = false; + size_t n_len = __compiletime_strlen(name); + const size_t n_size = __member_size(name); - if (strnlen(name, KSYM_NAME_LEN) >= KSYM_NAME_LEN) + if (n_len == SIZE_MAX || KSYM_NAME_LEN < n_size) + n_len = strnlen(name, KSYM_NAME_LEN); + + if (n_len >= KSYM_NAME_LEN) return 0; if (name[0] != '.') { -- 2.51.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] powerpc/text-patching: Fix possible stringop-overread compilation error 2026-02-05 10:05 ` [PATCH 2/2] powerpc/text-patching: Fix possible stringop-overread compilation error Xie Yuanbin @ 2026-02-05 16:40 ` Andy Shevchenko 2026-02-06 11:14 ` Xie Yuanbin 2026-02-06 18:26 ` Kees Cook 1 sibling, 1 reply; 9+ messages in thread From: Andy Shevchenko @ 2026-02-05 16:40 UTC (permalink / raw) To: Xie Yuanbin Cc: maddy, mpe, npiggin, chleroy, kees, andy, linuxppc-dev, linux-kernel, linux-hardening, lilinjie8, liaohua4 On Thu, Feb 05, 2026 at 06:05:17PM +0800, Xie Yuanbin wrote: First of all, when sending a series, always add a cover letter to explain dependencies, goal, and how to route the series via the respective tree(s), et cetera. > For strnlen(), if the compiler detects that the maxlen argument exceeds > the valid memory size of the input string object, a compilation error may > occur. > > For lastest linux-next source, changing ppc_kallsyms_lookup_name() to > __always_inline, So, there is no issue in upstream without the mentioned change, right? > using default ppc64_defconfig, and setting > CONFIG_EXPERT=y, CONFIG_PPC64_BIG_ENDIAN_ELF_ABI_V2=n, > CONFIG_CC_OPTIMIZE_FOR_SIZE=y. Then, when using gcc-15 for compilation, > the following error will be triggered: > ```log > CC arch/powerpc/kernel/optprobes.o > In file included from ./arch/powerpc/include/asm/kprobes.h:24, > from ./include/linux/kprobes.h:31, > from arch/powerpc/kernel/optprobes.c:8: > In function ‘ppc_kallsyms_lookup_name’, > inlined from ‘arch_prepare_optimized_kprobe’ at arch/powerpc/kernel/optprobes.c:209:21: > ./arch/powerpc/include/asm/text-patching.h:232:13: error: ‘strnlen’ specified bound 512 exceeds source size 19 [-Werror=stringop-overread] > 232 | if (strnlen(name, KSYM_NAME_LEN) >= KSYM_NAME_LEN) > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ > In function ‘ppc_kallsyms_lookup_name’, > inlined from ‘arch_prepare_optimized_kprobe’ at arch/powerpc/kernel/optprobes.c:210:22: > ./arch/powerpc/include/asm/text-patching.h:232:13: error: ‘strnlen’ specified bound 512 exceeds source size 13 [-Werror=stringop-overread] > 232 | if (strnlen(name, KSYM_NAME_LEN) >= KSYM_NAME_LEN) > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ > cc1: all warnings being treated as errors > ``` > > Refer to the implementation of fortify's strnlen(). If the string length > is a compile-time constant, do not call the strnlen() function. I don't with the first patch this is a correct approach. But I let others to comment, I assume Kees knows better what's this and how it can be fixed without exporting special macros. -- With Best Regards, Andy Shevchenko ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] powerpc/text-patching: Fix possible stringop-overread compilation error 2026-02-05 16:40 ` Andy Shevchenko @ 2026-02-06 11:14 ` Xie Yuanbin 0 siblings, 0 replies; 9+ messages in thread From: Xie Yuanbin @ 2026-02-06 11:14 UTC (permalink / raw) To: maddy, mpe, npiggin, chleroy, kees, andy Cc: linuxppc-dev, linux-kernel, linux-hardening, lilinjie8, liaohua4, xieyuanbin1 On Thu, 5 Feb 2026 18:40:08 +0200, Andy Shevchenko wrote: >> For strnlen(), if the compiler detects that the maxlen argument exceeds >> the valid memory size of the input string object, a compilation error may >> occur. >> >> For lastest linux-next source, changing ppc_kallsyms_lookup_name() to >> __always_inline, > > So, there is no issue in upstream without the mentioned change, right? Yes. However, before the commit 889b3c1245de48ed0cac ("compiler: remove CONFIG_OPTIMIZE_INLINING entirely") is merged, inline will be changed to __always_inline, and this error will be directly triggered. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] powerpc/text-patching: Fix possible stringop-overread compilation error 2026-02-05 10:05 ` [PATCH 2/2] powerpc/text-patching: Fix possible stringop-overread compilation error Xie Yuanbin 2026-02-05 16:40 ` Andy Shevchenko @ 2026-02-06 18:26 ` Kees Cook 2026-02-06 19:53 ` Christophe Leroy (CS GROUP) 1 sibling, 1 reply; 9+ messages in thread From: Kees Cook @ 2026-02-06 18:26 UTC (permalink / raw) To: Xie Yuanbin Cc: maddy, mpe, npiggin, chleroy, andy, linuxppc-dev, linux-kernel, linux-hardening, lilinjie8, liaohua4 On Thu, Feb 05, 2026 at 06:05:17PM +0800, Xie Yuanbin wrote: > For strnlen(), if the compiler detects that the maxlen argument exceeds > the valid memory size of the input string object, a compilation error may > occur. > > For lastest linux-next source, changing ppc_kallsyms_lookup_name() to > __always_inline, using default ppc64_defconfig, and setting > CONFIG_EXPERT=y, CONFIG_PPC64_BIG_ENDIAN_ELF_ABI_V2=n, > CONFIG_CC_OPTIMIZE_FOR_SIZE=y. Then, when using gcc-15 for compilation, > the following error will be triggered: > ```log > CC arch/powerpc/kernel/optprobes.o > In file included from ./arch/powerpc/include/asm/kprobes.h:24, > from ./include/linux/kprobes.h:31, > from arch/powerpc/kernel/optprobes.c:8: > In function ‘ppc_kallsyms_lookup_name’, > inlined from ‘arch_prepare_optimized_kprobe’ at arch/powerpc/kernel/optprobes.c:209:21: > ./arch/powerpc/include/asm/text-patching.h:232:13: error: ‘strnlen’ specified bound 512 exceeds source size 19 [-Werror=stringop-overread] > 232 | if (strnlen(name, KSYM_NAME_LEN) >= KSYM_NAME_LEN) > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ > In function ‘ppc_kallsyms_lookup_name’, > inlined from ‘arch_prepare_optimized_kprobe’ at arch/powerpc/kernel/optprobes.c:210:22: > ./arch/powerpc/include/asm/text-patching.h:232:13: error: ‘strnlen’ specified bound 512 exceeds source size 13 [-Werror=stringop-overread] > 232 | if (strnlen(name, KSYM_NAME_LEN) >= KSYM_NAME_LEN) > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ > cc1: all warnings being treated as errors > ``` > > Refer to the implementation of fortify's strnlen(). If the string length > is a compile-time constant, do not call the strnlen() function. > > Signed-off-by: Xie Yuanbin <xieyuanbin1@huawei.com> > --- > arch/powerpc/include/asm/text-patching.h | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/arch/powerpc/include/asm/text-patching.h b/arch/powerpc/include/asm/text-patching.h > index e7f14720f630..ce1b2131980a 100644 > --- a/arch/powerpc/include/asm/text-patching.h > +++ b/arch/powerpc/include/asm/text-patching.h > @@ -228,8 +228,13 @@ static inline unsigned long ppc_kallsyms_lookup_name(const char *name) > /* check for dot variant */ > char dot_name[1 + KSYM_NAME_LEN]; > bool dot_appended = false; > + size_t n_len = __compiletime_strlen(name); > + const size_t n_size = __member_size(name); > > - if (strnlen(name, KSYM_NAME_LEN) >= KSYM_NAME_LEN) > + if (n_len == SIZE_MAX || KSYM_NAME_LEN < n_size) > + n_len = strnlen(name, KSYM_NAME_LEN); > + > + if (n_len >= KSYM_NAME_LEN) > return 0; Isn't it possible to do this and not need __compiletime_strlen at all? n_len = strnlen(name, min(__member_size(name), KSYM_NAME_LEN)); ? > > if (name[0] != '.') { > -- > 2.51.0 > -- Kees Cook ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] powerpc/text-patching: Fix possible stringop-overread compilation error 2026-02-06 18:26 ` Kees Cook @ 2026-02-06 19:53 ` Christophe Leroy (CS GROUP) 2026-02-09 13:25 ` Xie Yuanbin 0 siblings, 1 reply; 9+ messages in thread From: Christophe Leroy (CS GROUP) @ 2026-02-06 19:53 UTC (permalink / raw) To: Kees Cook, Xie Yuanbin Cc: maddy, mpe, npiggin, andy, linuxppc-dev, linux-kernel, linux-hardening, lilinjie8, liaohua4 Le 06/02/2026 à 19:26, Kees Cook a écrit : > On Thu, Feb 05, 2026 at 06:05:17PM +0800, Xie Yuanbin wrote: >> For strnlen(), if the compiler detects that the maxlen argument exceeds >> the valid memory size of the input string object, a compilation error may >> occur. >> >> For lastest linux-next source, changing ppc_kallsyms_lookup_name() to >> __always_inline, using default ppc64_defconfig, and setting >> CONFIG_EXPERT=y, CONFIG_PPC64_BIG_ENDIAN_ELF_ABI_V2=n, >> CONFIG_CC_OPTIMIZE_FOR_SIZE=y. Then, when using gcc-15 for compilation, >> the following error will be triggered: >> ```log >> CC arch/powerpc/kernel/optprobes.o >> In file included from ./arch/powerpc/include/asm/kprobes.h:24, >> from ./include/linux/kprobes.h:31, >> from arch/powerpc/kernel/optprobes.c:8: >> In function ‘ppc_kallsyms_lookup_name’, >> inlined from ‘arch_prepare_optimized_kprobe’ at arch/powerpc/kernel/optprobes.c:209:21: >> ./arch/powerpc/include/asm/text-patching.h:232:13: error: ‘strnlen’ specified bound 512 exceeds source size 19 [-Werror=stringop-overread] >> 232 | if (strnlen(name, KSYM_NAME_LEN) >= KSYM_NAME_LEN) >> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> In function ‘ppc_kallsyms_lookup_name’, >> inlined from ‘arch_prepare_optimized_kprobe’ at arch/powerpc/kernel/optprobes.c:210:22: >> ./arch/powerpc/include/asm/text-patching.h:232:13: error: ‘strnlen’ specified bound 512 exceeds source size 13 [-Werror=stringop-overread] >> 232 | if (strnlen(name, KSYM_NAME_LEN) >= KSYM_NAME_LEN) >> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> cc1: all warnings being treated as errors >> ``` >> >> Refer to the implementation of fortify's strnlen(). If the string length >> is a compile-time constant, do not call the strnlen() function. >> >> Signed-off-by: Xie Yuanbin <xieyuanbin1@huawei.com> >> --- >> arch/powerpc/include/asm/text-patching.h | 7 ++++++- >> 1 file changed, 6 insertions(+), 1 deletion(-) >> >> diff --git a/arch/powerpc/include/asm/text-patching.h b/arch/powerpc/include/asm/text-patching.h >> index e7f14720f630..ce1b2131980a 100644 >> --- a/arch/powerpc/include/asm/text-patching.h >> +++ b/arch/powerpc/include/asm/text-patching.h >> @@ -228,8 +228,13 @@ static inline unsigned long ppc_kallsyms_lookup_name(const char *name) >> /* check for dot variant */ >> char dot_name[1 + KSYM_NAME_LEN]; >> bool dot_appended = false; >> + size_t n_len = __compiletime_strlen(name); >> + const size_t n_size = __member_size(name); >> >> - if (strnlen(name, KSYM_NAME_LEN) >= KSYM_NAME_LEN) >> + if (n_len == SIZE_MAX || KSYM_NAME_LEN < n_size) >> + n_len = strnlen(name, KSYM_NAME_LEN); >> + >> + if (n_len >= KSYM_NAME_LEN) >> return 0; > > Isn't it possible to do this and not need __compiletime_strlen at all? > > n_len = strnlen(name, min(__member_size(name), KSYM_NAME_LEN)); ppc_kallsyms_lookup_name() only has two callers and they call it with a built-in string. I think we can do something a lot simpler, something like (untested): static inline unsigned long __ppc_kallsyms_lookup_name(const char *name) { unsigned long addr = kallsyms_lookup_name(name); if (IS_ENABLED(CONFIG_PPC64_ELF_ABI_V2) && addr) addr = ppc_function_entry((void *)addr); return addr; } #ifdef CONFIG_PPC64_ELF_ABI_V1 #define ppc_kallsyms_lookup_name(x) __ppc_kallsyms_lookup_name("." ## x); #else #define ppc_kallsyms_lookup_name(x) __ppc_kallsyms_lookup_name(x) #endif Christophe ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] powerpc/text-patching: Fix possible stringop-overread compilation error 2026-02-06 19:53 ` Christophe Leroy (CS GROUP) @ 2026-02-09 13:25 ` Xie Yuanbin 2026-02-09 13:41 ` Christophe Leroy (CS GROUP) 0 siblings, 1 reply; 9+ messages in thread From: Xie Yuanbin @ 2026-02-09 13:25 UTC (permalink / raw) To: chleroy, andriy.shevchenko, maddy, mpe, npiggin, kees, andy Cc: linuxppc-dev, linux-kernel, linux-hardening, lilinjie8, liaohua4, xieyuanbin1 [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain; charset="y", Size: 1564 bytes --] On Fri, 6 Feb 2026 20:53:55 +0100, Christophe Leroy (CS GROUP) wrote: > Le 06/02/2026 à 19:26, Kees Cook a écrit : >> >> Isn't it possible to do this and not need __compiletime_strlen at all? >> >> n_len = strnlen(name, min(__member_size(name), KSYM_NAME_LEN)); > > ppc_kallsyms_lookup_name() only has two callers and they call it with a > built-in string. I think we can do something a lot simpler, something > like (untested): > > static inline unsigned long __ppc_kallsyms_lookup_name(const char *name) > { > unsigned long addr = kallsyms_lookup_name(name); > > if (IS_ENABLED(CONFIG_PPC64_ELF_ABI_V2) && addr) > addr = ppc_function_entry((void *)addr); > > return addr; > } > > #ifdef CONFIG_PPC64_ELF_ABI_V1 > #define ppc_kallsyms_lookup_name(x) __ppc_kallsyms_lookup_name("." ## x); > #else > #define ppc_kallsyms_lookup_name(x) __ppc_kallsyms_lookup_name(x) > #endif > > Christophe When CONFIG_PPC64_ELF_ABI_V1=y, it seems that the try of lookupinp the original non-dot symbol is missing. What about this (Only the compilation test is performed): ```c static inline unsigned long __ppc_kallsyms_lookup_name(const char *name) { unsigned long addr = kallsyms_lookup_name(name); if (IS_ENABLED(CONFIG_PPC64_ELF_ABI_V2) && addr) addr = ppc_function_entry((void *)addr); return addr; } #define ppc_kallsyms_lookup_name(x) ({ \ unsigned long addr = 0; \ if (IS_ENABLED(CONFIG_PPC64_ELF_ABI_V1)) \ addr = __ppc_kallsyms_lookup_name("." x); \ if (!addr) \ addr = __ppc_kallsyms_lookup_name(x); \ addr; \ }) ``` ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] powerpc/text-patching: Fix possible stringop-overread compilation error 2026-02-09 13:25 ` Xie Yuanbin @ 2026-02-09 13:41 ` Christophe Leroy (CS GROUP) 2026-02-09 14:11 ` Xie Yuanbin 0 siblings, 1 reply; 9+ messages in thread From: Christophe Leroy (CS GROUP) @ 2026-02-09 13:41 UTC (permalink / raw) To: Xie Yuanbin, andriy.shevchenko, maddy, mpe, npiggin, kees, andy Cc: linuxppc-dev, linux-kernel, linux-hardening, lilinjie8, liaohua4 Le 09/02/2026 à 14:25, Xie Yuanbin a écrit : > On Fri, 6 Feb 2026 20:53:55 +0100, Christophe Leroy (CS GROUP) wrote: >> Le 06/02/2026 à 19:26, Kees Cook a écrit : >>> >>> Isn't it possible to do this and not need __compiletime_strlen at all? >>> >>> n_len = strnlen(name, min(__member_size(name), KSYM_NAME_LEN)); >> >> ppc_kallsyms_lookup_name() only has two callers and they call it with a >> built-in string. I think we can do something a lot simpler, something >> like (untested): >> >> static inline unsigned long __ppc_kallsyms_lookup_name(const char *name) >> { >> unsigned long addr = kallsyms_lookup_name(name); >> >> if (IS_ENABLED(CONFIG_PPC64_ELF_ABI_V2) && addr) >> addr = ppc_function_entry((void *)addr); >> >> return addr; >> } >> >> #ifdef CONFIG_PPC64_ELF_ABI_V1 >> #define ppc_kallsyms_lookup_name(x) __ppc_kallsyms_lookup_name("." ## x); >> #else >> #define ppc_kallsyms_lookup_name(x) __ppc_kallsyms_lookup_name(x) >> #endif >> >> Christophe > > When CONFIG_PPC64_ELF_ABI_V1=y, it seems that the try of lookupinp > the original non-dot symbol is missing. > > What about this (Only the compilation test is performed): > ```c > static inline unsigned long __ppc_kallsyms_lookup_name(const char *name) > { > unsigned long addr = kallsyms_lookup_name(name); > > if (IS_ENABLED(CONFIG_PPC64_ELF_ABI_V2) && addr) > addr = ppc_function_entry((void *)addr); > > return addr; > } > > #define ppc_kallsyms_lookup_name(x) ({ \ > unsigned long addr = 0; \ > if (IS_ENABLED(CONFIG_PPC64_ELF_ABI_V1)) \ > addr = __ppc_kallsyms_lookup_name("." x); \ > if (!addr) \ > addr = __ppc_kallsyms_lookup_name(x); \ > addr; \ > }) > ``` Good point. To avoid duplicating the string I'd suggest: static inline unsigned long __ppc_kallsyms_lookup_name(const char *name) { unsigned long addr = kallsyms_lookup_name(name); if (IS_ENABLED(CONFIG_PPC64_ELF_ABI_V1) && !addr) addr = kallsyms_lookup_name(name + 1); if (IS_ENABLED(CONFIG_PPC64_ELF_ABI_V2) && addr) addr = ppc_function_entry((void *)addr); return addr; } #ifdef CONFIG_PPC64_ELF_ABI_V1 #define ppc_kallsyms_lookup_name(x) __ppc_kallsyms_lookup_name("." x); #else #define ppc_kallsyms_lookup_name(x) __ppc_kallsyms_lookup_name(x) #endif ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] powerpc/text-patching: Fix possible stringop-overread compilation error 2026-02-09 13:41 ` Christophe Leroy (CS GROUP) @ 2026-02-09 14:11 ` Xie Yuanbin 0 siblings, 0 replies; 9+ messages in thread From: Xie Yuanbin @ 2026-02-09 14:11 UTC (permalink / raw) To: chleroy, andriy.shevchenko, maddy, mpe, npiggin, kees, andy Cc: linuxppc-dev, linux-kernel, linux-hardening, lilinjie8, liaohua4, xieyuanbin1 [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain; charset="y", Size: 2382 bytes --] On Mon, 9 Feb 2026 14:41:51 +0100, Christophe Leroy (CS GROUP) wrote: > Le 09/02/2026 à 14:25, Xie Yuanbin a écrit : >> On Fri, 6 Feb 2026 20:53:55 +0100, Christophe Leroy (CS GROUP) wrote: >>> ppc_kallsyms_lookup_name() only has two callers and they call it with a >>> built-in string. I think we can do something a lot simpler, something >>> like (untested): >>> >>> static inline unsigned long __ppc_kallsyms_lookup_name(const char *name) >>> { >>> unsigned long addr = kallsyms_lookup_name(name); >>> >>> if (IS_ENABLED(CONFIG_PPC64_ELF_ABI_V2) && addr) >>> addr = ppc_function_entry((void *)addr); >>> >>> return addr; >>> } >>> >>> #ifdef CONFIG_PPC64_ELF_ABI_V1 >>> #define ppc_kallsyms_lookup_name(x) __ppc_kallsyms_lookup_name("." ## x); >>> #else >>> #define ppc_kallsyms_lookup_name(x) __ppc_kallsyms_lookup_name(x) >>> #endif >>> >>> Christophe >> >> When CONFIG_PPC64_ELF_ABI_V1=y, it seems that the try of lookupinp >> the original non-dot symbol is missing. >> >> What about this (Only the compilation test is performed): >> ```c >> static inline unsigned long __ppc_kallsyms_lookup_name(const char *name) >> { >> unsigned long addr = kallsyms_lookup_name(name); >> >> if (IS_ENABLED(CONFIG_PPC64_ELF_ABI_V2) && addr) >> addr = ppc_function_entry((void *)addr); >> >> return addr; >> } >> >> #define ppc_kallsyms_lookup_name(x) ({ \ >> unsigned long addr = 0; \ >> if (IS_ENABLED(CONFIG_PPC64_ELF_ABI_V1)) \ >> addr = __ppc_kallsyms_lookup_name("." x); \ >> if (!addr) \ >> addr = __ppc_kallsyms_lookup_name(x); \ >> addr; \ >> }) >> ``` > > Good point. > > To avoid duplicating the string I'd suggest: > > static inline unsigned long __ppc_kallsyms_lookup_name(const char *name) > { > unsigned long addr = kallsyms_lookup_name(name); > > if (IS_ENABLED(CONFIG_PPC64_ELF_ABI_V1) && !addr) > addr = kallsyms_lookup_name(name + 1); > if (IS_ENABLED(CONFIG_PPC64_ELF_ABI_V2) && addr) > addr = ppc_function_entry((void *)addr); > > return addr; > } > > #ifdef CONFIG_PPC64_ELF_ABI_V1 > #define ppc_kallsyms_lookup_name(x) __ppc_kallsyms_lookup_name("." x); > #else > #define ppc_kallsyms_lookup_name(x) __ppc_kallsyms_lookup_name(x) > #endif This seems good, but there seems to be an extra ';' after '__ppc_kallsyms_lookup_name("." x)' ? After removing the extra ';', I performed a compilation test, no warnings. ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-02-09 14:11 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-02-05 10:05 [PATCH 1/2] string: move __compiletime_strlen() to string.h Xie Yuanbin 2026-02-05 10:05 ` [PATCH 2/2] powerpc/text-patching: Fix possible stringop-overread compilation error Xie Yuanbin 2026-02-05 16:40 ` Andy Shevchenko 2026-02-06 11:14 ` Xie Yuanbin 2026-02-06 18:26 ` Kees Cook 2026-02-06 19:53 ` Christophe Leroy (CS GROUP) 2026-02-09 13:25 ` Xie Yuanbin 2026-02-09 13:41 ` Christophe Leroy (CS GROUP) 2026-02-09 14:11 ` Xie Yuanbin
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox