Pull probes updates from Masami Hiramatsu: "Uprobes: - x86/shstk: Make return uprobe work with shadow stack - Add uretprobe syscall which speeds up the uretprobe 10-30% faster. This syscall is automatically used from user-space trampolines which are generated by the uretprobe. If this syscall is used by normal user program, it will cause SIGILL. Note that this is currently only implemented on x86_64. (This also has two fixes for adjusting the syscall number to avoid conflict with new *attrat syscalls.) - uprobes/perf: fix user stack traces in the presence of pending uretprobe. This corrects the uretprobe's trampoline address in the stacktrace with correct return address - selftests/x86: Add a return uprobe with shadow stack test - selftests/bpf: Add uretprobe syscall related tests. - test case for register integrity check - test case with register changing case - test case for uretprobe syscall without uprobes (expected to fail) - test case for uretprobe with shadow stack - selftests/bpf: add test validating uprobe/uretprobe stack traces - MAINTAINERS: Add uprobes entry. This does not specify the tree but to clarify who maintains and reviews the uprobes Kprobes: - tracing/kprobes: Test case cleanups. Replace redundant WARN_ON_ONCE() + pr_warn() with WARN_ONCE() and remove unnecessary code from selftest - tracing/kprobes: Add symbol counting check when module loads. This checks the uniqueness of the probed symbol on modules. The same check has already done for kernel symbols (This also has a fix for build error with CONFIG_MODULES=n) Cleanup: - Add MODULE_DESCRIPTION() macros for fprobe and kprobe examples" * tag 'probes-v6.11' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: MAINTAINERS: Add uprobes entry selftests/bpf: Change uretprobe syscall number in uprobe_syscall test uprobe: Change uretprobe syscall scope and number tracing/kprobes: Fix build error when find_module() is not available tracing/kprobes: Add symbol counting check when module loads selftests/bpf: add test validating uprobe/uretprobe stack traces perf,uprobes: fix user stack traces in the presence of pending uretprobes tracing/kprobe: Remove cleanup code unrelated to selftest tracing/kprobe: Integrate test warnings into WARN_ONCE selftests/bpf: Add uretprobe shadow stack test selftests/bpf: Add uretprobe syscall call from user space test selftests/bpf: Add uretprobe syscall test for regs changes selftests/bpf: Add uretprobe syscall test for regs integrity selftests/x86: Add return uprobe shadow stack test uprobe: Add uretprobe syscall to speed up return probe uprobe: Wire up uretprobe system call x86/shstk: Make return uprobe work with shadow stack samples: kprobes: add missing MODULE_DESCRIPTION() macros fprobe: add missing MODULE_DESCRIPTION() macro
Showing the changes to kernel/trace (1 of 23 files). Show all
Unified · Split
| @@ -678,6 +678,21 @@ end: · 677 unmodified lines | ||
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 680 | #ifdef CONFIG_MODULES |
| 681 | +static int validate_module_probe_symbol(const char *modname, const char *symbol); | |
| 682 | + | |
| 683 | +static int register_module_trace_kprobe(struct module *mod, struct trace_kprobe *tk) | |
| 684 | +{ | |
| 685 | + const char *p; | |
| 686 | + int ret = 0; | |
| 687 | + | |
| 688 | + p = strchr(trace_kprobe_symbol(tk), ':'); | |
| 689 | + if (p) | |
| 690 | + ret = validate_module_probe_symbol(module_name(mod), p + 1); | |
| 691 | + if (!ret) | |
| 692 | + ret = __register_trace_kprobe(tk); | |
| 693 | + return ret; | |
| 694 | +} | |
| 695 | + | |
| 681 | 696 | /* Module notifier call back, checking event on the module */ |
| 682 | 697 | static int trace_kprobe_module_callback(struct notifier_block *nb, |
| 683 | 698 | unsigned long val, void *data) |
| @@ -696,7 +711,7 @@ static int trace_kprobe_module_callback(struct notifier_block *nb, · 12 unmodified lines | ||
| 696 | 711 | if (trace_kprobe_within_module(tk, mod)) { |
| 697 | 712 | /* Don't need to check busy - this should have gone. */ |
| 698 | 713 | __unregister_trace_kprobe(tk); |
| 699 | − ret = __register_trace_kprobe(tk); | |
| 714 | + ret = register_module_trace_kprobe(mod, tk); | |
| 700 | 715 | if (ret) |
| 701 | 716 | pr_warn("Failed to re-register probe %s on %s: %d\n", |
| 702 | 717 | trace_probe_name(&tk->tp), |
| @@ -747,17 +762,81 @@ static int count_mod_symbols(void *data, const char *name, unsigned long unused) · 44 unmodified lines | ||
| 747 | 762 | return 0; |
| 748 | 763 | } |
| 749 | 764 | |
| 750 | −static unsigned int number_of_same_symbols(char *func_name) | |
| 765 | +static unsigned int number_of_same_symbols(const char *mod, const char *func_name) | |
| 751 | 766 | { |
| 752 | 767 | struct sym_count_ctx ctx = { .count = 0, .name = func_name }; |
| 753 | 768 | |
| 754 | − kallsyms_on_each_match_symbol(count_symbols, func_name, &ctx.count); | |
| 769 | + if (!mod) | |
| 770 | + kallsyms_on_each_match_symbol(count_symbols, func_name, &ctx.count); | |
| 755 | 771 | |
| 756 | − module_kallsyms_on_each_symbol(NULL, count_mod_symbols, &ctx); | |
| 772 | + module_kallsyms_on_each_symbol(mod, count_mod_symbols, &ctx); | |
| 757 | 773 | |
| 758 | 774 | return ctx.count; |
| 759 | 775 | } |
| 760 | 776 | |
| 777 | +static int validate_module_probe_symbol(const char *modname, const char *symbol) | |
| 778 | +{ | |
| 779 | + unsigned int count = number_of_same_symbols(modname, symbol); | |
| 780 | + | |
| 781 | + if (count > 1) { | |
| 782 | + /* | |
| 783 | + * Users should use ADDR to remove the ambiguity of | |
| 784 | + * using KSYM only. | |
| 785 | + */ | |
| 786 | + return -EADDRNOTAVAIL; | |
| 787 | + } else if (count == 0) { | |
| 788 | + /* | |
| 789 | + * We can return ENOENT earlier than when register the | |
| 790 | + * kprobe. | |
| 791 | + */ | |
| 792 | + return -ENOENT; | |
| 793 | + } | |
| 794 | + return 0; | |
| 795 | +} | |
| 796 | + | |
| 797 | +#ifdef CONFIG_MODULES | |
| 798 | +/* Return NULL if the module is not loaded or under unloading. */ | |
| 799 | +static struct module *try_module_get_by_name(const char *name) | |
| 800 | +{ | |
| 801 | + struct module *mod; | |
| 802 | + | |
| 803 | + rcu_read_lock_sched(); | |
| 804 | + mod = find_module(name); | |
| 805 | + if (mod && !try_module_get(mod)) | |
| 806 | + mod = NULL; | |
| 807 | + rcu_read_unlock_sched(); | |
| 808 | + | |
| 809 | + return mod; | |
| 810 | +} | |
| 811 | +#else | |
| 812 | +#define try_module_get_by_name(name) (NULL) | |
| 813 | +#endif | |
| 814 | + | |
| 815 | +static int validate_probe_symbol(char *symbol) | |
| 816 | +{ | |
| 817 | + struct module *mod = NULL; | |
| 818 | + char *modname = NULL, *p; | |
| 819 | + int ret = 0; | |
| 820 | + | |
| 821 | + p = strchr(symbol, ':'); | |
| 822 | + if (p) { | |
| 823 | + modname = symbol; | |
| 824 | + symbol = p + 1; | |
| 825 | + *p = '\0'; | |
| 826 | + mod = try_module_get_by_name(modname); | |
| 827 | + if (!mod) | |
| 828 | + goto out; | |
| 829 | + } | |
| 830 | + | |
| 831 | + ret = validate_module_probe_symbol(modname, symbol); | |
| 832 | +out: | |
| 833 | + if (p) | |
| 834 | + *p = ':'; | |
| 835 | + if (mod) | |
| 836 | + module_put(mod); | |
| 837 | + return ret; | |
| 838 | +} | |
| 839 | + | |
| 761 | 840 | static int trace_kprobe_entry_handler(struct kretprobe_instance *ri, |
| 762 | 841 | struct pt_regs *regs); |
| 763 | 842 | |
| @@ -881,6 +960,14 @@ static int __trace_kprobe_create(int argc, const char *argv[]) · 117 unmodified lines | ||
| 881 | 960 | trace_probe_log_err(0, BAD_PROBE_ADDR); |
| 882 | 961 | goto parse_error; |
| 883 | 962 | } |
| 963 | + ret = validate_probe_symbol(symbol); | |
| 964 | + if (ret) { | |
| 965 | + if (ret == -EADDRNOTAVAIL) | |
| 966 | + trace_probe_log_err(0, NON_UNIQ_SYMBOL); | |
| 967 | + else | |
| 968 | + trace_probe_log_err(0, BAD_PROBE_ADDR); | |
| 969 | + goto parse_error; | |
| 970 | + } | |
| 884 | 971 | if (is_return) |
| 885 | 972 | ctx.flags |= TPARG_FL_RETURN; |
| 886 | 973 | ret = kprobe_on_func_entry(NULL, symbol, offset); |
| @@ -893,31 +980,6 @@ static int __trace_kprobe_create(int argc, const char *argv[]) · 6 unmodified lines | ||
| 893 | 980 | } |
| 894 | 981 | } |
| 895 | 982 | |
| 896 | − if (symbol && !strchr(symbol, ':')) { | |
| 897 | − unsigned int count; | |
| 898 | − | |
| 899 | − count = number_of_same_symbols(symbol); | |
| 900 | − if (count > 1) { | |
| 901 | − /* | |
| 902 | − * Users should use ADDR to remove the ambiguity of | |
| 903 | − * using KSYM only. | |
| 904 | − */ | |
| 905 | − trace_probe_log_err(0, NON_UNIQ_SYMBOL); | |
| 906 | − ret = -EADDRNOTAVAIL; | |
| 907 | − | |
| 908 | − goto error; | |
| 909 | − } else if (count == 0) { | |
| 910 | − /* | |
| 911 | − * We can return ENOENT earlier than when register the | |
| 912 | − * kprobe. | |
| 913 | − */ | |
| 914 | − trace_probe_log_err(0, BAD_PROBE_ADDR); | |
| 915 | − ret = -ENOENT; | |
| 916 | − | |
| 917 | − goto error; | |
| 918 | − } | |
| 919 | − } | |
| 920 | − | |
| 921 | 983 | trace_probe_log_set_index(0); |
| 922 | 984 | if (event) { |
| 923 | 985 | ret = traceprobe_parse_event_name(&event, &group, gbuf, |
| @@ -1835,21 +1897,9 @@ create_local_trace_kprobe(char *func, void *addr, unsigned long offs, · 911 unmodified lines | ||
| 1835 | 1897 | char *event; |
| 1836 | 1898 | |
| 1837 | 1899 | if (func) { |
| 1838 | − unsigned int count; | |
| 1839 | − | |
| 1840 | − count = number_of_same_symbols(func); | |
| 1841 | − if (count > 1) | |
| 1842 | − /* | |
| 1843 | − * Users should use addr to remove the ambiguity of | |
| 1844 | − * using func only. | |
| 1845 | − */ | |
| 1846 | − return ERR_PTR(-EADDRNOTAVAIL); | |
| 1847 | − else if (count == 0) | |
| 1848 | − /* | |
| 1849 | − * We can return ENOENT earlier than when register the | |
| 1850 | − * kprobe. | |
| 1851 | − */ | |
| 1852 | − return ERR_PTR(-ENOENT); | |
| 1900 | + ret = validate_probe_symbol(func); | |
| 1901 | + if (ret) | |
| 1902 | + return ERR_PTR(ret); | |
| 1853 | 1903 | } |
| 1854 | 1904 | |
| 1855 | 1905 | /* |
| @@ -2023,19 +2073,16 @@ static __init int kprobe_trace_self_tests_init(void) · 167 unmodified lines | ||
| 2023 | 2073 | pr_info("Testing kprobe tracing: "); |
| 2024 | 2074 | |
| 2025 | 2075 | ret = create_or_delete_trace_kprobe("p:testprobe kprobe_trace_selftest_target $stack $stack0 +0($stack)"); |
| 2026 | − if (WARN_ON_ONCE(ret)) { | |
| 2027 | − pr_warn("error on probing function entry.\n"); | |
| 2076 | + if (WARN_ONCE(ret, "error on probing function entry.")) { | |
| 2028 | 2077 | warn++; |
| 2029 | 2078 | } else { |
| 2030 | 2079 | /* Enable trace point */ |
| 2031 | 2080 | tk = find_trace_kprobe("testprobe", KPROBE_EVENT_SYSTEM); |
| 2032 | − if (WARN_ON_ONCE(tk == NULL)) { | |
| 2033 | − pr_warn("error on getting new probe.\n"); | |
| 2081 | + if (WARN_ONCE(tk == NULL, "error on probing function entry.")) { | |
| 2034 | 2082 | warn++; |
| 2035 | 2083 | } else { |
| 2036 | 2084 | file = find_trace_probe_file(tk, top_trace_array()); |
| 2037 | − if (WARN_ON_ONCE(file == NULL)) { | |
| 2038 | − pr_warn("error on getting probe file.\n"); | |
| 2085 | + if (WARN_ONCE(file == NULL, "error on getting probe file.")) { | |
| 2039 | 2086 | warn++; |
| 2040 | 2087 | } else |
| 2041 | 2088 | enable_trace_kprobe( |
| @@ -2044,19 +2091,16 @@ static __init int kprobe_trace_self_tests_init(void) · 2 unmodified lines | ||
| 2044 | 2091 | } |
| 2045 | 2092 | |
| 2046 | 2093 | ret = create_or_delete_trace_kprobe("r:testprobe2 kprobe_trace_selftest_target $retval"); |
| 2047 | − if (WARN_ON_ONCE(ret)) { | |
| 2048 | − pr_warn("error on probing function return.\n"); | |
| 2094 | + if (WARN_ONCE(ret, "error on probing function return.")) { | |
| 2049 | 2095 | warn++; |
| 2050 | 2096 | } else { |
| 2051 | 2097 | /* Enable trace point */ |
| 2052 | 2098 | tk = find_trace_kprobe("testprobe2", KPROBE_EVENT_SYSTEM); |
| 2053 | − if (WARN_ON_ONCE(tk == NULL)) { | |
| 2054 | − pr_warn("error on getting 2nd new probe.\n"); | |
| 2099 | + if (WARN_ONCE(tk == NULL, "error on getting 2nd new probe.")) { | |
| 2055 | 2100 | warn++; |
| 2056 | 2101 | } else { |
| 2057 | 2102 | file = find_trace_probe_file(tk, top_trace_array()); |
| 2058 | − if (WARN_ON_ONCE(file == NULL)) { | |
| 2059 | − pr_warn("error on getting probe file.\n"); | |
| 2103 | + if (WARN_ONCE(file == NULL, "error on getting probe file.")) { | |
| 2060 | 2104 | warn++; |
| 2061 | 2105 | } else |
| 2062 | 2106 | enable_trace_kprobe( |
| @@ -2079,18 +2123,15 @@ static __init int kprobe_trace_self_tests_init(void) · 16 unmodified lines | ||
| 2079 | 2123 | |
| 2080 | 2124 | /* Disable trace points before removing it */ |
| 2081 | 2125 | tk = find_trace_kprobe("testprobe", KPROBE_EVENT_SYSTEM); |
| 2082 | − if (WARN_ON_ONCE(tk == NULL)) { | |
| 2083 | − pr_warn("error on getting test probe.\n"); | |
| 2126 | + if (WARN_ONCE(tk == NULL, "error on getting test probe.")) { | |
| 2084 | 2127 | warn++; |
| 2085 | 2128 | } else { |
| 2086 | − if (trace_kprobe_nhit(tk) != 1) { | |
| 2087 | − pr_warn("incorrect number of testprobe hits\n"); | |
| 2129 | + if (WARN_ONCE(trace_kprobe_nhit(tk) != 1, | |
| 2130 | + "incorrect number of testprobe hits.")) | |
| 2088 | 2131 | warn++; |
| 2089 | − } | |
| 2090 | 2132 | |
| 2091 | 2133 | file = find_trace_probe_file(tk, top_trace_array()); |
| 2092 | − if (WARN_ON_ONCE(file == NULL)) { | |
| 2093 | − pr_warn("error on getting probe file.\n"); | |
| 2134 | + if (WARN_ONCE(file == NULL, "error on getting probe file.")) { | |
| 2094 | 2135 | warn++; |
| 2095 | 2136 | } else |
| 2096 | 2137 | disable_trace_kprobe( |
| @@ -2098,18 +2139,15 @@ static __init int kprobe_trace_self_tests_init(void) · 1 unmodified line | ||
| 2098 | 2139 | } |
| 2099 | 2140 | |
| 2100 | 2141 | tk = find_trace_kprobe("testprobe2", KPROBE_EVENT_SYSTEM); |
| 2101 | − if (WARN_ON_ONCE(tk == NULL)) { | |
| 2102 | − pr_warn("error on getting 2nd test probe.\n"); | |
| 2142 | + if (WARN_ONCE(tk == NULL, "error on getting 2nd test probe.")) { | |
| 2103 | 2143 | warn++; |
| 2104 | 2144 | } else { |
| 2105 | − if (trace_kprobe_nhit(tk) != 1) { | |
| 2106 | − pr_warn("incorrect number of testprobe2 hits\n"); | |
| 2145 | + if (WARN_ONCE(trace_kprobe_nhit(tk) != 1, | |
| 2146 | + "incorrect number of testprobe2 hits.")) | |
| 2107 | 2147 | warn++; |
| 2108 | − } | |
| 2109 | 2148 | |
| 2110 | 2149 | file = find_trace_probe_file(tk, top_trace_array()); |
| 2111 | − if (WARN_ON_ONCE(file == NULL)) { | |
| 2112 | − pr_warn("error on getting probe file.\n"); | |
| 2150 | + if (WARN_ONCE(file == NULL, "error on getting probe file.")) { | |
| 2113 | 2151 | warn++; |
| 2114 | 2152 | } else |
| 2115 | 2153 | disable_trace_kprobe( |
| @@ -2117,23 +2155,15 @@ static __init int kprobe_trace_self_tests_init(void) · 1 unmodified line | ||
| 2117 | 2155 | } |
| 2118 | 2156 | |
| 2119 | 2157 | ret = create_or_delete_trace_kprobe("-:testprobe"); |
| 2120 | − if (WARN_ON_ONCE(ret)) { | |
| 2121 | − pr_warn("error on deleting a probe.\n"); | |
| 2158 | + if (WARN_ONCE(ret, "error on deleting a probe.")) | |
| 2122 | 2159 | warn++; |
| 2123 | − } | |
| 2124 | 2160 | |
| 2125 | 2161 | ret = create_or_delete_trace_kprobe("-:testprobe2"); |
| 2126 | − if (WARN_ON_ONCE(ret)) { | |
| 2127 | − pr_warn("error on deleting a probe.\n"); | |
| 2162 | + if (WARN_ONCE(ret, "error on deleting a probe.")) | |
| 2128 | 2163 | warn++; |
| 2129 | − } | |
| 2164 | + | |
| 2130 | 2165 | |
| 2131 | 2166 | end: |
| 2132 | − ret = dyn_events_release_all(&trace_kprobe_ops); | |
| 2133 | − if (WARN_ON_ONCE(ret)) { | |
| 2134 | − pr_warn("error on cleaning up probes.\n"); | |
| 2135 | − warn++; | |
| 2136 | − } | |
| 2137 | 2167 | /* |
| 2138 | 2168 | * Wait for the optimizer work to finish. Otherwise it might fiddle |
| 2139 | 2169 | * with probes in already freed __init text. |