Skip to content

Commit f10f048

Browse files
committed
Merge tag 'for-linus-rseq' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull rseq fixes from Paolo Bonzini: "A fix for a bug with restartable sequences and KVM. KVM's handling of TIF_NOTIFY_RESUME, e.g. for task migration, clears the flag without informing rseq and leads to stale data in userspace's rseq struct" * tag 'for-linus-rseq' of git://git.kernel.org/pub/scm/virt/kvm/kvm: KVM: selftests: Remove __NR_userfaultfd syscall fallback KVM: selftests: Add a test for KVM_RUN+rseq to detect task migration bugs tools: Move x86 syscall number fallbacks to .../uapi/ entry: rseq: Call rseq_handle_notify_resume() in tracehook_notify_resume() KVM: rseq: Update rseq when processing NOTIFY_RESUME on xfer to KVM guest
2 parents 9bc62af + 2da4a23 commit f10f048

File tree

13 files changed

+258
-22
lines changed

13 files changed

+258
-22
lines changed

arch/arm/kernel/signal.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,6 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
628628
uprobe_notify_resume(regs);
629629
} else {
630630
tracehook_notify_resume(regs);
631-
rseq_handle_notify_resume(NULL, regs);
632631
}
633632
}
634633
local_irq_disable();

arch/arm64/kernel/signal.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -940,10 +940,8 @@ void do_notify_resume(struct pt_regs *regs, unsigned long thread_flags)
940940
if (thread_flags & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL))
941941
do_signal(regs);
942942

943-
if (thread_flags & _TIF_NOTIFY_RESUME) {
943+
if (thread_flags & _TIF_NOTIFY_RESUME)
944944
tracehook_notify_resume(regs);
945-
rseq_handle_notify_resume(NULL, regs);
946-
}
947945

948946
if (thread_flags & _TIF_FOREIGN_FPSTATE)
949947
fpsimd_restore_current_state();

arch/csky/kernel/signal.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,6 @@ asmlinkage void do_notify_resume(struct pt_regs *regs,
260260
if (thread_info_flags & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL))
261261
do_signal(regs);
262262

263-
if (thread_info_flags & _TIF_NOTIFY_RESUME) {
263+
if (thread_info_flags & _TIF_NOTIFY_RESUME)
264264
tracehook_notify_resume(regs);
265-
rseq_handle_notify_resume(NULL, regs);
266-
}
267265
}

arch/mips/kernel/signal.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -906,10 +906,8 @@ asmlinkage void do_notify_resume(struct pt_regs *regs, void *unused,
906906
if (thread_info_flags & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL))
907907
do_signal(regs);
908908

909-
if (thread_info_flags & _TIF_NOTIFY_RESUME) {
909+
if (thread_info_flags & _TIF_NOTIFY_RESUME)
910910
tracehook_notify_resume(regs);
911-
rseq_handle_notify_resume(NULL, regs);
912-
}
913911

914912
user_enter();
915913
}

arch/powerpc/kernel/signal.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,8 @@ void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags)
293293
do_signal(current);
294294
}
295295

296-
if (thread_info_flags & _TIF_NOTIFY_RESUME) {
296+
if (thread_info_flags & _TIF_NOTIFY_RESUME)
297297
tracehook_notify_resume(regs);
298-
rseq_handle_notify_resume(NULL, regs);
299-
}
300298
}
301299

302300
static unsigned long get_tm_stackpointer(struct task_struct *tsk)

include/linux/tracehook.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ static inline void tracehook_notify_resume(struct pt_regs *regs)
197197

198198
mem_cgroup_handle_over_high();
199199
blkcg_maybe_throttle_current();
200+
201+
rseq_handle_notify_resume(NULL, regs);
200202
}
201203

202204
/*

kernel/entry/common.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,8 @@ static unsigned long exit_to_user_mode_loop(struct pt_regs *regs,
171171
if (ti_work & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL))
172172
handle_signal_work(regs, ti_work);
173173

174-
if (ti_work & _TIF_NOTIFY_RESUME) {
174+
if (ti_work & _TIF_NOTIFY_RESUME)
175175
tracehook_notify_resume(regs);
176-
rseq_handle_notify_resume(NULL, regs);
177-
}
178176

179177
/* Architecture specific TIF work */
180178
arch_exit_to_user_mode_work(regs, ti_work);

kernel/rseq.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,17 @@ void __rseq_handle_notify_resume(struct ksignal *ksig, struct pt_regs *regs)
282282

283283
if (unlikely(t->flags & PF_EXITING))
284284
return;
285-
ret = rseq_ip_fixup(regs);
286-
if (unlikely(ret < 0))
287-
goto error;
285+
286+
/*
287+
* regs is NULL if and only if the caller is in a syscall path. Skip
288+
* fixup and leave rseq_cs as is so that rseq_sycall() will detect and
289+
* kill a misbehaving userspace on debug kernels.
290+
*/
291+
if (regs) {
292+
ret = rseq_ip_fixup(regs);
293+
if (unlikely(ret < 0))
294+
goto error;
295+
}
288296
if (unlikely(rseq_update_cpu_id(t)))
289297
goto error;
290298
return;

tools/arch/x86/include/asm/unistd_64.h renamed to tools/arch/x86/include/uapi/asm/unistd_64.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
/* SPDX-License-Identifier: GPL-2.0 */
2-
#ifndef __NR_userfaultfd
3-
#define __NR_userfaultfd 282
4-
#endif
52
#ifndef __NR_perf_event_open
63
# define __NR_perf_event_open 298
74
#endif

0 commit comments

Comments
 (0)