Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'probes-fixes-v6.6-rc6.2' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace

Pull probes fixes from Masami Hiramatsu:

- kprobe-events: Fix kprobe events to reject if the attached symbol is
not unique name because it may not the function which the user want
to attach to. (User can attach a probe to such symbol using the
nearest unique symbol + offset.)

- selftest: Add a testcase to ensure the kprobe event rejects non
unique symbol correctly.

* tag 'probes-fixes-v6.6-rc6.2' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace:
selftests/ftrace: Add new test case which checks non unique symbol
tracing/kprobes: Return EADDRNOTAVAIL when func matches several symbols

+77
+63
kernel/trace/trace_kprobe.c
··· 705 705 .priority = 1 /* Invoked after kprobe module callback */ 706 706 }; 707 707 708 + static int count_symbols(void *data, unsigned long unused) 709 + { 710 + unsigned int *count = data; 711 + 712 + (*count)++; 713 + 714 + return 0; 715 + } 716 + 717 + static unsigned int number_of_same_symbols(char *func_name) 718 + { 719 + unsigned int count; 720 + 721 + count = 0; 722 + kallsyms_on_each_match_symbol(count_symbols, func_name, &count); 723 + 724 + return count; 725 + } 726 + 708 727 static int __trace_kprobe_create(int argc, const char *argv[]) 709 728 { 710 729 /* ··· 852 833 if (ret == -EINVAL && is_return) { 853 834 trace_probe_log_err(0, BAD_RETPROBE); 854 835 goto parse_error; 836 + } 837 + } 838 + 839 + if (symbol && !strchr(symbol, ':')) { 840 + unsigned int count; 841 + 842 + count = number_of_same_symbols(symbol); 843 + if (count > 1) { 844 + /* 845 + * Users should use ADDR to remove the ambiguity of 846 + * using KSYM only. 847 + */ 848 + trace_probe_log_err(0, NON_UNIQ_SYMBOL); 849 + ret = -EADDRNOTAVAIL; 850 + 851 + goto error; 852 + } else if (count == 0) { 853 + /* 854 + * We can return ENOENT earlier than when register the 855 + * kprobe. 856 + */ 857 + trace_probe_log_err(0, BAD_PROBE_ADDR); 858 + ret = -ENOENT; 859 + 860 + goto error; 855 861 } 856 862 } 857 863 ··· 1739 1695 } 1740 1696 1741 1697 #ifdef CONFIG_PERF_EVENTS 1698 + 1742 1699 /* create a trace_kprobe, but don't add it to global lists */ 1743 1700 struct trace_event_call * 1744 1701 create_local_trace_kprobe(char *func, void *addr, unsigned long offs, ··· 1749 1704 struct trace_kprobe *tk; 1750 1705 int ret; 1751 1706 char *event; 1707 + 1708 + if (func) { 1709 + unsigned int count; 1710 + 1711 + count = number_of_same_symbols(func); 1712 + if (count > 1) 1713 + /* 1714 + * Users should use addr to remove the ambiguity of 1715 + * using func only. 1716 + */ 1717 + return ERR_PTR(-EADDRNOTAVAIL); 1718 + else if (count == 0) 1719 + /* 1720 + * We can return ENOENT earlier than when register the 1721 + * kprobe. 1722 + */ 1723 + return ERR_PTR(-ENOENT); 1724 + } 1752 1725 1753 1726 /* 1754 1727 * local trace_kprobes are not added to dyn_event, so they are never
+1
kernel/trace/trace_probe.h
··· 450 450 C(BAD_MAXACT, "Invalid maxactive number"), \ 451 451 C(MAXACT_TOO_BIG, "Maxactive is too big"), \ 452 452 C(BAD_PROBE_ADDR, "Invalid probed address or symbol"), \ 453 + C(NON_UNIQ_SYMBOL, "The symbol is not unique"), \ 453 454 C(BAD_RETPROBE, "Retprobe address must be an function entry"), \ 454 455 C(NO_TRACEPOINT, "Tracepoint is not found"), \ 455 456 C(BAD_ADDR_SUFFIX, "Invalid probed address suffix"), \
+13
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_non_uniq_symbol.tc
··· 1 + #!/bin/sh 2 + # SPDX-License-Identifier: GPL-2.0 3 + # description: Test failure of registering kprobe on non unique symbol 4 + # requires: kprobe_events 5 + 6 + SYMBOL='name_show' 7 + 8 + # We skip this test on kernel where SYMBOL is unique or does not exist. 9 + if [ "$(grep -c -E "[[:alnum:]]+ t ${SYMBOL}" /proc/kallsyms)" -le '1' ]; then 10 + exit_unsupported 11 + fi 12 + 13 + ! echo "p:test_non_unique ${SYMBOL}" > kprobe_events