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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 5 Oct 2017 06:03:49 -0700
From:   tip-bot for Kees Cook <tipbot@...or.com>
To:     linux-tip-commits@...r.kernel.org
Cc:     linux@...ck-us.net, pmladek@...e.com, cmetcalf@...lanox.com,
        manish.chopra@...ium.com, oleg@...hat.com, hpa@...or.com,
        harish.patil@...ium.com, paulus@...ba.org,
        gregkh@...uxfoundation.org, benh@...nel.crashing.org,
        tj@...nel.org, kvalo@....qualcomm.com, ubraun@...ux.vnet.ibm.com,
        schwidefsky@...ibm.com, stefanr@...6.in-berlin.de,
        john.stultz@...aro.org, akpm@...ux-foundation.org,
        rjw@...ysocki.net, tglx@...utronix.de, mingo@...nel.org,
        ralf@...ux-mips.org, jwi@...ux.vnet.ibm.com, sre@...nel.org,
        viresh.kumar@...aro.org, linux-kernel@...r.kernel.org,
        jiangshanlai@...il.com, martin.petersen@...cle.com, pavel@....cz,
        sudipm.mukherjee@...il.com, sboyd@...eaurora.org, arnd@...db.de,
        mark.gross@...el.com, jejb@...ux.vnet.ibm.com,
        keescook@...omium.org, geert@...ux-m68k.org,
        heiko.carstens@...ibm.com, wim@...ana.be, len.brown@...el.com,
        mdr@....com, mpe@...erman.id.au
Subject: [tip:timers/core] timer: Convert schedule_timeout() to use
 from_timer()

Commit-ID:  58e1177b4cd10b0d358faf7d7ebb3779f98bc3ea
Gitweb:     https://git.kernel.org/tip/58e1177b4cd10b0d358faf7d7ebb3779f98bc3ea
Author:     Kees Cook <keescook@...omium.org>
AuthorDate: Wed, 4 Oct 2017 16:26:55 -0700
Committer:  Thomas Gleixner <tglx@...utronix.de>
CommitDate: Thu, 5 Oct 2017 15:01:16 +0200

timer: Convert schedule_timeout() to use from_timer()

In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new from_timer() helper and passing
the timer pointer explicitly. Since this special timer is on the stack, it
needs to have a wrapper structure to carry state once .data is eliminated.

Signed-off-by: Kees Cook <keescook@...omium.org>
Signed-off-by: Thomas Gleixner <tglx@...utronix.de>
Cc: linux-mips@...ux-mips.org
Cc: Petr Mladek <pmladek@...e.com>
Cc: Benjamin Herrenschmidt <benh@...nel.crashing.org>
Cc: Lai Jiangshan <jiangshanlai@...il.com>
Cc: Sebastian Reichel <sre@...nel.org>
Cc: Kalle Valo <kvalo@....qualcomm.com>
Cc: Paul Mackerras <paulus@...ba.org>
Cc: Pavel Machek <pavel@....cz>
Cc: linux1394-devel@...ts.sourceforge.net
Cc: Chris Metcalf <cmetcalf@...lanox.com>
Cc: linux-s390@...r.kernel.org
Cc: linux-wireless@...r.kernel.org
Cc: "James E.J. Bottomley" <jejb@...ux.vnet.ibm.com>
Cc: Wim Van Sebroeck <wim@...ana.be>
Cc: Michael Ellerman <mpe@...erman.id.au>
Cc: Ursula Braun <ubraun@...ux.vnet.ibm.com>
Cc: Geert Uytterhoeven <geert@...ux-m68k.org>
Cc: Viresh Kumar <viresh.kumar@...aro.org>
Cc: Harish Patil <harish.patil@...ium.com>
Cc: Guenter Roeck <linux@...ck-us.net>
Cc: Manish Chopra <manish.chopra@...ium.com>
Cc: Len Brown <len.brown@...el.com>
Cc: Arnd Bergmann <arnd@...db.de>
Cc: linux-pm@...r.kernel.org
Cc: Heiko Carstens <heiko.carstens@...ibm.com>
Cc: Tejun Heo <tj@...nel.org>
Cc: Julian Wiedmann <jwi@...ux.vnet.ibm.com>
Cc: John Stultz <john.stultz@...aro.org>
Cc: Mark Gross <mark.gross@...el.com>
Cc: "Rafael J. Wysocki" <rjw@...ysocki.net>
Cc: linux-watchdog@...r.kernel.org
Cc: linux-scsi@...r.kernel.org
Cc: "Martin K. Petersen" <martin.petersen@...cle.com>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: Stephen Boyd <sboyd@...eaurora.org>
Cc: Oleg Nesterov <oleg@...hat.com>
Cc: Ralf Baechle <ralf@...ux-mips.org>
Cc: Stefan Richter <stefanr@...6.in-berlin.de>
Cc: Michael Reed <mdr@....com>
Cc: netdev@...r.kernel.org
Cc: Martin Schwidefsky <schwidefsky@...ibm.com>
Cc: Andrew Morton <akpm@...ux-foundation.org>
Cc: linuxppc-dev@...ts.ozlabs.org
Cc: Sudip Mukherjee <sudipm.mukherjee@...il.com>
Link: https://lkml.kernel.org/r/1507159627-127660-2-git-send-email-keescook@chromium.org

---
 include/linux/timer.h |  8 ++++++++
 kernel/time/timer.c   | 26 +++++++++++++++++++-------
 2 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/include/linux/timer.h b/include/linux/timer.h
index 6383c52..5ef5c9e 100644
--- a/include/linux/timer.h
+++ b/include/linux/timer.h
@@ -179,6 +179,14 @@ static inline void timer_setup(struct timer_list *timer,
 		      (TIMER_DATA_TYPE)timer, flags);
 }
 
+static inline void timer_setup_on_stack(struct timer_list *timer,
+			       void (*callback)(struct timer_list *),
+			       unsigned int flags)
+{
+	__setup_timer_on_stack(timer, (TIMER_FUNC_TYPE)callback,
+			       (TIMER_DATA_TYPE)timer, flags);
+}
+
 #define from_timer(var, callback_timer, timer_fieldname) \
 	container_of(callback_timer, typeof(*var), timer_fieldname)
 
diff --git a/kernel/time/timer.c b/kernel/time/timer.c
index f2674a0..38613ce 100644
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -1668,9 +1668,20 @@ void run_local_timers(void)
 	raise_softirq(TIMER_SOFTIRQ);
 }
 
-static void process_timeout(unsigned long __data)
+/*
+ * Since schedule_timeout()'s timer is defined on the stack, it must store
+ * the target task on the stack as well.
+ */
+struct process_timer {
+	struct timer_list timer;
+	struct task_struct *task;
+};
+
+static void process_timeout(struct timer_list *t)
 {
-	wake_up_process((struct task_struct *)__data);
+	struct process_timer *timeout = from_timer(timeout, t, timer);
+
+	wake_up_process(timeout->task);
 }
 
 /**
@@ -1704,7 +1715,7 @@ static void process_timeout(unsigned long __data)
  */
 signed long __sched schedule_timeout(signed long timeout)
 {
-	struct timer_list timer;
+	struct process_timer timer;
 	unsigned long expire;
 
 	switch (timeout)
@@ -1738,13 +1749,14 @@ signed long __sched schedule_timeout(signed long timeout)
 
 	expire = timeout + jiffies;
 
-	setup_timer_on_stack(&timer, process_timeout, (unsigned long)current);
-	__mod_timer(&timer, expire, false);
+	timer.task = current;
+	timer_setup_on_stack(&timer.timer, process_timeout, 0);
+	__mod_timer(&timer.timer, expire, false);
 	schedule();
-	del_singleshot_timer_sync(&timer);
+	del_singleshot_timer_sync(&timer.timer);
 
 	/* Remove the timer from the object tracker */
-	destroy_timer_on_stack(&timer);
+	destroy_timer_on_stack(&timer.timer);
 
 	timeout = expire - jiffies;
 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ