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:   Fri, 15 Jun 2018 18:39:15 +0900
From:   Sergey Senozhatsky <sergey.senozhatsky.work@...il.com>
To:     Petr Mladek <pmladek@...e.com>,
        Steven Rostedt <rostedt@...dmis.org>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Jiri Slaby <jslaby@...e.com>
Cc:     Linus Torvalds <torvalds@...ux-foundation.org>,
        Peter Zijlstra <peterz@...radead.org>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Dmitry Vyukov <dvyukov@...gle.com>,
        linux-kernel@...r.kernel.org, linux-serial@...r.kernel.org,
        Sergey Senozhatsky <sergey.senozhatsky@...il.com>,
        Sergey Senozhatsky <sergey.senozhatsky.work@...il.com>
Subject: [RFC][PATCH 2/6] tty: add tty_port locking helpers

TTY port spin_lock is one of the locks that can cause a
printk-recursion deadlock, thus we need to lock it from
printk_safe context. E.g.

ioctl()
 tty_ioctl()
  spin_lock(&tty_port->lock)
   printk()
    call_console_drivers()
     foo_console_write()
      spin_lock(&uart_port->lock)
       tty_wakeup()
        spin_lock(&tty_port->lock)    << deadlock

This patch adds tty_port->lock helper macros which take care
of printk_safe context and redirect potentially unsafe printk()
calls to per-CPU buffers, which we flush later from safe a
context. The helper macros will turn the above mentioned deadlock
scenario into:

ioctl()
 tty_ioctl()
  printk_safe_enter()
   spin_lock(&tty_port->lock)
    printk()
     printk_safe_log_store()
      irq_work_queue()
   spin_unlock(&tty_port->lock)
  printk_safe_exit()

 IRQ
  printk_safe_flush_buffer()
   vprintk_deferred()

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@...il.com>
---
 include/linux/tty.h | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/include/linux/tty.h b/include/linux/tty.h
index c56e3978b00f..828f91ab680b 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -252,6 +252,30 @@ struct tty_port {
 	void 			*client_data;
 };
 
+#define tty_port_lock_irq(lock)				\
+	do {						\
+		printk_safe_enter_irq();		\
+		spin_lock(lock);			\
+	} while (0)
+
+#define tty_port_unlock_irq(lock)			\
+	do {						\
+		spin_unlock(lock);			\
+		printk_safe_exit_irq();			\
+	} while (0)
+
+#define tty_port_lock_irqsave(lock, flags)		\
+	do {						\
+		printk_safe_enter_irqsave(flags);	\
+		spin_lock(lock);			\
+	} while (0)
+
+#define tty_port_unlock_irqrestore(lock, flags)		\
+	do {						\
+		spin_unlock(lock);			\
+		printk_safe_exit_irqrestore(flags);	\
+	} while (0)
+
 /* tty_port::iflags bits -- use atomic bit ops */
 #define TTY_PORT_INITIALIZED	0	/* device is initialized */
 #define TTY_PORT_SUSPENDED	1	/* device is suspended */
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ