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: <62f3a734401016a387b59bda8ecd39252a8da849.1764272407.git.chris@chrisdown.name>
Date: Fri, 28 Nov 2025 03:43:12 +0800
From: Chris Down <chris@...isdown.name>
To: Petr Mladek <pmladek@...e.com>
Cc: linux-kernel@...r.kernel.org,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	Sergey Senozhatsky <senozhatsky@...omium.org>,
	Steven Rostedt <rostedt@...dmis.org>,
	John Ogness <john.ogness@...utronix.de>,
	Geert Uytterhoeven <geert@...ux-m68k.org>,
	Tony Lindgren <tony.lindgren@...ux.intel.com>, kernel-team@...com
Subject: [PATCH v8 01/21] printk: Fully resolve loglevel before deciding
 printk delay suppression

When printk_delay() is called from vprintk_emit(), the level argument
may be LOGLEVEL_DEFAULT (-1) if the loglevel was not explicitly provided
by the caller.

If printk_delay() relies on comparing level against the console loglevel
(e.g. for suppression), receiving -1 results in incorrect behaviour
because -1 is treated as a high priority (so not suppressed), causing
unnecessary delays for default-level messages.

Parse the format string prefix to resolve the actual loglevel before
passing it to printk_delay().

Signed-off-by: Chris Down <chris@...isdown.name>
---
 kernel/printk/printk.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 5aee9ffb16b9..f002744b9a90 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2179,6 +2179,32 @@ u16 printk_parse_prefix(const char *text, int *level,
 	return prefix_len;
 }
 
+/**
+ * printk_resolve_loglevel - Resolve the effective loglevel for a message
+ *
+ * @facility:	The log facility (0 for kernel messages)
+ * @level:	The initial loglevel, may be LOGLEVEL_DEFAULT
+ * @fmt:	The format string, potentially containing a loglevel prefix
+ *
+ * Determines the actual loglevel to use for a printk message. If the level
+ * is LOGLEVEL_DEFAULT and the facility indicates a kernel message, parses
+ * the format string prefix to extract an embedded loglevel. If no loglevel
+ * is found, falls back to the default_message_loglevel.
+ *
+ * Return: The resolved loglevel value
+ */
+static inline int printk_resolve_loglevel(int facility, int level,
+					  const char *fmt)
+{
+	if (facility == 0 && level == LOGLEVEL_DEFAULT && fmt)
+		printk_parse_prefix(fmt, &level, NULL);
+
+	if (level == LOGLEVEL_DEFAULT)
+		level = default_message_loglevel;
+
+	return level;
+}
+
 __printf(5, 0)
 static u16 printk_sprint(char *text, u16 size, int facility,
 			 enum printk_info_flags *flags, const char *fmt,
@@ -2394,7 +2420,7 @@ asmlinkage int vprintk_emit(int facility, int level,
 		ft.legacy_direct = false;
 	}
 
-	printk_delay(level);
+	printk_delay(printk_resolve_loglevel(facility, level, fmt));
 
 	printed_len = vprintk_store(facility, level, dev_info, fmt, args);
 
-- 
2.51.2


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ