Skip to content

Commit b1f6f16

Browse files
soleenkees
authored andcommitted
printk: honor the max_reason field in kmsg_dumper
kmsg_dump() allows to dump kmesg buffer for various system events: oops, panic, reboot, etc. It provides an interface to register a callback call for clients, and in that callback interface there is a field "max_reason", but it was getting ignored when set to any "reason" higher than KMSG_DUMP_OOPS unless "always_kmsg_dump" was passed as kernel parameter. Allow clients to actually control their "max_reason", and keep the current behavior when "max_reason" is not set. Signed-off-by: Pavel Tatashin <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Reviewed-by: Petr Mladek <[email protected]> Signed-off-by: Kees Cook <[email protected]>
1 parent 6d3cf96 commit b1f6f16

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

include/linux/kmsg_dump.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ enum kmsg_dump_reason {
2626
KMSG_DUMP_OOPS,
2727
KMSG_DUMP_EMERG,
2828
KMSG_DUMP_SHUTDOWN,
29+
KMSG_DUMP_MAX
2930
};
3031

3132
/**

kernel/printk/printk.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3157,12 +3157,19 @@ void kmsg_dump(enum kmsg_dump_reason reason)
31573157
struct kmsg_dumper *dumper;
31583158
unsigned long flags;
31593159

3160-
if ((reason > KMSG_DUMP_OOPS) && !always_kmsg_dump)
3161-
return;
3162-
31633160
rcu_read_lock();
31643161
list_for_each_entry_rcu(dumper, &dump_list, list) {
3165-
if (dumper->max_reason && reason > dumper->max_reason)
3162+
enum kmsg_dump_reason max_reason = dumper->max_reason;
3163+
3164+
/*
3165+
* If client has not provided a specific max_reason, default
3166+
* to KMSG_DUMP_OOPS, unless always_kmsg_dump was set.
3167+
*/
3168+
if (max_reason == KMSG_DUMP_UNDEF) {
3169+
max_reason = always_kmsg_dump ? KMSG_DUMP_MAX :
3170+
KMSG_DUMP_OOPS;
3171+
}
3172+
if (reason > max_reason)
31663173
continue;
31673174

31683175
/* initialize iterator with data about the stored records */

0 commit comments

Comments
 (0)