History

Merge tag 'probes-v6.11' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace

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

Linus Torvalds committed 2 years ago

Commit 91bd0082 parents cb273eb c26b1b823 files · +1320 −92Browse files

Showing the changes to kernel/trace (1 of 23 files). Show all

Unified · Split

kernel/trace/trace_kprobe.c+111−81
@@ -678,6 +678,21 @@ end: · 677 unmodified lines
678}678}
679 679
680#ifdef CONFIG_MODULES680#ifdef CONFIG_MODULES
681static int validate_module_probe_symbol(const char *modname, const char *symbol);
682
683static 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/* Module notifier call back, checking event on the module */696/* Module notifier call back, checking event on the module */
682static int trace_kprobe_module_callback(struct notifier_block *nb,697static int trace_kprobe_module_callback(struct notifier_block *nb,
683 unsigned long val, void *data)698 unsigned long val, void *data)
@@ -696,7 +711,7 @@ static int trace_kprobe_module_callback(struct notifier_block *nb, · 12 unmodified lines
696 if (trace_kprobe_within_module(tk, mod)) {711 if (trace_kprobe_within_module(tk, mod)) {
697 /* Don't need to check busy - this should have gone. */712 /* Don't need to check busy - this should have gone. */
698 __unregister_trace_kprobe(tk);713 __unregister_trace_kprobe(tk);
699 ret = __register_trace_kprobe(tk);714 ret = register_module_trace_kprobe(mod, tk);
700 if (ret)715 if (ret)
701 pr_warn("Failed to re-register probe %s on %s: %d\n",716 pr_warn("Failed to re-register probe %s on %s: %d\n",
702 trace_probe_name(&tk->tp),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 return 0;762 return 0;
748}763}
749 764
750static unsigned int number_of_same_symbols(char *func_name)765static unsigned int number_of_same_symbols(const char *mod, const char *func_name)
751{766{
752 struct sym_count_ctx ctx = { .count = 0, .name = func_name };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 return ctx.count;774 return ctx.count;
759}775}
760 776
777static 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. */
799static 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
815static 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);
832out:
833 if (p)
834 *p = ':';
835 if (mod)
836 module_put(mod);
837 return ret;
838}
839
761static int trace_kprobe_entry_handler(struct kretprobe_instance *ri,840static int trace_kprobe_entry_handler(struct kretprobe_instance *ri,
762 struct pt_regs *regs);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 trace_probe_log_err(0, BAD_PROBE_ADDR);960 trace_probe_log_err(0, BAD_PROBE_ADDR);
882 goto parse_error;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 if (is_return)971 if (is_return)
885 ctx.flags |= TPARG_FL_RETURN;972 ctx.flags |= TPARG_FL_RETURN;
886 ret = kprobe_on_func_entry(NULL, symbol, offset);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 trace_probe_log_set_index(0);983 trace_probe_log_set_index(0);
922 if (event) {984 if (event) {
923 ret = traceprobe_parse_event_name(&event, &group, gbuf,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 char *event;1897 char *event;
1836 1898
1837 if (func) {1899 if (func) {
1838 unsigned int count;1900 ret = validate_probe_symbol(func);
1839 1901 if (ret)
1840 count = number_of_same_symbols(func);1902 return ERR_PTR(ret);
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);
1853 }1903 }
1854 1904
1855 /*1905 /*
@@ -2023,19 +2073,16 @@ static __init int kprobe_trace_self_tests_init(void) · 167 unmodified lines
2023 pr_info("Testing kprobe tracing: ");2073 pr_info("Testing kprobe tracing: ");
2024 2074
2025 ret = create_or_delete_trace_kprobe("p:testprobe kprobe_trace_selftest_target $stack $stack0 +0($stack)");2075 ret = create_or_delete_trace_kprobe("p:testprobe kprobe_trace_selftest_target $stack $stack0 +0($stack)");
2026 if (WARN_ON_ONCE(ret)) {2076 if (WARN_ONCE(ret, "error on probing function entry.")) {
2027 pr_warn("error on probing function entry.\n");
2028 warn++;2077 warn++;
2029 } else {2078 } else {
2030 /* Enable trace point */2079 /* Enable trace point */
2031 tk = find_trace_kprobe("testprobe", KPROBE_EVENT_SYSTEM);2080 tk = find_trace_kprobe("testprobe", KPROBE_EVENT_SYSTEM);
2032 if (WARN_ON_ONCE(tk == NULL)) {2081 if (WARN_ONCE(tk == NULL, "error on probing function entry.")) {
2033 pr_warn("error on getting new probe.\n");
2034 warn++;2082 warn++;
2035 } else {2083 } else {
2036 file = find_trace_probe_file(tk, top_trace_array());2084 file = find_trace_probe_file(tk, top_trace_array());
2037 if (WARN_ON_ONCE(file == NULL)) {2085 if (WARN_ONCE(file == NULL, "error on getting probe file.")) {
2038 pr_warn("error on getting probe file.\n");
2039 warn++;2086 warn++;
2040 } else2087 } else
2041 enable_trace_kprobe(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 ret = create_or_delete_trace_kprobe("r:testprobe2 kprobe_trace_selftest_target $retval");2093 ret = create_or_delete_trace_kprobe("r:testprobe2 kprobe_trace_selftest_target $retval");
2047 if (WARN_ON_ONCE(ret)) {2094 if (WARN_ONCE(ret, "error on probing function return.")) {
2048 pr_warn("error on probing function return.\n");
2049 warn++;2095 warn++;
2050 } else {2096 } else {
2051 /* Enable trace point */2097 /* Enable trace point */
2052 tk = find_trace_kprobe("testprobe2", KPROBE_EVENT_SYSTEM);2098 tk = find_trace_kprobe("testprobe2", KPROBE_EVENT_SYSTEM);
2053 if (WARN_ON_ONCE(tk == NULL)) {2099 if (WARN_ONCE(tk == NULL, "error on getting 2nd new probe.")) {
2054 pr_warn("error on getting 2nd new probe.\n");
2055 warn++;2100 warn++;
2056 } else {2101 } else {
2057 file = find_trace_probe_file(tk, top_trace_array());2102 file = find_trace_probe_file(tk, top_trace_array());
2058 if (WARN_ON_ONCE(file == NULL)) {2103 if (WARN_ONCE(file == NULL, "error on getting probe file.")) {
2059 pr_warn("error on getting probe file.\n");
2060 warn++;2104 warn++;
2061 } else2105 } else
2062 enable_trace_kprobe(2106 enable_trace_kprobe(
@@ -2079,18 +2123,15 @@ static __init int kprobe_trace_self_tests_init(void) · 16 unmodified lines
2079 2123
2080 /* Disable trace points before removing it */2124 /* Disable trace points before removing it */
2081 tk = find_trace_kprobe("testprobe", KPROBE_EVENT_SYSTEM);2125 tk = find_trace_kprobe("testprobe", KPROBE_EVENT_SYSTEM);
2082 if (WARN_ON_ONCE(tk == NULL)) {2126 if (WARN_ONCE(tk == NULL, "error on getting test probe.")) {
2083 pr_warn("error on getting test probe.\n");
2084 warn++;2127 warn++;
2085 } else {2128 } else {
2086 if (trace_kprobe_nhit(tk) != 1) {2129 if (WARN_ONCE(trace_kprobe_nhit(tk) != 1,
2087 pr_warn("incorrect number of testprobe hits\n");2130 "incorrect number of testprobe hits."))
2088 warn++;2131 warn++;
2089 }
2090 2132
2091 file = find_trace_probe_file(tk, top_trace_array());2133 file = find_trace_probe_file(tk, top_trace_array());
2092 if (WARN_ON_ONCE(file == NULL)) {2134 if (WARN_ONCE(file == NULL, "error on getting probe file.")) {
2093 pr_warn("error on getting probe file.\n");
2094 warn++;2135 warn++;
2095 } else2136 } else
2096 disable_trace_kprobe(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 tk = find_trace_kprobe("testprobe2", KPROBE_EVENT_SYSTEM);2141 tk = find_trace_kprobe("testprobe2", KPROBE_EVENT_SYSTEM);
2101 if (WARN_ON_ONCE(tk == NULL)) {2142 if (WARN_ONCE(tk == NULL, "error on getting 2nd test probe.")) {
2102 pr_warn("error on getting 2nd test probe.\n");
2103 warn++;2143 warn++;
2104 } else {2144 } else {
2105 if (trace_kprobe_nhit(tk) != 1) {2145 if (WARN_ONCE(trace_kprobe_nhit(tk) != 1,
2106 pr_warn("incorrect number of testprobe2 hits\n");2146 "incorrect number of testprobe2 hits."))
2107 warn++;2147 warn++;
2108 }
2109 2148
2110 file = find_trace_probe_file(tk, top_trace_array());2149 file = find_trace_probe_file(tk, top_trace_array());
2111 if (WARN_ON_ONCE(file == NULL)) {2150 if (WARN_ONCE(file == NULL, "error on getting probe file.")) {
2112 pr_warn("error on getting probe file.\n");
2113 warn++;2151 warn++;
2114 } else2152 } else
2115 disable_trace_kprobe(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 ret = create_or_delete_trace_kprobe("-:testprobe");2157 ret = create_or_delete_trace_kprobe("-:testprobe");
2120 if (WARN_ON_ONCE(ret)) {2158 if (WARN_ONCE(ret, "error on deleting a probe."))
2121 pr_warn("error on deleting a probe.\n");
2122 warn++;2159 warn++;
2123 }
2124 2160
2125 ret = create_or_delete_trace_kprobe("-:testprobe2");2161 ret = create_or_delete_trace_kprobe("-:testprobe2");
2126 if (WARN_ON_ONCE(ret)) {2162 if (WARN_ONCE(ret, "error on deleting a probe."))
2127 pr_warn("error on deleting a probe.\n");
2128 warn++;2163 warn++;
2129 }2164
2130 2165
2131end:2166end:
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 * Wait for the optimizer work to finish. Otherwise it might fiddle2168 * Wait for the optimizer work to finish. Otherwise it might fiddle
2139 * with probes in already freed __init text.2169 * with probes in already freed __init text.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t