]> git.baikalelectronics.ru Git - kernel.git/commitdiff
task_work: Call tracehook_notify_signal from get_signal on all architectures
authorEric W. Biederman <ebiederm@xmission.com>
Wed, 9 Feb 2022 15:51:14 +0000 (09:51 -0600)
committerEric W. Biederman <ebiederm@xmission.com>
Thu, 10 Mar 2022 22:51:36 +0000 (16:51 -0600)
Always handle TIF_NOTIFY_SIGNAL in get_signal.  With commit 35d0b389f3b2
("task_work: unconditionally run task_work from get_signal()") always
calling task_work_run all of the work of tracehook_notify_signal is
already happening except clearing TIF_NOTIFY_SIGNAL.

Factor clear_notify_signal out of tracehook_notify_signal and use it in
get_signal so that get_signal only needs one call of task_work_run.

To keep the semantics in sync update xfer_to_guest_mode_work (which
does not call get_signal) to call tracehook_notify_signal if either
_TIF_SIGPENDING or _TIF_NOTIFY_SIGNAL.

Reviewed-by: Kees Cook <keescook@chromium.org>
Link: https://lkml.kernel.org/r/20220309162454.123006-8-ebiederm@xmission.com
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
arch/s390/kernel/signal.c
arch/x86/kernel/signal.c
include/linux/entry-common.h
include/linux/tracehook.h
kernel/entry/common.c
kernel/entry/kvm.c
kernel/signal.c

index 307f5d99514d70d811fbf800dec48164bdd2cb87..ea9e5e8182cd326fb35d039d0e7124f846f7c3b0 100644 (file)
@@ -453,7 +453,7 @@ static void handle_signal(struct ksignal *ksig, sigset_t *oldset,
  * stack-frames in one go after that.
  */
 
-void arch_do_signal_or_restart(struct pt_regs *regs, bool has_signal)
+void arch_do_signal_or_restart(struct pt_regs *regs)
 {
        struct ksignal ksig;
        sigset_t *oldset = sigmask_to_save();
@@ -466,7 +466,7 @@ void arch_do_signal_or_restart(struct pt_regs *regs, bool has_signal)
        current->thread.system_call =
                test_pt_regs_flag(regs, PIF_SYSCALL) ? regs->int_code : 0;
 
-       if (has_signal && get_signal(&ksig)) {
+       if (get_signal(&ksig)) {
                /* Whee!  Actually deliver the signal.  */
                if (current->thread.system_call) {
                        regs->int_code = current->thread.system_call;
index ec71e06ae364b864335b585d8515866d86eb9b09..de3d5b5724d8a0682751d63ab3c227cf32a3af5a 100644 (file)
@@ -861,11 +861,11 @@ static inline unsigned long get_nr_restart_syscall(const struct pt_regs *regs)
  * want to handle. Thus you cannot kill init even with a SIGKILL even by
  * mistake.
  */
-void arch_do_signal_or_restart(struct pt_regs *regs, bool has_signal)
+void arch_do_signal_or_restart(struct pt_regs *regs)
 {
        struct ksignal ksig;
 
-       if (has_signal && get_signal(&ksig)) {
+       if (get_signal(&ksig)) {
                /* Whee! Actually deliver the signal.  */
                handle_signal(&ksig, regs);
                return;
index 9efbdda61f7aac37c9d36006568f8aff06d47ba9..3537fd25f14ec3c6d4ce73fee327c663728833be 100644 (file)
@@ -257,7 +257,7 @@ static __always_inline void arch_exit_to_user_mode(void) { }
  *
  * Invoked from exit_to_user_mode_loop().
  */
-void arch_do_signal_or_restart(struct pt_regs *regs, bool has_signal);
+void arch_do_signal_or_restart(struct pt_regs *regs);
 
 /**
  * exit_to_user_mode - Fixup state when exiting to user mode
index fa834a22e86e7b53c7e662b1c113dbd1052c798e..b44a7820c4684ea3309afd593e4a4afe5c49fb9c 100644 (file)
@@ -106,6 +106,12 @@ static inline void tracehook_notify_resume(struct pt_regs *regs)
        rseq_handle_notify_resume(NULL, regs);
 }
 
+static inline void clear_notify_signal(void)
+{
+       clear_thread_flag(TIF_NOTIFY_SIGNAL);
+       smp_mb__after_atomic();
+}
+
 /*
  * called by exit_to_user_mode_loop() if ti_work & _TIF_NOTIFY_SIGNAL. This
  * is currently used by TWA_SIGNAL based task_work, which requires breaking
@@ -113,8 +119,7 @@ static inline void tracehook_notify_resume(struct pt_regs *regs)
  */
 static inline void tracehook_notify_signal(void)
 {
-       clear_thread_flag(TIF_NOTIFY_SIGNAL);
-       smp_mb__after_atomic();
+       clear_notify_signal();
        if (task_work_pending(current))
                task_work_run();
 }
index f0b1daa1e8da8ba14e7e5b1a82466cdc7915b26c..79eaf9b4b10d1504b42b39de8a4032323f438228 100644 (file)
@@ -139,15 +139,7 @@ void noinstr exit_to_user_mode(void)
 }
 
 /* Workaround to allow gradual conversion of architecture code */
-void __weak arch_do_signal_or_restart(struct pt_regs *regs, bool has_signal) { }
-
-static void handle_signal_work(struct pt_regs *regs, unsigned long ti_work)
-{
-       if (ti_work & _TIF_NOTIFY_SIGNAL)
-               tracehook_notify_signal();
-
-       arch_do_signal_or_restart(regs, ti_work & _TIF_SIGPENDING);
-}
+void __weak arch_do_signal_or_restart(struct pt_regs *regs) { }
 
 static unsigned long exit_to_user_mode_loop(struct pt_regs *regs,
                                            unsigned long ti_work)
@@ -170,7 +162,7 @@ static unsigned long exit_to_user_mode_loop(struct pt_regs *regs,
                        klp_update_patch_state(current);
 
                if (ti_work & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL))
-                       handle_signal_work(regs, ti_work);
+                       arch_do_signal_or_restart(regs);
 
                if (ti_work & _TIF_NOTIFY_RESUME)
                        tracehook_notify_resume(regs);
index 96d476e06c7777d6d6412ea180255e03910d6792..cabf36a489e40a57285c2d33c952913b4a2d8f54 100644 (file)
@@ -8,7 +8,7 @@ static int xfer_to_guest_mode_work(struct kvm_vcpu *vcpu, unsigned long ti_work)
        do {
                int ret;
 
-               if (ti_work & _TIF_NOTIFY_SIGNAL)
+               if (ti_work & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL))
                        tracehook_notify_signal();
 
                if (ti_work & _TIF_SIGPENDING) {
index 3b4cf25fb9b3a573a0e6ee6f0866f2f6e37fa99d..8632b88982c9b5102511e6b90940d9f9c9900160 100644 (file)
@@ -2626,20 +2626,12 @@ bool get_signal(struct ksignal *ksig)
        struct signal_struct *signal = current->signal;
        int signr;
 
+       clear_notify_signal();
        if (unlikely(task_work_pending(current)))
                task_work_run();
 
-       /*
-        * For non-generic architectures, check for TIF_NOTIFY_SIGNAL so
-        * that the arch handlers don't all have to do it. If we get here
-        * without TIF_SIGPENDING, just exit after running signal work.
-        */
-       if (!IS_ENABLED(CONFIG_GENERIC_ENTRY)) {
-               if (test_thread_flag(TIF_NOTIFY_SIGNAL))
-                       tracehook_notify_signal();
-               if (!task_sigpending(current))
-                       return false;
-       }
+       if (!task_sigpending(current))
+               return false;
 
        if (unlikely(uprobe_deny_signal()))
                return false;