]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
signal: Provide posixtimer_sigqueue_init()
authorThomas Gleixner <tglx@linutronix.de>
Tue, 5 Nov 2024 08:14:39 +0000 (09:14 +0100)
committerThomas Gleixner <tglx@linutronix.de>
Thu, 7 Nov 2024 01:14:44 +0000 (02:14 +0100)
To cure the SIG_IGN handling for posix interval timers, the preallocated
sigqueue needs to be embedded into struct k_itimer to prevent life time
races of all sorts.

Provide a new function to initialize the embedded sigqueue to prepare for
that.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Frederic Weisbecker <frederic@kernel.org>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/all/20241105064213.450427515@linutronix.de
include/linux/posix-timers.h
kernel/signal.c

index 9740fd0c2933f83d5cd6f1739049491fc80505ca..200098d27cc04065f216aacf18520f0d16732aaa 100644 (file)
@@ -12,6 +12,7 @@
 
 struct kernel_siginfo;
 struct task_struct;
+struct sigqueue;
 struct k_itimer;
 
 static inline clockid_t make_process_cpuclock(const unsigned int pid,
@@ -106,6 +107,7 @@ static inline void posix_cputimers_rt_watchdog(struct posix_cputimers *pct,
 }
 
 void posixtimer_rearm_itimer(struct task_struct *p);
+bool posixtimer_init_sigqueue(struct sigqueue *q);
 bool posixtimer_deliver_signal(struct kernel_siginfo *info);
 void posixtimer_free_timer(struct k_itimer *timer);
 
index dbd42471cf03064deba7c941465d8f49f8d144a6..911ed3ab479e753d218497e084a63114d524332b 100644 (file)
@@ -1905,6 +1905,17 @@ void flush_itimer_signals(void)
        __flush_itimer_signals(&tsk->signal->shared_pending);
 }
 
+bool posixtimer_init_sigqueue(struct sigqueue *q)
+{
+       struct ucounts *ucounts = sig_get_ucounts(current, -1, 0);
+
+       if (!ucounts)
+               return false;
+       clear_siginfo(&q->info);
+       __sigqueue_init(q, ucounts, SIGQUEUE_PREALLOC);
+       return true;
+}
+
 struct sigqueue *sigqueue_alloc(void)
 {
        return __sigqueue_alloc(-1, current, GFP_KERNEL, 0, SIGQUEUE_PREALLOC);