Skip to contentSkip to conversation

cobalt/posix/signal: Fix iteration over sigwaiters

PATCH Applied Jan Kiszka 1 participant 2 messages Jun 19, 2019 – Jun 21, 2019

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/1 cobalt/posix/signal: Fix iteration over sigwaiters

From: Jan Kiszka <[email protected]>

Using thread both as the iteration variable and the source of the list causes list_for_each_entry to derail after the first thread that has no hit. This could be triggered by sending a process a signal that was in sigwait, but not for that signal.

Fix this by using a stable list pointer.

---

I had already tagged 3.0.9, just not pushed yet - tag deleted again.

 kernel/cobalt/posix/signal.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
kernel/cobalt/posix/signal.c +4 -2
index 7e0eb52e99..e75ce2b693 100644
@@ -46,6 +46,7 @@ static int cobalt_signal_deliver(struct cobalt_thread *thread,
 {				/* nklocked, IRQs off */
 	struct cobalt_sigwait_context *swc;
 	struct xnthread_wait_context *wc;
+	struct list_head *sigwaiters;
 	int sig, ret;
 
 	sig = sigp->si.si_signo;
@@ -67,10 +68,11 @@ static int cobalt_signal_deliver(struct cobalt_thread *thread,
 	 * group, try to deliver to any thread from the same process
 	 * waiting for that signal.
 	 */
-	if (!group || list_empty(&thread->process->sigwaiters))
+	sigwaiters = &thread->process->sigwaiters;
+	if (!group || list_empty(sigwaiters))
 		return 0;
 
-	list_for_each_entry(thread, &thread->process->sigwaiters, signext) {
+	list_for_each_entry(thread, sigwaiters, signext) {
 		wc = xnthread_get_wait_context(&thread->threadbase);
 		swc = container_of(wc, struct cobalt_sigwait_context, wc);
 		if (sigismember(swc->set, sig))
Signature · 1 line
2.16.4
author Applied
#1 lore raw
Quoted 34 lines · Jan Kiszka via Xenomai

From: Jan Kiszka <[email protected]>

Using thread both as the iteration variable and the source of the list causes list_for_each_entry to derail after the first thread that has no hit. This could be triggered by sending a process a signal that was in sigwait, but not for that signal.

Fix this by using a stable list pointer.

---

I had already tagged 3.0.9, just not pushed yet - tag deleted again.

  kernel/cobalt/posix/signal.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
kernel/cobalt/posix/signal.c +1 -0
index 7e0eb52e99..e75ce2b693 100644
@@ -46,6 +46,7 @@ static int cobalt_signal_deliver(struct cobalt_thread *thread,
  {				/* nklocked, IRQs off */
  	struct cobalt_sigwait_context *swc;
  	struct xnthread_wait_context *wc;
+	struct list_head *sigwaiters;
  	int sig, ret;
 
  	sig = sigp->si.si_signo;
@@ -67,10 +68,11 @@ static int cobalt_signal_deliver(struct cobalt_thread *thread,
  	 * group, try to deliver to any thread from the same process
  	 * waiting for that signal.
  	 */

kernel/cobalt/posix/signal.c static int cobalt_signal_deliver(struct cobalt_thread *thread, · line 78

Quoted 10 lines
kernel/cobalt/posix/signal.c +3 -2
-	if (!group || list_empty(&thread->process->sigwaiters))
+	sigwaiters = &thread->process->sigwaiters;
+	if (!group || list_empty(sigwaiters))
  		return 0;
 
-	list_for_each_entry(thread, &thread->process->sigwaiters, signext) {
+	list_for_each_entry(thread, sigwaiters, signext) {
  		wc = xnthread_get_wait_context(&thread->threadbase);
  		swc = container_of(wc, struct cobalt_sigwait_context, wc);
  		if (sigismember(swc->set, sig))

Merged into master and stable.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux