1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
From: John Ogness <john.ogness@linutronix.de>
Date: Sun, 17 Feb 2019 03:11:20 +0100
Subject: [PATCH] printk: only allow kernel to emergency message
Origin: https://www.kernel.org/pub/linux/kernel/projects/rt/5.0/older/patches-5.0.10-rt7.tar.xz
Emergency messages exist as a mechanism for the kernel to
communicate critical information to users. It is not meant for
use by userspace. Only allow facility=0 messages to be
processed by the emergency message code.
Signed-off-by: John Ogness <john.ogness@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
kernel/printk/printk.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1700,7 +1700,8 @@ static void printk_write_history(struct
* The console_lock must be held.
*/
static void call_console_drivers(u64 seq, const char *ext_text, size_t ext_len,
- const char *text, size_t len, int level)
+ const char *text, size_t len, int level,
+ int facility)
{
struct console *con;
@@ -1720,13 +1721,14 @@ static void call_console_drivers(u64 seq
con->wrote_history = 1;
con->printk_seq = seq - 1;
}
- if (con->write_atomic && level < emergency_console_loglevel) {
+ if (con->write_atomic && level < emergency_console_loglevel &&
+ facility == 0) {
/* skip emergency messages, already printed */
if (con->printk_seq < seq)
con->printk_seq = seq;
continue;
}
- if (con->flags & CON_BOOT) {
+ if (con->flags & CON_BOOT && facility == 0) {
/* skip emergency messages, already printed */
if (con->printk_seq < seq)
con->printk_seq = seq;
@@ -1894,7 +1896,11 @@ asmlinkage int vprintk_emit(int facility
* - text points to beginning of text
* - there is room before text for prefix
*/
- printk_emergency(rbuf, level & 7, ts_nsec, cpu, text, text_len);
+ if (facility == 0) {
+ /* only the kernel can create emergency messages */
+ printk_emergency(rbuf, level & 7, ts_nsec, cpu,
+ text, text_len);
+ }
if ((lflags & LOG_CONT) || !(lflags & LOG_NEWLINE)) {
cont_add(ctx, cpu, facility, level, lflags, text, text_len);
@@ -2657,8 +2663,8 @@ static int printk_kthread_func(void *dat
&len, printk_time);
console_lock();
- call_console_drivers(master_seq, ext_text,
- ext_len, text, len, msg->level);
+ call_console_drivers(master_seq, ext_text, ext_len, text, len,
+ msg->level, msg->facility);
if (len > 0 || ext_len > 0)
printk_delay(msg->level);
console_unlock();
|