hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/arch/x86/kernel/unwind_frame.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 #include <linux/sched.h>
23 #include <linux/sched/task.h>
34 #include <linux/sched/task_stack.h>
....@@ -69,26 +70,11 @@
6970 }
7071 }
7172
72
-static size_t regs_size(struct pt_regs *regs)
73
-{
74
- /* x86_32 regs from kernel mode are two words shorter: */
75
- if (IS_ENABLED(CONFIG_X86_32) && !user_mode(regs))
76
- return sizeof(*regs) - 2*sizeof(long);
77
-
78
- return sizeof(*regs);
79
-}
80
-
8173 static bool in_entry_code(unsigned long ip)
8274 {
8375 char *addr = (char *)ip;
8476
85
- if (addr >= __entry_text_start && addr < __entry_text_end)
86
- return true;
87
-
88
- if (addr >= __irqentry_text_start && addr < __irqentry_text_end)
89
- return true;
90
-
91
- return false;
77
+ return addr >= __entry_text_start && addr < __entry_text_end;
9278 }
9379
9480 static inline unsigned long *last_frame(struct unwind_state *state)
....@@ -197,12 +183,6 @@
197183 }
198184 #endif
199185
200
-#ifdef CONFIG_X86_32
201
-#define KERNEL_REGS_SIZE (sizeof(struct pt_regs) - 2*sizeof(long))
202
-#else
203
-#define KERNEL_REGS_SIZE (sizeof(struct pt_regs))
204
-#endif
205
-
206186 static bool update_stack_state(struct unwind_state *state,
207187 unsigned long *next_bp)
208188 {
....@@ -213,7 +193,7 @@
213193 size_t len;
214194
215195 if (state->regs)
216
- prev_frame_end = (void *)state->regs + regs_size(state->regs);
196
+ prev_frame_end = (void *)state->regs + sizeof(*state->regs);
217197 else
218198 prev_frame_end = (void *)state->bp + FRAME_HEADER_SIZE;
219199
....@@ -221,7 +201,7 @@
221201 regs = decode_frame_pointer(next_bp);
222202 if (regs) {
223203 frame = (unsigned long *)regs;
224
- len = KERNEL_REGS_SIZE;
204
+ len = sizeof(*regs);
225205 state->got_irq = true;
226206 } else {
227207 frame = next_bp;
....@@ -243,14 +223,6 @@
243223 /* Make sure it only unwinds up and doesn't overlap the prev frame: */
244224 if (state->orig_sp && state->stack_info.type == prev_type &&
245225 frame < prev_frame_end)
246
- return false;
247
-
248
- /*
249
- * On 32-bit with user mode regs, make sure the last two regs are safe
250
- * to access:
251
- */
252
- if (IS_ENABLED(CONFIG_X86_32) && regs && user_mode(regs) &&
253
- !on_stack(info, frame, len + 2*sizeof(long)))
254226 return false;
255227
256228 /* Move state to the next frame: */
....@@ -297,13 +269,13 @@
297269 /*
298270 * kthreads (other than the boot CPU's idle thread) have some
299271 * partial regs at the end of their stack which were placed
300
- * there by copy_thread_tls(). But the regs don't have any
272
+ * there by copy_thread(). But the regs don't have any
301273 * useful information, so we can skip them.
302274 *
303275 * This user_mode() check is slightly broader than a PF_KTHREAD
304276 * check because it also catches the awkward situation where a
305277 * newly forked kthread transitions into a user task by calling
306
- * do_execve(), which eventually clears PF_KTHREAD.
278
+ * kernel_execve(), which eventually clears PF_KTHREAD.
307279 */
308280 if (!user_mode(regs))
309281 goto the_end;
....@@ -366,6 +338,9 @@
366338 if (IS_ENABLED(CONFIG_X86_32))
367339 goto the_end;
368340
341
+ if (state->task != current)
342
+ goto the_end;
343
+
369344 if (state->regs) {
370345 printk_deferred_once(KERN_WARNING
371346 "WARNING: kernel stack regs at %p in %s:%d has bad 'bp' value %p\n",
....@@ -411,10 +386,9 @@
411386 * Pretend that the frame is complete and that BP points to it, but save
412387 * the real BP so that we can use it when looking for the next frame.
413388 */
414
- if (regs && regs->ip == 0 &&
415
- (unsigned long *)kernel_stack_pointer(regs) >= first_frame) {
389
+ if (regs && regs->ip == 0 && (unsigned long *)regs->sp >= first_frame) {
416390 state->next_bp = bp;
417
- bp = ((unsigned long *)kernel_stack_pointer(regs)) - 1;
391
+ bp = ((unsigned long *)regs->sp) - 1;
418392 }
419393
420394 /* Initialize stack info and make sure the frame data is accessible: */