lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230822074547.8037-1-ming.qian@nxp.com>
Date:   Tue, 22 Aug 2023 15:45:47 +0800
From:   Ming Qian <ming.qian@....com>
To:     mingo@...hat.com, peterz@...radead.org, juri.lelli@...hat.com,
        vincent.guittot@...aro.org
Cc:     dietmar.eggemann@....com, rostedt@...dmis.org, bsegall@...gle.com,
        mgorman@...e.de, bristot@...hat.com, vschneid@...hat.com,
        eagle.zhou@....com, tao.jiang_2@....com, linux-imx@....com,
        linux-kernel@...r.kernel.org, linux-arm-kernel@...ts.infradead.org
Subject: [PATCH] wait: don't wake up freezable wait by freezing fake signal

kernel may try to wake up task with fake signal when freezing task,
if the task is waiting event using wait_event_freezable,
it's better to freeze the wait, instead of breaking it.

otherwise the caller may need to retry the wait,
maybe like below code:

	if (rc == -ERESTARTSYS && freezing(current)) {
		clear_thread_flag(TIF_SIGPENDING);
		goto again;
	}

Signed-off-by: TaoJiang <tao.jiang_2@....com>
Signed-off-by: Ming Qian <ming.qian@....com>
---
 include/linux/wait.h |  9 +++++++--
 kernel/sched/wait.c  | 14 ++++++++++++++
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/include/linux/wait.h b/include/linux/wait.h
index 5ec7739400f4..975ee67f259a 100644
--- a/include/linux/wait.h
+++ b/include/linux/wait.h
@@ -287,6 +287,7 @@ static inline void wake_up_pollfree(struct wait_queue_head *wq_head)
 	 (state & (TASK_INTERRUPTIBLE | TASK_WAKEKILL)))
 
 extern void init_wait_entry(struct wait_queue_entry *wq_entry, int flags);
+bool freezing_wait(struct wait_queue_entry *wq_entry, int state);
 
 /*
  * The below macro ___wait_event() has an explicit shadow of the __ret
@@ -314,8 +315,12 @@ extern void init_wait_entry(struct wait_queue_entry *wq_entry, int flags);
 			break;							\
 										\
 		if (___wait_is_interruptible(state) && __int) {			\
-			__ret = __int;						\
-			goto __out;						\
+			if (unlikely(freezing_wait(&__wq_entry, state))) {	\
+				clear_thread_flag(TIF_SIGPENDING);		\
+			} else {						\
+				__ret = __int;					\
+				goto __out;					\
+			}							\
 		}								\
 										\
 		cmd;								\
diff --git a/kernel/sched/wait.c b/kernel/sched/wait.c
index 802d98cf2de3..37c3b2bc1fc9 100644
--- a/kernel/sched/wait.c
+++ b/kernel/sched/wait.c
@@ -5,6 +5,8 @@
  * (C) 2004 Nadia Yvette Chambers, Oracle
  */
 
+#include <linux/freezer.h>
+
 void __init_waitqueue_head(struct wait_queue_head *wq_head, const char *name, struct lock_class_key *key)
 {
 	spin_lock_init(&wq_head->lock);
@@ -484,3 +486,15 @@ int woken_wake_function(struct wait_queue_entry *wq_entry, unsigned mode, int sy
 	return default_wake_function(wq_entry, mode, sync, key);
 }
 EXPORT_SYMBOL(woken_wake_function);
+
+bool freezing_wait(struct wait_queue_entry *wq_entry, int state)
+{
+	if (!(state & TASK_FREEZABLE))
+		return false;
+	if (fatal_signal_pending(wq_entry->private))
+		return false;
+	if (unlikely(freezing(wq_entry->private)))
+		return true;
+	return false;
+}
+EXPORT_SYMBOL(freezing_wait);
-- 
2.38.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ