--- zzzz-none-000/linux-5.15.111/kernel/signal.c 2023-05-11 14:00:40.000000000 +0000 +++ puma7-arm-6670-761/linux-5.15.111/kernel/signal.c 2024-02-07 09:28:08.000000000 +0000 @@ -45,6 +45,7 @@ #include #include #include +#include #define CREATE_TRACE_POINTS #include @@ -1068,6 +1069,37 @@ return (sig < SIGRTMIN) && sigismember(&signals->signal, sig); } +static void avm_trace_critical_init_signals(kernel_siginfo_t *info, + struct task_struct *t) +{ + /* + * HAX: Busybox init shuts down the system on some signals. + * Take note of processes that are sending such signals. + * + * This really should be handled in user space, but... user space on a + * Fritzbox has currently no means by itself to write persistent logs, + * traversing parent processes is a pain outside the kernel, and it's + * just simpler to maintain here rather than in the busybox init. + */ + + if (!IS_ENABLED(CONFIG_AVM_TRACE_INIT_SIGNALS)) + return; + + if (likely(!is_global_init(t))) + return; + + switch (info->si_signo) { + case SIGTERM: + case SIGUSR1: + case SIGUSR2: + case SIGPWR: + pr_notice("Task (pid %d) is sending signal #%d to init!\n", + task_pid_nr(current), + info->si_signo); + show_parent_tasks_cmdlines(current); + } +} + static int __send_signal(int sig, struct kernel_siginfo *info, struct task_struct *t, enum pid_type type, bool force) { @@ -1182,6 +1214,7 @@ complete_signal(sig, t, type); ret: trace_signal_generate(sig, info, t, type != PIDTYPE_PID, result); + avm_trace_critical_init_signals(info, t); return ret; } @@ -1699,6 +1732,13 @@ force_sig(SIGSEGV); } +int +kill_proc(pid_t pid, int sig, int priv) +{ + return kill_proc_info(sig, __si_special(priv), pid); +} +EXPORT_SYMBOL(kill_proc); + int force_sig_fault_to_task(int sig, int code, void __user *addr ___ARCH_SI_IA64(int imm, unsigned int flags, unsigned long isr) , struct task_struct *t) @@ -1997,6 +2037,7 @@ result = TRACE_SIGNAL_DELIVERED; out: trace_signal_generate(sig, &q->info, t, type != PIDTYPE_PID, result); + avm_trace_critical_init_signals(&q->info, t); unlock_task_sighand(t, &flags); ret: rcu_read_unlock();