[patch 33/45] signal: Provide posixtimer_sigqueue_init()

From: Thomas Gleixner
Date: Tue Jun 06 2023 - 10:40:35 EST


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@xxxxxxxxxxxxx>
---
include/linux/posix-timers.h | 1 +
kernel/signal.c | 11 +++++++++++
2 files changed, 12 insertions(+)

--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -168,6 +168,7 @@ static inline void posix_cputimers_rt_wa
}

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);

--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -1901,6 +1901,17 @@ void flush_itimer_signals(void)
spin_unlock_irqrestore(&tsk->sighand->siglock, flags);
}

+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);