Skip to contentSkip to conversation

posix-cpu-timers: don't abuse lock_task_sighand() in handle_posix_cpu_timers()

PATCH Applied Oleg Nesterov 4 participants 9 messages Jul 4 – Jul 8 Posix clocks and timers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 posix-cpu-timers: don't abuse lock_task_sighand() in handle_posix_cpu_timers()

After the commit f90fff1e152d ("posix-cpu-timers: fix race between handle_posix_cpu_timers() and posix_cpu_timer_del()"), tsk->sighand is stable in handle_posix_cpu_timers(), so it can use the plain spin_lock_irqsave(&tsk->sighand->siglock).

---
 kernel/time/posix-cpu-timers.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
kernel/time/posix-cpu-timers.c +6 -3
index a7d3e8229c4b..d73d31c7994f 100644
@@ -1357,8 +1357,11 @@ static void handle_posix_cpu_timers(struct task_struct *tsk)
 	unsigned long flags, start;
 	LIST_HEAD(firing);
 
-	if (!lock_task_sighand(tsk, &flags))
-		return;
+	/*
+	 * tsk is current and ->sighand is stable, see the
+	 * tsk->exit_state check in run_posix_cpu_timers()
+	 */
+	spin_lock_irqsave(&tsk->sighand->siglock, flags);
 
 	do {
 		/*
@@ -1418,7 +1421,7 @@ static void handle_posix_cpu_timers(struct task_struct *tsk)
 	 * that gets the timer lock before we do will give it up and
 	 * spin until we've taken care of that timer below.
 	 */
-	unlock_task_sighand(tsk, &flags);
+	spin_unlock_irqrestore(&tsk->sighand->siglock, flags);
 
 	/*
 	 * Now that all the timers on our list have the firing flag,
Signature · 1 line
2.52.0
Reviewed-by on v1 1/1
#1 lore raw

hi oleg! I'm new to reviewing, so feel free to criticize.

This patch does LGTM,

Something else I'd like to bring up though, this file has already regressed once, 0bdd2ed4138e (dropping the exit_state check)

And then f90fff1e152d re adding it.

Would a WARN_ON_ONCE(tsk != current) be worth adding?

Not a blocker or anything, just a question!

For this patch,

Thanks!

#2 lore raw
Quoted 7 lines · Bradley Morgan

Something else I'd like to bring up though, this file has already regressed once, 0bdd2ed4138e (dropping the exit_state check)

And then f90fff1e152d re adding it.

Would a WARN_ON_ONCE(tsk != current) be worth adding?

Well may be, up to Thomas...

But note that the problem was not that tsk != current. The problem was that tsk->sighand could go away after unlock_task_sighand(tsk), even if tsk == current.

Quoted 1 line

Thanks,

Oleg.

#3 lore raw
In reply to Bradley Morgan

Hi Bradley,

FYI, this is another private message.

Quoted 2 lines · Bradley Morgan

hi oleg! I'm new to reviewing, so feel free to criticize.

This is fine...

But if you want to have a "real" practice, you can try to review V2 from Eric:

	[PATCH v2 00/14] Short circuit delivery for coredump signals
	https://lore.kernel.org/all/[email protected]/

I won't be able to take a look until the middle of the next week.

Quoted 1 line

Would a WARN_ON_ONCE(tsk != current) be worth adding?

See my reply on lkml. But since this message is private...

IOW. tsk->sighand must be stable here or we have more problems. Without this patch the "if (!lock_task_sighand(tsk, &flags))" check looks as if we can handle the case were ->sighand is not stable, but this is not true.

And. This patch is trivial, but it connects to other (under discussion, nontrivial) changes related to the wrong usage of lock_task_sighand() in posix-cpu-timers.c.

Quoted 3 lines

For this patch,

Thanks again,

Oleg.

#4 lore raw
Quoted 3 lines · Oleg Nesterov

Hi Bradley,

FYI, this is another private message.

It's not.

Quoted 29 lines · Bradley Morgan
Quoted 2 lines

hi oleg! I'm new to reviewing, so feel free to criticize.

This is fine...

But if you want to have a "real" practice, you can try to review V2 from Eric:

	[PATCH v2 00/14] Short circuit delivery for coredump signals
	https://lore.kernel.org/all/[email protected]/

I won't be able to take a look until the middle of the next week.

Quoted 1 line

Would a WARN_ON_ONCE(tsk != current) be worth adding?

See my reply on lkml. But since this message is private...

IOW. tsk->sighand must be stable here or we have more problems. Without this
patch the "if (!lock_task_sighand(tsk, &flags))" check looks as if we can handle
the case were ->sighand is not stable, but this is not true.

And. This patch is trivial, but it connects to other (under discussion, nontrivial)
changes related to the wrong usage of lock_task_sighand() in posix-cpu-timers.c.

Quoted 9 lines
Quoted 3 lines

For this patch,

Thanks again,

Oleg.

Thanks!

#5 lore raw
In reply to Oleg Nesterov
Quoted 4 lines · Oleg Nesterov

Hi Bradley,

FYI, this is another private message.

Damn ;)

FYI, it wasn't private. I've pressed 'g' by mistake.

Oleg.

Quoted 31 lines · Bradley Morgan
Quoted 2 lines

hi oleg! I'm new to reviewing, so feel free to criticize.

This is fine...

But if you want to have a "real" practice, you can try to review V2 from Eric:

	[PATCH v2 00/14] Short circuit delivery for coredump signals
	https://lore.kernel.org/all/[email protected]/

I won't be able to take a look until the middle of the next week.

Quoted 1 line

Would a WARN_ON_ONCE(tsk != current) be worth adding?

See my reply on lkml. But since this message is private...

IOW. tsk->sighand must be stable here or we have more problems. Without this patch the "if (!lock_task_sighand(tsk, &flags))" check looks as if we can handle the case were ->sighand is not stable, but this is not true.

And. This patch is trivial, but it connects to other (under discussion, nontrivial) changes related to the wrong usage of lock_task_sighand() in posix-cpu-timers.c.

Quoted 3 lines

For this patch,

Thanks again,

Oleg.

#6 lore raw
In reply to Oleg Nesterov
Quoted 8 lines · Oleg Nesterov

Hi Bradley,

FYI, this is another private message.

Quoted 2 lines · Bradley Morgan

hi oleg! I'm new to reviewing, so feel free to criticize.

Quoted 7 lines

This is fine...

But if you want to have a "real" practice, you can try to review V2 from Eric:

	[PATCH v2 00/14] Short circuit delivery for coredump signals
	https://lore.kernel.org/all/[email protected]/

If you CC me, I'll review anything! :)

Quoted 17 lines

I won't be able to take a look until the middle of the next week.

Quoted 1 line

Would a WARN_ON_ONCE(tsk != current) be worth adding?

See my reply on lkml. But since this message is private...

IOW. tsk->sighand must be stable here or we have more problems. Without this
patch the "if (!lock_task_sighand(tsk, &flags))" check looks as if we can handle
the case were ->sighand is not stable, but this is not true.

And. This patch is trivial, but it connects to other (under discussion, nontrivial)
changes related to the wrong usage of lock_task_sighand() in posix-cpu-timers.c.

Quoted 9 lines
Quoted 3 lines

For this patch,

Thanks again,

Oleg.

Thanks!

merge bot Applied
#7 lore raw

[tip: timers/core] posix-cpu-timers: Don't abuse lock_task_sighand() in handle_posix_cpu_timers()

In reply to Oleg Nesterov
The following commit has been merged into the timers/core branch of tip:

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     a73d7f98e41a96d6e1bcb0e731ab185d9d67878e
Gitweb:        https://git.kernel.org/tip/a73d7f98e41a96d6e1bcb0e731ab185d9d67878e
Author:        Oleg Nesterov <[email protected]>
AuthorDate:    Sat, 04 Jul 2026 13:09:36 +02:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Sun, 05 Jul 2026 12:15:22 +02:00

posix-cpu-timers: Don't abuse lock_task_sighand() in handle_posix_cpu_timers()

After commit f90fff1e152d ("posix-cpu-timers: fix race between handle_posix_cpu_timers() and posix_cpu_timer_del()"), tsk->sighand is stable in handle_posix_cpu_timers(), so it can use the plain spin_lock_irqsave(&tsk->sighand->siglock).

---
 kernel/time/posix-cpu-timers.c |  9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
kernel/time/posix-cpu-timers.c +6 -3
index 5e633d8..c8a9b52 100644
@@ -1300,8 +1300,11 @@ static void handle_posix_cpu_timers(struct task_struct *tsk)
 	unsigned long flags, start;
 	LIST_HEAD(firing);
 
-	if (!lock_task_sighand(tsk, &flags))
-		return;
+	/*
+	 * tsk is current and ->sighand is stable, see the
+	 * tsk->exit_state check in run_posix_cpu_timers()
+	 */
+	spin_lock_irqsave(&tsk->sighand->siglock, flags);
 
 	do {
 		/*
@@ -1361,7 +1364,7 @@ static void handle_posix_cpu_timers(struct task_struct *tsk)
 	 * that gets the timer lock before we do will give it up and
 	 * spin until we've taken care of that timer below.
 	 */
-	unlock_task_sighand(tsk, &flags);
+	spin_unlock_irqrestore(&tsk->sighand->siglock, flags);
 
 	/*
 	 * Now that all the timers on our list have the firing flag,
maintainer Reviewed-by on v1 1/1
#8 lore raw
In reply to Oleg Nesterov
Quoted 6 lines · Oleg Nesterov

After the commit f90fff1e152d ("posix-cpu-timers: fix race between handle_posix_cpu_timers() and posix_cpu_timer_del()"), tsk->sighand is stable in handle_posix_cpu_timers(), so it can use the plain spin_lock_irqsave(&tsk->sighand->siglock).

Quoted 35 lines
---
 kernel/time/posix-cpu-timers.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
kernel/time/posix-cpu-timers.c +6 -3
index a7d3e8229c4b..d73d31c7994f 100644
@@ -1357,8 +1357,11 @@ static void handle_posix_cpu_timers(struct task_struct *tsk)
 	unsigned long flags, start;
 	LIST_HEAD(firing);
 
-	if (!lock_task_sighand(tsk, &flags))
-		return;
+	/*
+	 * tsk is current and ->sighand is stable, see the
+	 * tsk->exit_state check in run_posix_cpu_timers()
+	 */
+	spin_lock_irqsave(&tsk->sighand->siglock, flags);
 
 	do {
 		/*
@@ -1418,7 +1421,7 @@ static void handle_posix_cpu_timers(struct task_struct *tsk)
 	 * that gets the timer lock before we do will give it up and
 	 * spin until we've taken care of that timer below.
 	 */
-	unlock_task_sighand(tsk, &flags);
+	spin_unlock_irqrestore(&tsk->sighand->siglock, flags);
 
 	/*
 	 * Now that all the timers on our list have the firing flag,
Signature · 1 line
2.52.0
Signature · 2 lines
Frederic Weisbecker
SUSE Labs