hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/include/linux/tracehook.h
....@@ -1,11 +1,8 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
23 * Tracing hooks
34 *
45 * Copyright (C) 2008-2009 Red Hat, Inc. All rights reserved.
5
- *
6
- * This copyrighted material is made available to anyone wishing to use,
7
- * modify, copy, or redistribute it subject to the terms and conditions
8
- * of the GNU General Public License v.2.
96 *
107 * This file defines hook entry points called by core code where
118 * user tracing/debugging support might need to do something. These
....@@ -57,13 +54,15 @@
5754 /*
5855 * ptrace report for syscall entry and exit looks identical.
5956 */
60
-static inline int ptrace_report_syscall(struct pt_regs *regs)
57
+static inline int ptrace_report_syscall(struct pt_regs *regs,
58
+ unsigned long message)
6159 {
6260 int ptrace = current->ptrace;
6361
6462 if (!(ptrace & PT_PTRACED))
6563 return 0;
6664
65
+ current->ptrace_message = message;
6766 ptrace_notify(SIGTRAP | ((ptrace & PT_TRACESYSGOOD) ? 0x80 : 0));
6867
6968 /*
....@@ -76,6 +75,7 @@
7675 current->exit_code = 0;
7776 }
7877
78
+ current->ptrace_message = 0;
7979 return fatal_signal_pending(current);
8080 }
8181
....@@ -83,8 +83,8 @@
8383 * tracehook_report_syscall_entry - task is about to attempt a system call
8484 * @regs: user register state of current task
8585 *
86
- * This will be called if %TIF_SYSCALL_TRACE has been set, when the
87
- * current task has just entered the kernel for a system call.
86
+ * This will be called if %TIF_SYSCALL_TRACE or %TIF_SYSCALL_EMU have been set,
87
+ * when the current task has just entered the kernel for a system call.
8888 * Full user register state is available here. Changing the values
8989 * in @regs can affect the system call number and arguments to be tried.
9090 * It is safe to block here, preventing the system call from beginning.
....@@ -101,7 +101,7 @@
101101 static inline __must_check int tracehook_report_syscall_entry(
102102 struct pt_regs *regs)
103103 {
104
- return ptrace_report_syscall(regs);
104
+ return ptrace_report_syscall(regs, PTRACE_EVENTMSG_SYSCALL_ENTRY);
105105 }
106106
107107 /**
....@@ -123,15 +123,10 @@
123123 */
124124 static inline void tracehook_report_syscall_exit(struct pt_regs *regs, int step)
125125 {
126
- if (step) {
127
- siginfo_t info;
128
- clear_siginfo(&info);
129
- user_single_step_siginfo(current, regs, &info);
130
- force_sig_info(SIGTRAP, &info, current);
131
- return;
132
- }
133
-
134
- ptrace_report_syscall(regs);
126
+ if (step)
127
+ user_single_step_report(regs);
128
+ else
129
+ ptrace_report_syscall(regs, PTRACE_EVENTMSG_SYSCALL_EXIT);
135130 }
136131
137132 /**
....@@ -183,17 +178,47 @@
183178 */
184179 static inline void tracehook_notify_resume(struct pt_regs *regs)
185180 {
181
+ clear_thread_flag(TIF_NOTIFY_RESUME);
186182 /*
187
- * The caller just cleared TIF_NOTIFY_RESUME. This barrier
188
- * pairs with task_work_add()->set_notify_resume() after
183
+ * This barrier pairs with task_work_add()->set_notify_resume() after
189184 * hlist_add_head(task->task_works);
190185 */
191186 smp_mb__after_atomic();
192187 if (unlikely(current->task_works))
193188 task_work_run();
194189
190
+#ifdef CONFIG_KEYS_REQUEST_CACHE
191
+ if (unlikely(current->cached_requested_key)) {
192
+ key_put(current->cached_requested_key);
193
+ current->cached_requested_key = NULL;
194
+ }
195
+#endif
196
+
195197 mem_cgroup_handle_over_high();
196198 blkcg_maybe_throttle_current();
197199 }
198200
201
+/*
202
+ * called by exit_to_user_mode_loop() if ti_work & _TIF_NOTIFY_SIGNAL. This
203
+ * is currently used by TWA_SIGNAL based task_work, which requires breaking
204
+ * wait loops to ensure that task_work is noticed and run.
205
+ */
206
+static inline void tracehook_notify_signal(void)
207
+{
208
+ clear_thread_flag(TIF_NOTIFY_SIGNAL);
209
+ smp_mb__after_atomic();
210
+ if (current->task_works)
211
+ task_work_run();
212
+}
213
+
214
+/*
215
+ * Called when we have work to process from exit_to_user_mode_loop()
216
+ */
217
+static inline void set_notify_signal(struct task_struct *task)
218
+{
219
+ if (!test_and_set_tsk_thread_flag(task, TIF_NOTIFY_SIGNAL) &&
220
+ !wake_up_state(task, TASK_INTERRUPTIBLE))
221
+ kick_process(task);
222
+}
223
+
199224 #endif /* <linux/tracehook.h> */