From nobody Sat Jun 13 19:12:08 2026 Received: from canpmsgout06.his.huawei.com (canpmsgout06.his.huawei.com [113.46.200.221]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63AE2283C9D for ; Wed, 6 May 2026 02:12:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.221 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778033536; cv=none; b=UcVow02AZE8gzkMA0nOEDjKaw+tsfbVc0B5ovBVuzFG2kYUrrumc+007lV0Iasex4Ht2Iz6gulR+Ah+hpk9gzZCxSnC3rmq9zAd640wZ1+B+ffHlNWD6ZPQGwYoN7Y0p8bbkAEyX/3yz+j8hyY8s/pbCeNXeq4nKm0Una57fkNo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778033536; c=relaxed/simple; bh=9N64u9FTvf7qgJPPWEuiphJ0d2DfSC0KCCubpvZ3Q7I=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=rtdzv0cD+AaErH2Z6l5hfkVNQCvLvXEPpx1sNjR2m6+MtDkiew/oWmtum0BT/am9/buUeb1ClQf6NAj8tg1lvah4W/XisOkHKUzSjvEc8HKTE7gUu6eKvTYn0tChXm93gVa9QSYzF+Hcdo0F8uU37fZpCtvY3VUdw3DCPuOs94k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=yNTbuRmo; arc=none smtp.client-ip=113.46.200.221 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="yNTbuRmo" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=HMqHW+wl1jJEGGmKKzAemuQMuR+F3aEoMElUydaAiH0=; b=yNTbuRmolm/SEoq+MkaSp/cYhtRgK4nsCKZwtO3fqA6+9ZhleNRt68Jnv2/RrJISaYn6gSd+u aCx6xYY7OF2l0Uw8iMfP40fycKvDbh7HTo3w3AmhHFNraYyNk8UjMKjfYVfDjZn7E4qgOx7xeYc cbrTTJrKbUV2daiXo8CM/wE= Received: from mail.maildlp.com (unknown [172.19.163.0]) by canpmsgout06.his.huawei.com (SkyGuard) with ESMTPS id 4g9Jbn3WcSzRhRT; Wed, 6 May 2026 10:04:37 +0800 (CST) Received: from kwepemj100009.china.huawei.com (unknown [7.202.194.3]) by mail.maildlp.com (Postfix) with ESMTPS id CC7FD40561; Wed, 6 May 2026 10:12:09 +0800 (CST) Received: from DESKTOP-A37P9LK.huawei.com (10.67.109.17) by kwepemj100009.china.huawei.com (7.202.194.3) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.36; Wed, 6 May 2026 10:12:09 +0800 From: Xie Yuanbin To: , , , , , CC: , , , , Subject: [PATCH V2] powerpc/text-patching: simplify the implementation of ppc_kallsyms_lookup_name() Date: Wed, 6 May 2026 10:11:43 +0800 Message-ID: <20260506021143.13797-1-xieyuanbin1@huawei.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems500001.china.huawei.com (7.221.188.70) To kwepemj100009.china.huawei.com (7.202.194.3) Content-Type: text/plain; charset="utf-8" ppc_kallsyms_lookup_name() is called only twice in the kernel code, and the parameters are all constant strings. strnlen(name, KSYM_NAME_LEN) is called inside ppc_kallsyms_lookup_name(), when the compiler detects that KSYM_NAME_LEN is larger then the constant strings, 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/opt= probes.c:209:21: ./arch/powerpc/include/asm/text-patching.h:232:13: error: 'strnlen' specifi= ed bound 512 exceeds source size 19 [-Werror=3Dstringop-overread] 232 | if (strnlen(name, KSYM_NAME_LEN) >=3D KSYM_NAME_LEN) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ In function 'ppc_kallsyms_lookup_name', inlined from 'arch_prepare_optimized_kprobe' at arch/powerpc/kernel/opt= probes.c:210:22: ./arch/powerpc/include/asm/text-patching.h:232:13: error: 'strnlen' specifi= ed bound 512 exceeds source size 13 [-Werror=3Dstringop-overread] 232 | if (strnlen(name, KSYM_NAME_LEN) >=3D KSYM_NAME_LEN) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors ``` The error can be reproduced in the following ways: Use lastest linux-next source, change ppc_kallsyms_lookup_name() to __always_inline, use default ppc64_defconfig, set CONFIG_EXPERT=3Dy, CONFIG_PPC64_BIG_ENDIAN_ELF_ABI_V2=3Dn, CONFIG_CC_OPTIMIZE_FOR_SIZE=3Dy, and use gcc-14 or a later version for compilation. Since ppc_kallsyms_lookup_name() is called only twice in the kernel, and the parameters are all constant strins, simplify the implementation of ppc_kallsyms_lookup_name() and avoid calling strnlen(). Cc: Andy Shevchenko Cc: Kees Cook Suggested-by: Christophe Leroy (CS GROUP) Signed-off-by: Xie Yuanbin Reviewed-by: Christophe Leroy (CS GROUP) --- v1->v2: https://lore.kernel.org/20260205100517.292858-2-xieyuanbin1@huawei.= com - Not use strlen() arch/powerpc/include/asm/text-patching.h | 50 ++++++++---------------- 1 file changed, 17 insertions(+), 33 deletions(-) diff --git a/arch/powerpc/include/asm/text-patching.h b/arch/powerpc/includ= e/asm/text-patching.h index e7f14720f630..2d3f698cb4f1 100644 --- a/arch/powerpc/include/asm/text-patching.h +++ b/arch/powerpc/include/asm/text-patching.h @@ -221,39 +221,23 @@ static inline unsigned long ppc_global_function_entry= (void *func) * - For ABIv1, we lookup the dot variant. * - For ABIv2, we return the local entry point. */ -static inline unsigned long ppc_kallsyms_lookup_name(const char *name) -{ - unsigned long addr; -#ifdef CONFIG_PPC64_ELF_ABI_V1 - /* check for dot variant */ - char dot_name[1 + KSYM_NAME_LEN]; - bool dot_appended =3D false; - - if (strnlen(name, KSYM_NAME_LEN) >=3D KSYM_NAME_LEN) - return 0; - - if (name[0] !=3D '.') { - dot_name[0] =3D '.'; - dot_name[1] =3D '\0'; - strlcat(dot_name, name, sizeof(dot_name)); - dot_appended =3D true; - } else { - dot_name[0] =3D '\0'; - strlcat(dot_name, name, sizeof(dot_name)); - } - addr =3D kallsyms_lookup_name(dot_name); - if (!addr && dot_appended) - /* Let's try the original non-dot symbol lookup */ - addr =3D kallsyms_lookup_name(name); -#elif defined(CONFIG_PPC64_ELF_ABI_V2) - addr =3D kallsyms_lookup_name(name); - if (addr) - addr =3D ppc_function_entry((void *)addr); -#else - addr =3D kallsyms_lookup_name(name); -#endif - return addr; -} +static inline unsigned long __ppc_kallsyms_lookup_name(const char *name) +{ + unsigned long addr =3D kallsyms_lookup_name(name); + + if (IS_ENABLED(CONFIG_PPC64_ELF_ABI_V1) && !addr) + addr =3D kallsyms_lookup_name(name + 1); + if (IS_ENABLED(CONFIG_PPC64_ELF_ABI_V2) && addr) + addr =3D 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 =20 /* * Some instruction encodings commonly used in dynamic ftracing --=20 2.53.0