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]
Message-ID: <402f0cbc3a573503c7cc794113aa5137ed7f276c.1705331453.git.sreenath.vijayan@sony.com>
Date: Wed, 17 Jan 2024 15:42:19 +0530
From: Sreenath Vijayan <sreenath.vijayan@...y.com>
To: john.ogness@...utronix.de, corbet@....net, gregkh@...uxfoundation.org,
        jirislaby@...nel.org, rdunlap@...radead.org, pmladek@...e.com
Cc: rostedt@...dmis.org, senozhatsky@...omium.org, linux-doc@...r.kernel.org,
        linux-kernel@...r.kernel.org, linux-serial@...r.kernel.org,
        taichi.shimoyashiki@...y.com, daniel.palmer@...y.com,
        anandakumar.balasubramaniam@...y.com, sreenath.vijayan@...y.com
Subject: [PATCH v3 1/2] printk: Add function to dump printk buffer directly to consoles

It is useful to be able to dump the printk buffer directly to
consoles in some situations so as to not flood the buffer.
This needs access to private items of printk like PRINTK_MESSAGE_MAX.
Add function in printk.c to accomplish this.

Suggested-by: John Ogness <john.ogness@...utronix.de>
Signed-off-by: Sreenath Vijayan <sreenath.vijayan@...y.com>
Signed-off-by: Shimoyashiki Taichi <taichi.shimoyashiki@...y.com>
---
 include/linux/printk.h |  4 ++++
 kernel/printk/printk.c | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/include/linux/printk.h b/include/linux/printk.h
index 8ef499ab3c1e..0896745f31e2 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -192,6 +192,7 @@ void show_regs_print_info(const char *log_lvl);
 extern asmlinkage void dump_stack_lvl(const char *log_lvl) __cold;
 extern asmlinkage void dump_stack(void) __cold;
 void printk_trigger_flush(void);
+void dump_printk_buffer(void);
 #else
 static inline __printf(1, 0)
 int vprintk(const char *s, va_list args)
@@ -271,6 +272,9 @@ static inline void dump_stack(void)
 static inline void printk_trigger_flush(void)
 {
 }
+static inline void dump_printk_buffer(void)
+{
+}
 #endif
 
 #ifdef CONFIG_SMP
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index f2444b581e16..5b11fb377f8f 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -4259,6 +4259,39 @@ void kmsg_dump_rewind(struct kmsg_dump_iter *iter)
 }
 EXPORT_SYMBOL_GPL(kmsg_dump_rewind);
 
+/**
+ * Dump the printk ring buffer directly to consoles
+ */
+void dump_printk_buffer(void)
+{
+	struct kmsg_dump_iter iter;
+	struct console *con;
+	char *buf;
+	size_t len;
+	int cookie;
+
+	buf = kmalloc(PRINTK_MESSAGE_MAX, GFP_KERNEL);
+	if (!buf)
+		return;
+
+	kmsg_dump_rewind(&iter);
+	while (kmsg_dump_get_line(&iter, 1, buf, PRINTK_MESSAGE_MAX, &len)) {
+		/*
+		 * Since using printk() or pr_*() will append the message to the
+		 * printk ring buffer, they cannot be used to display the retrieved
+		 * message. Hence console_write() of serial drivers is used.
+		 */
+		console_lock();
+		cookie = console_srcu_read_lock();
+		for_each_console_srcu(con) {
+			if ((console_srcu_read_flags(con) & CON_ENABLED) && con->write)
+				con->write(con, buf, len);
+		}
+		console_srcu_read_unlock(cookie);
+		console_unlock();
+	}
+	kfree(buf);
+}
 #endif
 
 #ifdef CONFIG_SMP
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ