kbuild: detect module name collisions between '-' and '_'
Subsystems (2)
PATCH 1/1 kbuild: detect module name collisions between '-' and '_'
From: Hamdy Abou El Anein <[email protected]>
Kbuild converts hyphens to underscores in KBUILD_MODNAME, and the module loader treats both characters as equivalent. However, modules-check.sh compares module basenames without normalization. Consequently, modules named foo-bar.o and foo_bar.o pass the conflict check even though they have the same effective module name.
Normalize basenames before checking for duplicates, and use awk to show the original module paths in diagnostics. Preserve detection of exact duplicates and leave distinct names unaffected.
--- scripts/modules-check.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
scripts/modules-check.sh +11 -2
@@ -13,10 +13,19 @@ exit_code=0 # Check uniqueness of module names check_same_name_modules() { - for m in $(sed 's:.*/::' "$1" | sort | uniq -d) + for m in $(sed 's:.*/::; s/-/_/g' "$1" | sort | uniq -d) do echo "error: the following would cause module name conflict:" >&2 - sed -n "/\/$m/s:^\(.*\)\.o\$: \1.ko:p" "$1" >&2 + awk -v name="$m" ' + { + basename = $0 + sub(/^.*\//, "", basename) + gsub(/-/, "_", basename) + if (basename == name) { + sub(/\.o$/, ".ko") + print " " $0 + } + }' "$1" >&2 exit_code=1 done }
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
Signature · 1 line
2.56.0
Quoted 11 lines
Kbuildconverts hyphens to underscores inKBUILD_MODNAME, and the module loader treats both characters as equivalent. However,modules-check.shcompares module basenames without normalization. Consequently, modules named foo-bar.o and foo_bar.o pass the conflict check even though they have the same effective module name.Normalize basenames before checking for duplicates, and use awk to show the original module paths in diagnostics. Preserve detection of exact duplicates and leave distinct names unaffected.
Signed-off-by Hamdy Abou El Anein <[email protected]>
Good catch, I was able to reproduce this type of miss. This resolves it. I suppose this has been a problem since this patch was first merged?
Signature · 2 lines
Cheers, Nathan
Hi Nathan,
Yes, it appears so. The module-name uniqueness check dates back to 2019 and compared basenames without normalizing '-' and '_', so this case seems to have been missed since its introduction.
Thanks for reviewing,
Hamdy
Nicolas Schier
maintainerQuoted 11 lines · Hamdy Abou El Anein
Kbuildconverts hyphens to underscores inKBUILD_MODNAME, and the module loader treats both characters as equivalent. However,modules-check.shcompares module basenames without normalization. Consequently, modules named foo-bar.o and foo_bar.o pass the conflict check even though they have the same effective module name.Normalize basenames before checking for duplicates, and use awk to show the original module paths in diagnostics. Preserve detection of exact duplicates and leave distinct names unaffected.
[...]
Applied to kbuild/linux.git (kbuild-next-unstable), with 'Fixes:' tag added, thanks!
[1/1] kbuild: detect module name collisions between '-' and '_'
https://git.kernel.org/kbuild/c/bc348949
Please look out for regression or issue reports or other follow up comments, as they may result in the patch/series getting dropped, reverted or modified (e.g. trailers).
Patches applied to the kbuild-next-unstable branch are accepted pending wider testing in linux-next and any post-commit review; they will generally be moved to the kbuild-next branch in about a week if no issues are found.
Best regards,
Signature · 1 line
Nicolas
Quoted 4 lines · Nicolas Schier
Applied to kbuild/linux.git (kbuild-next-unstable), with 'Fixes:' tag added, thanks!
[1/1] kbuild: detect module name collisions between '-' and '_'
https://git.kernel.org/kbuild/c/bc348949
With this applied, ARCH=arm allmodconfig fails in modules_check on two pairs of modules that have been in the tree for years:
error: the following would cause module name conflict:
drivers/input/apm-power.ko drivers/power/supply/apm_power.ko
error: the following would cause module name conflict:
arch/arm/probes/kprobes/test-kprobes.ko lib/tests/test_kprobes.ko
KernelCI report:
https://d.kernelci.org/i/maestro:a0850dfdbf5eccb82fb3e7100a7178920a91c662
--
Thanks,
Sasha
Nathan Chancellor
maintainerQuoted 8 lines · Sasha Levin
Quoted 4 lines · Nicolas Schier
Applied to kbuild/linux.git (kbuild-next-unstable), with 'Fixes:' tag added, thanks!
[1/1] kbuild: detect module name collisions between '-' and '_'
https://git.kernel.org/kbuild/c/bc348949With this applied, ARCH=arm allmodconfig fails in
modules_checkon two pairs of modules that have been in the tree for years:
Thanks a lot for the report. I tested arm64 and x86_64 allmodconfig but failed to do arm. I sent the following patches for these.
Quoted 3 lines
error: the following would cause module name conflict:
drivers/input/apm-power.kodrivers/power/supply/apm_power.ko
https://lore.kernel.org/[email protected]/
Quoted 3 lines
error: the following would cause module name conflict:
arch/arm/probes/kprobes/test-kprobes.kolib/tests/test_kprobes.ko
https://lore.kernel.org/[email protected]/
Signature · 2 lines
Cheers, Nathan