Skip to contentSkip to conversation

signal: re-arm ignored periodic POSIX timers when handler is installed in do_sigaction()

PATCH In review Hui Peng 2 participants 2 messages Sep 19 – Sep 20

lore
Share & tools
lore

Hui Peng

author
#0 lore raw

PATCH 1/1 signal: re-arm ignored periodic POSIX timers when handler is installed in do_sigaction()

When a periodic POSIX timer fires while its target signal is ignored (e.g. default SIGCONT/SIGCHLD/SIGURG/SIGWINCH or SIG_IGN), the signal is dropped without advancing or queueing the timer's sigqueue, leaving the periodic timer stalled even after userspace installs a signal handler via sigaction(). Check and re-arm any pending ignored POSIX timers on the thread group when do_sigaction() transitions a signal out of the ignored state.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
Assisted-by LLM

---

kernel/signal.c +2 -2
index ec30550951ec..49ba188296c4 100644
@@ -4351,7 +4351,7 @@ int do_sigaction(int sig, struct k_sigaction *act, struct k_sigaction *oact)
 	sigaction_compat_abi(act, oact);
 
 	if (act) {
-		bool was_ignored = k->sa.sa_handler == SIG_IGN;
+		bool was_ignored = sig_task_ignored(p, sig, false);
 
 		sigdelsetmask(&act->sa.sa_mask,
 			      sigmask(SIGKILL) | sigmask(SIGSTOP));
@@ -4367,7 +4367,7 @@ int do_sigaction(int sig, struct k_sigaction *act, struct k_sigaction *oact)
 		 *   (for example, SIGCHLD), shall cause the pending signal to
 		 *   be discarded, whether or not it is blocked"
 		 */
-		if (sig_handler_ignored(sig_handler(p, sig), sig)) {
+		if (sig_task_ignored(p, sig, false)) {
 			sigemptyset(&mask);
 			sigaddset(&mask, sig);
 			flush_sigqueue_mask(p, &mask, &p->signal->shared_pending);
#1 lore raw
Quoted 10 lines · Hui Peng

When a periodic POSIX timer fires while its target signal is ignored (e.g. default SIGCONT/SIGCHLD/SIGURG/SIGWINCH or SIG_IGN), the signal is dropped without advancing or queueing the timer's sigqueue, leaving the periodic timer stalled even after userspace installs a signal handler via sigaction(). Check and re-arm any pending ignored POSIX timers on the thread group when do_sigaction() transitions a signal out of the ignored state.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")

Well, It was supposed to have been fixed by caf77435dd8a ("signal: Handle ignored signals in do_sigaction(action != SIG_IGN)") and other commits in that series...

Do you have a test-case?

Oleg.

Quoted 26 lines
Assisted-by LLM

---

kernel/signal.c +2 -2
index ec30550951ec..49ba188296c4 100644
@@ -4351,7 +4351,7 @@ int do_sigaction(int sig, struct k_sigaction *act, struct k_sigaction *oact)
 	sigaction_compat_abi(act, oact);
 
 	if (act) {
-		bool was_ignored = k->sa.sa_handler == SIG_IGN;
+		bool was_ignored = sig_task_ignored(p, sig, false);
 
 		sigdelsetmask(&act->sa.sa_mask,
 			      sigmask(SIGKILL) | sigmask(SIGSTOP));
@@ -4367,7 +4367,7 @@ int do_sigaction(int sig, struct k_sigaction *act, struct k_sigaction *oact)
 		 *   (for example, SIGCHLD), shall cause the pending signal to
 		 *   be discarded, whether or not it is blocked"
 		 */
-		if (sig_handler_ignored(sig_handler(p, sig), sig)) {
+		if (sig_task_ignored(p, sig, false)) {
 			sigemptyset(&mask);
 			sigaddset(&mask, sig);
 			flush_sigqueue_mask(p, &mask, &p->signal->shared_pending);