summaryrefslogtreecommitdiff
path: root/include/linux/coredump.h
diff options
context:
space:
mode:
authorRoman Kisel <romank@linux.microsoft.com>2024-07-18 11:27:24 -0700
committerKees Cook <kees@kernel.org>2024-08-05 21:29:20 -0700
commitc114e9948c2b6a0b400266e59cc656b59e795bca (patch)
tree791b33c3f1d316e21358e3ae5820e50aa5c50dec /include/linux/coredump.h
parentde9c2c66ad8e787abec7c9d7eff4f8c3cdd28aed (diff)
downloadlinux-c114e9948c2b6a0b400266e59cc656b59e795bca.tar.gz
linux-c114e9948c2b6a0b400266e59cc656b59e795bca.tar.bz2
linux-c114e9948c2b6a0b400266e59cc656b59e795bca.zip
coredump: Standartize and fix logging
The coredump code does not log the process ID and the comm consistently, logs unescaped comm when it does log it, and does not always use the ratelimited logging. That makes it harder to analyze logs and puts the system at the risk of spamming the system log incase something crashes many times over and over again. Fix that by logging TGID and comm (escaped) consistently and using the ratelimited logging always. Signed-off-by: Roman Kisel <romank@linux.microsoft.com> Tested-by: Allen Pais <apais@linux.microsoft.com> Link: https://lore.kernel.org/r/20240718182743.1959160-2-romank@linux.microsoft.com Signed-off-by: Kees Cook <kees@kernel.org>
Diffstat (limited to 'include/linux/coredump.h')
-rw-r--r--include/linux/coredump.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/include/linux/coredump.h b/include/linux/coredump.h
index 0904ba010341..45e598fe3476 100644
--- a/include/linux/coredump.h
+++ b/include/linux/coredump.h
@@ -43,8 +43,30 @@ extern int dump_align(struct coredump_params *cprm, int align);
int dump_user_range(struct coredump_params *cprm, unsigned long start,
unsigned long len);
extern void do_coredump(const kernel_siginfo_t *siginfo);
+
+/*
+ * Logging for the coredump code, ratelimited.
+ * The TGID and comm fields are added to the message.
+ */
+
+#define __COREDUMP_PRINTK(Level, Format, ...) \
+ do { \
+ char comm[TASK_COMM_LEN]; \
+ \
+ get_task_comm(comm, current); \
+ printk_ratelimited(Level "coredump: %d(%*pE): " Format "\n", \
+ task_tgid_vnr(current), (int)strlen(comm), comm, ##__VA_ARGS__); \
+ } while (0) \
+
+#define coredump_report(fmt, ...) __COREDUMP_PRINTK(KERN_INFO, fmt, ##__VA_ARGS__)
+#define coredump_report_failure(fmt, ...) __COREDUMP_PRINTK(KERN_WARNING, fmt, ##__VA_ARGS__)
+
#else
static inline void do_coredump(const kernel_siginfo_t *siginfo) {}
+
+#define coredump_report(...)
+#define coredump_report_failure(...)
+
#endif
#if defined(CONFIG_COREDUMP) && defined(CONFIG_SYSCTL)