提交 a8837d4e 编写于 作者: A Alexander Lobakin 提交者: Zheng Zengkai

modpost: fix removing numeric suffixes

stable inclusion
from stable-v5.10.122
commit 741e49eacdcd31ec9b448a77b1ab9219a00c1db9
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I5W6OE

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=741e49eacdcd31ec9b448a77b1ab9219a00c1db9

--------------------------------

[ Upstream commit b5beffa2 ]

With the `-z unique-symbol` linker flag or any similar mechanism,
it is possible to trigger the following:

ERROR: modpost: "param_set_uint.0" [vmlinux] is a static EXPORT_SYMBOL

The reason is that for now the condition from remove_dot():

if (m && (s[n + m] == '.' || s[n + m] == 0))

which was designed to test if it's a dot or a '\0' after the suffix
is never satisfied.
This is due to that `s[n + m]` always points to the last digit of a
numeric suffix, not on the symbol next to it (from a custom debug
print added to modpost):

param_set_uint.0, s[n + m] is '0', s[n + m + 1] is '\0'

So it's off-by-one and was like that since 2014.

Fix this for the sake of any potential upcoming features, but don't
bother stable-backporting, as it's well hidden -- apart from that
LD flag, it can be triggered only with GCC LTO which never landed
upstream.

Fixes: fcd38ed0 ("scripts: modpost: fix compilation warning")
Signed-off-by: NAlexander Lobakin <alexandr.lobakin@intel.com>
Reviewed-by: NPetr Mladek <pmladek@suse.com>
Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
Reviewed-by: NWei Li <liwei391@huawei.com>
上级 1788e4cb
...@@ -1982,7 +1982,7 @@ static char *remove_dot(char *s) ...@@ -1982,7 +1982,7 @@ static char *remove_dot(char *s)
if (n && s[n]) { if (n && s[n]) {
size_t m = strspn(s + n + 1, "0123456789"); size_t m = strspn(s + n + 1, "0123456789");
if (m && (s[n + m] == '.' || s[n + m] == 0)) if (m && (s[n + m + 1] == '.' || s[n + m + 1] == 0))
s[n] = 0; s[n] = 0;
} }
return s; return s;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册