Skip to content

Commit 3a3a11e

Browse files
keesgregkh
authored andcommitted
lkdtm: Use init_uts_ns.name instead of macros
Using generated/compile.h triggered a full LKDTM rebuild with every build. Avoid this by using the exported strings instead. Fixes: b866145 ("lkdtm: Add kernel version to failure hints") Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent bf9f243 commit 3a3a11e

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

drivers/misc/lkdtm/core.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/init.h>
2727
#include <linux/slab.h>
2828
#include <linux/debugfs.h>
29+
#include <linux/utsname.h>
2930

3031
#define DEFAULT_COUNT 10
3132

@@ -210,6 +211,8 @@ module_param(cpoint_count, int, 0644);
210211
MODULE_PARM_DESC(cpoint_count, " Crash Point Count, number of times the "\
211212
"crash point is to be hit to trigger action");
212213

214+
/* For test debug reporting. */
215+
char *lkdtm_kernel_info;
213216

214217
/* Return the crashtype number or NULL if the name is invalid */
215218
static const struct crashtype *find_crashtype(const char *name)
@@ -490,6 +493,11 @@ static int __init lkdtm_module_init(void)
490493
crash_count = cpoint_count;
491494
#endif
492495

496+
/* Common initialization. */
497+
lkdtm_kernel_info = kasprintf(GFP_KERNEL, "kernel (%s %s)",
498+
init_uts_ns.name.release,
499+
init_uts_ns.name.machine);
500+
493501
/* Handle test-specific initialization. */
494502
lkdtm_bugs_init(&recur_count);
495503
lkdtm_perms_init();
@@ -538,6 +546,8 @@ static void __exit lkdtm_module_exit(void)
538546
if (lkdtm_kprobe != NULL)
539547
unregister_kprobe(lkdtm_kprobe);
540548

549+
kfree(lkdtm_kernel_info);
550+
541551
pr_info("Crash point unregistered\n");
542552
}
543553

drivers/misc/lkdtm/lkdtm.h

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
#define pr_fmt(fmt) "lkdtm: " fmt
66

77
#include <linux/kernel.h>
8-
#include <generated/compile.h>
9-
#include <generated/utsrelease.h>
108

11-
#define LKDTM_KERNEL "kernel (" UTS_RELEASE " " UTS_MACHINE ")"
9+
extern char *lkdtm_kernel_info;
1210

1311
#define pr_expected_config(kconfig) \
1412
{ \
1513
if (IS_ENABLED(kconfig)) \
16-
pr_err("Unexpected! This " LKDTM_KERNEL " was built with " #kconfig "=y\n"); \
14+
pr_err("Unexpected! This %s was built with " #kconfig "=y\n", \
15+
lkdtm_kernel_info); \
1716
else \
18-
pr_warn("This is probably expected, since this " LKDTM_KERNEL " was built *without* " #kconfig "=y\n"); \
17+
pr_warn("This is probably expected, since this %s was built *without* " #kconfig "=y\n", \
18+
lkdtm_kernel_info); \
1919
}
2020

2121
#ifndef MODULE
@@ -25,24 +25,30 @@ int lkdtm_check_bool_cmdline(const char *param);
2525
if (IS_ENABLED(kconfig)) { \
2626
switch (lkdtm_check_bool_cmdline(param)) { \
2727
case 0: \
28-
pr_warn("This is probably expected, since this " LKDTM_KERNEL " was built with " #kconfig "=y but booted with '" param "=N'\n"); \
28+
pr_warn("This is probably expected, since this %s was built with " #kconfig "=y but booted with '" param "=N'\n", \
29+
lkdtm_kernel_info); \
2930
break; \
3031
case 1: \
31-
pr_err("Unexpected! This " LKDTM_KERNEL " was built with " #kconfig "=y and booted with '" param "=Y'\n"); \
32+
pr_err("Unexpected! This %s was built with " #kconfig "=y and booted with '" param "=Y'\n", \
33+
lkdtm_kernel_info); \
3234
break; \
3335
default: \
34-
pr_err("Unexpected! This " LKDTM_KERNEL " was built with " #kconfig "=y (and booted without '" param "' specified)\n"); \
36+
pr_err("Unexpected! This %s was built with " #kconfig "=y (and booted without '" param "' specified)\n", \
37+
lkdtm_kernel_info); \
3538
} \
3639
} else { \
3740
switch (lkdtm_check_bool_cmdline(param)) { \
3841
case 0: \
39-
pr_warn("This is probably expected, as this " LKDTM_KERNEL " was built *without* " #kconfig "=y and booted with '" param "=N'\n"); \
42+
pr_warn("This is probably expected, as this %s was built *without* " #kconfig "=y and booted with '" param "=N'\n", \
43+
lkdtm_kernel_info); \
4044
break; \
4145
case 1: \
42-
pr_err("Unexpected! This " LKDTM_KERNEL " was built *without* " #kconfig "=y but booted with '" param "=Y'\n"); \
46+
pr_err("Unexpected! This %s was built *without* " #kconfig "=y but booted with '" param "=Y'\n", \
47+
lkdtm_kernel_info); \
4348
break; \
4449
default: \
45-
pr_err("This is probably expected, since this " LKDTM_KERNEL " was built *without* " #kconfig "=y (and booted without '" param "' specified)\n"); \
50+
pr_err("This is probably expected, since this %s was built *without* " #kconfig "=y (and booted without '" param "' specified)\n", \
51+
lkdtm_kernel_info); \
4652
break; \
4753
} \
4854
} \

0 commit comments

Comments
 (0)