Skip to content

Commit 0e20cd3

Browse files
committed
posix-timers: Handle ignored list on delete and exit
To handle posix timer signals on sigaction(SIG_IGN) properly, the timers will be queued on a separate ignored list. Add the necessary cleanup code for timer_delete() and exit_itimers(). Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Frederic Weisbecker <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lore.kernel.org/all/[email protected]
1 parent 69f032c commit 0e20cd3

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

include/linux/posix-timers.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ static inline void posix_cputimers_init_work(void) { }
152152

153153
/**
154154
* struct k_itimer - POSIX.1b interval timer structure.
155-
* @list: List head for binding the timer to signals->posix_timers
155+
* @list: List node for binding the timer to tsk::signal::posix_timers
156+
* @ignored_list: List node for tracking ignored timers in tsk::signal::ignored_posix_timers
156157
* @t_hash: Entry in the posix timer hash table
157158
* @it_lock: Lock protecting the timer
158159
* @kclock: Pointer to the k_clock struct handling this timer
@@ -176,6 +177,7 @@ static inline void posix_cputimers_init_work(void) { }
176177
*/
177178
struct k_itimer {
178179
struct hlist_node list;
180+
struct hlist_node ignored_list;
179181
struct hlist_node t_hash;
180182
spinlock_t it_lock;
181183
const struct k_clock *kclock;

kernel/time/posix-timers.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,18 @@ int common_timer_del(struct k_itimer *timer)
10271027
return 0;
10281028
}
10291029

1030+
/*
1031+
* If the deleted timer is on the ignored list, remove it and
1032+
* drop the associated reference.
1033+
*/
1034+
static inline void posix_timer_cleanup_ignored(struct k_itimer *tmr)
1035+
{
1036+
if (!hlist_unhashed(&tmr->ignored_list)) {
1037+
hlist_del_init(&tmr->ignored_list);
1038+
posixtimer_putref(tmr);
1039+
}
1040+
}
1041+
10301042
static inline int timer_delete_hook(struct k_itimer *timer)
10311043
{
10321044
const struct k_clock *kc = timer->kclock;
@@ -1059,6 +1071,7 @@ SYSCALL_DEFINE1(timer_delete, timer_t, timer_id)
10591071

10601072
spin_lock(&current->sighand->siglock);
10611073
hlist_del(&timer->list);
1074+
posix_timer_cleanup_ignored(timer);
10621075
spin_unlock(&current->sighand->siglock);
10631076
/*
10641077
* A concurrent lookup could check timer::it_signal lockless. It
@@ -1110,6 +1123,8 @@ static void itimer_delete(struct k_itimer *timer)
11101123
}
11111124
hlist_del(&timer->list);
11121125

1126+
posix_timer_cleanup_ignored(timer);
1127+
11131128
/*
11141129
* Setting timer::it_signal to NULL is technically not required
11151130
* here as nothing can access the timer anymore legitimately via
@@ -1142,6 +1157,19 @@ void exit_itimers(struct task_struct *tsk)
11421157
/* The timers are not longer accessible via tsk::signal */
11431158
while (!hlist_empty(&timers))
11441159
itimer_delete(hlist_entry(timers.first, struct k_itimer, list));
1160+
1161+
/*
1162+
* There should be no timers on the ignored list. itimer_delete() has
1163+
* mopped them up.
1164+
*/
1165+
if (!WARN_ON_ONCE(!hlist_empty(&tsk->signal->ignored_posix_timers)))
1166+
return;
1167+
1168+
hlist_move_list(&tsk->signal->ignored_posix_timers, &timers);
1169+
while (!hlist_empty(&timers)) {
1170+
posix_timer_cleanup_ignored(hlist_entry(timers.first, struct k_itimer,
1171+
ignored_list));
1172+
}
11451173
}
11461174

11471175
SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,

0 commit comments

Comments
 (0)