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
678678 }
679679
680680 #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+
681696 /* Module notifier call back, checking event on the module */
682697 static int trace_kprobe_module_callback(struct notifier_block *nb,
683698 unsigned long val, void *data)
@@ -696,7 +711,7 @@ static int trace_kprobe_module_callback(struct notifier_block *nb, · 12 unmodified lines
696711 if (trace_kprobe_within_module(tk, mod)) {
697712 /* Don't need to check busy - this should have gone. */
698713 __unregister_trace_kprobe(tk);
699− ret = __register_trace_kprobe(tk);
714+ ret = register_module_trace_kprobe(mod, tk);
700715 if (ret)
701716 pr_warn("Failed to re-register probe %s on %s: %d\n",
702717 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
747762 return 0;
748763 }
749764
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)
751766 {
752767 struct sym_count_ctx ctx = { .count = 0, .name = func_name };
753768
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);
755771
756− module_kallsyms_on_each_symbol(NULL, count_mod_symbols, &ctx);
772+ module_kallsyms_on_each_symbol(mod, count_mod_symbols, &ctx);
757773
758774 return ctx.count;
759775 }
760776
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+
761840 static int trace_kprobe_entry_handler(struct kretprobe_instance *ri,
762841 struct pt_regs *regs);
763842
@@ -881,6 +960,14 @@ static int __trace_kprobe_create(int argc, const char *argv[]) · 117 unmodified lines
881960 trace_probe_log_err(0, BAD_PROBE_ADDR);
882961 goto parse_error;
883962 }
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+ }
884971 if (is_return)
885972 ctx.flags |= TPARG_FL_RETURN;
886973 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
893980 }
894981 }
895982
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−
921983 trace_probe_log_set_index(0);
922984 if (event) {
923985 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
18351897 char *event;
18361898
18371899 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);
18531903 }
18541904
18551905 /*
@@ -2023,19 +2073,16 @@ static __init int kprobe_trace_self_tests_init(void) · 167 unmodified lines
20232073 pr_info("Testing kprobe tracing: ");
20242074
20252075 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.")) {
20282077 warn++;
20292078 } else {
20302079 /* Enable trace point */
20312080 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.")) {
20342082 warn++;
20352083 } else {
20362084 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.")) {
20392086 warn++;
20402087 } else
20412088 enable_trace_kprobe(
@@ -2044,19 +2091,16 @@ static __init int kprobe_trace_self_tests_init(void) · 2 unmodified lines
20442091 }
20452092
20462093 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.")) {
20492095 warn++;
20502096 } else {
20512097 /* Enable trace point */
20522098 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.")) {
20552100 warn++;
20562101 } else {
20572102 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.")) {
20602104 warn++;
20612105 } else
20622106 enable_trace_kprobe(
@@ -2079,18 +2123,15 @@ static __init int kprobe_trace_self_tests_init(void) · 16 unmodified lines
20792123
20802124 /* Disable trace points before removing it */
20812125 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.")) {
20842127 warn++;
20852128 } 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."))
20882131 warn++;
2089− }
20902132
20912133 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.")) {
20942135 warn++;
20952136 } else
20962137 disable_trace_kprobe(
@@ -2098,18 +2139,15 @@ static __init int kprobe_trace_self_tests_init(void) · 1 unmodified line
20982139 }
20992140
21002141 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.")) {
21032143 warn++;
21042144 } 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."))
21072147 warn++;
2108− }
21092148
21102149 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.")) {
21132151 warn++;
21142152 } else
21152153 disable_trace_kprobe(
@@ -2117,23 +2155,15 @@ static __init int kprobe_trace_self_tests_init(void) · 1 unmodified line
21172155 }
21182156
21192157 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."))
21222159 warn++;
2123− }
21242160
21252161 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."))
21282163 warn++;
2129− }
2164+
21302165
21312166 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− }
21372167 /*
21382168 * Wait for the optimizer work to finish. Otherwise it might fiddle
21392169 * 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