When an unqualified kprobe target exists in both vmlinux and a loaded module, number_of_same_symbols() returns a count greater than 1, causing kprobe attachment to fail with -EADDRNOTAVAIL even though the vmlinux symbol is unambiguous. When no module qualifier is given and the symbol is found in vmlinux, return the vmlinux-only count without scanning loaded modules. This preserves the existing behavior for all other cases: - Symbol only in a module: vmlinux count is 0, falls through to module scan as before. - Symbol qualified with MOD:SYM: mod != NULL, unchanged path. - Symbol ambiguous within vmlinux itself: count > 1 is returned as-is.
Showing the changes to kernel (1 of 1 file). Show all
Unified · Split
| @@ -765,6 +765,14 @@ static unsigned int number_of_same_symbols(const char *mod, const char *func_nam · 764 unmodified lines | |||
| 765 | if (!mod) | 765 | if (!mod) |
| 766 | kallsyms_on_each_match_symbol(count_symbols, func_name, &ctx.count); | 766 | kallsyms_on_each_match_symbol(count_symbols, func_name, &ctx.count); |
| 767 | 767 | ||
| 768 | /* | ||
| 769 | * If the symbol is found in vmlinux, use vmlinux resolution only. | ||
| 770 | * This prevents module symbols from shadowing vmlinux symbols | ||
| 771 | * and causing -EADDRNOTAVAIL for unqualified kprobe targets. | ||
| 772 | */ | ||
| 773 | if (!mod && ctx.count > 0) | ||
| 774 | return ctx.count; | ||
| 775 | |||
| 768 | module_kallsyms_on_each_symbol(mod, count_mod_symbols, &ctx); | 776 | module_kallsyms_on_each_symbol(mod, count_mod_symbols, &ctx); |
| 769 | 777 | ||
| 770 | return ctx.count; | 778 | return ctx.count; |