* [PATCH] lkdtm: Use init_uts_ns.name instead of macros
@ 2021-09-01 23:34 Kees Cook
2021-09-09 15:49 ` Kees Cook
0 siblings, 1 reply; 6+ messages in thread
From: Kees Cook @ 2021-09-01 23:34 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Kees Cook, Arnd Bergmann, linux-kernel, linux-hardening
Using generated/compile.h triggered a full LKDTM rebuild with every
build. Avoid this by using the exported strings instead.
Fixes: b8661450bc7f ("lkdtm: Add kernel version to failure hints")
Signed-off-by: Kees Cook <keescook@chromium.org>
---
drivers/misc/lkdtm/core.c | 10 ++++++++++
drivers/misc/lkdtm/lkdtm.h | 28 +++++++++++++++++-----------
2 files changed, 27 insertions(+), 11 deletions(-)
diff --git a/drivers/misc/lkdtm/core.c b/drivers/misc/lkdtm/core.c
index 95b1c6800a22..fe6fd34b8caf 100644
--- a/drivers/misc/lkdtm/core.c
+++ b/drivers/misc/lkdtm/core.c
@@ -26,6 +26,7 @@
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/debugfs.h>
+#include <linux/utsname.h>
#define DEFAULT_COUNT 10
@@ -210,6 +211,8 @@ module_param(cpoint_count, int, 0644);
MODULE_PARM_DESC(cpoint_count, " Crash Point Count, number of times the "\
"crash point is to be hit to trigger action");
+/* For test debug reporting. */
+char *lkdtm_kernel_info;
/* Return the crashtype number or NULL if the name is invalid */
static const struct crashtype *find_crashtype(const char *name)
@@ -490,6 +493,11 @@ static int __init lkdtm_module_init(void)
crash_count = cpoint_count;
#endif
+ /* Common initialization. */
+ lkdtm_kernel_info = kasprintf(GFP_KERNEL, "kernel (%s %s)",
+ init_uts_ns.name.release,
+ init_uts_ns.name.machine);
+
/* Handle test-specific initialization. */
lkdtm_bugs_init(&recur_count);
lkdtm_perms_init();
@@ -538,6 +546,8 @@ static void __exit lkdtm_module_exit(void)
if (lkdtm_kprobe != NULL)
unregister_kprobe(lkdtm_kprobe);
+ kfree(lkdtm_kernel_info);
+
pr_info("Crash point unregistered\n");
}
diff --git a/drivers/misc/lkdtm/lkdtm.h b/drivers/misc/lkdtm/lkdtm.h
index d7d64d9765eb..c212a253edde 100644
--- a/drivers/misc/lkdtm/lkdtm.h
+++ b/drivers/misc/lkdtm/lkdtm.h
@@ -5,17 +5,17 @@
#define pr_fmt(fmt) "lkdtm: " fmt
#include <linux/kernel.h>
-#include <generated/compile.h>
-#include <generated/utsrelease.h>
-#define LKDTM_KERNEL "kernel (" UTS_RELEASE " " UTS_MACHINE ")"
+extern char *lkdtm_kernel_info;
#define pr_expected_config(kconfig) \
{ \
if (IS_ENABLED(kconfig)) \
- pr_err("Unexpected! This " LKDTM_KERNEL " was built with " #kconfig "=y\n"); \
+ pr_err("Unexpected! This %s was built with " #kconfig "=y\n", \
+ lkdtm_kernel_info); \
else \
- pr_warn("This is probably expected, since this " LKDTM_KERNEL " was built *without* " #kconfig "=y\n"); \
+ pr_warn("This is probably expected, since this %s was built *without* " #kconfig "=y\n", \
+ lkdtm_kernel_info); \
}
#ifndef MODULE
@@ -25,24 +25,30 @@ int lkdtm_check_bool_cmdline(const char *param);
if (IS_ENABLED(kconfig)) { \
switch (lkdtm_check_bool_cmdline(param)) { \
case 0: \
- pr_warn("This is probably expected, since this " LKDTM_KERNEL " was built with " #kconfig "=y but booted with '" param "=N'\n"); \
+ pr_warn("This is probably expected, since this %s was built with " #kconfig "=y but booted with '" param "=N'\n", \
+ lkdtm_kernel_info); \
break; \
case 1: \
- pr_err("Unexpected! This " LKDTM_KERNEL " was built with " #kconfig "=y and booted with '" param "=Y'\n"); \
+ pr_err("Unexpected! This %s was built with " #kconfig "=y and booted with '" param "=Y'\n", \
+ lkdtm_kernel_info); \
break; \
default: \
- pr_err("Unexpected! This " LKDTM_KERNEL " was built with " #kconfig "=y (and booted without '" param "' specified)\n"); \
+ pr_err("Unexpected! This %s was built with " #kconfig "=y (and booted without '" param "' specified)\n", \
+ lkdtm_kernel_info); \
} \
} else { \
switch (lkdtm_check_bool_cmdline(param)) { \
case 0: \
- pr_warn("This is probably expected, as this " LKDTM_KERNEL " was built *without* " #kconfig "=y and booted with '" param "=N'\n"); \
+ pr_warn("This is probably expected, as this %s was built *without* " #kconfig "=y and booted with '" param "=N'\n", \
+ lkdtm_kernel_info); \
break; \
case 1: \
- pr_err("Unexpected! This " LKDTM_KERNEL " was built *without* " #kconfig "=y but booted with '" param "=Y'\n"); \
+ pr_err("Unexpected! This %s was built *without* " #kconfig "=y but booted with '" param "=Y'\n", \
+ lkdtm_kernel_info); \
break; \
default: \
- pr_err("This is probably expected, since this " LKDTM_KERNEL " was built *without* " #kconfig "=y (and booted without '" param "' specified)\n"); \
+ pr_err("This is probably expected, since this %s was built *without* " #kconfig "=y (and booted without '" param "' specified)\n", \
+ lkdtm_kernel_info); \
break; \
} \
} \
--
2.30.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] lkdtm: Use init_uts_ns.name instead of macros
2021-09-01 23:34 [PATCH] lkdtm: Use init_uts_ns.name instead of macros Kees Cook
@ 2021-09-09 15:49 ` Kees Cook
2021-09-09 16:02 ` Greg Kroah-Hartman
0 siblings, 1 reply; 6+ messages in thread
From: Kees Cook @ 2021-09-09 15:49 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: Arnd Bergmann, linux-kernel, linux-hardening
On Wed, Sep 01, 2021 at 04:34:06PM -0700, Kees Cook wrote:
> Using generated/compile.h triggered a full LKDTM rebuild with every
> build. Avoid this by using the exported strings instead.
>
> Fixes: b8661450bc7f ("lkdtm: Add kernel version to failure hints")
> Signed-off-by: Kees Cook <keescook@chromium.org>
Hi Greg,
Your bot said "please wait, the merge window is open", but it'd be really
nice to get this into -rc1 to avoid annoying people doing rebuilds...
:)
-Kees
> ---
> drivers/misc/lkdtm/core.c | 10 ++++++++++
> drivers/misc/lkdtm/lkdtm.h | 28 +++++++++++++++++-----------
> 2 files changed, 27 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/misc/lkdtm/core.c b/drivers/misc/lkdtm/core.c
> index 95b1c6800a22..fe6fd34b8caf 100644
> --- a/drivers/misc/lkdtm/core.c
> +++ b/drivers/misc/lkdtm/core.c
> @@ -26,6 +26,7 @@
> #include <linux/init.h>
> #include <linux/slab.h>
> #include <linux/debugfs.h>
> +#include <linux/utsname.h>
>
> #define DEFAULT_COUNT 10
>
> @@ -210,6 +211,8 @@ module_param(cpoint_count, int, 0644);
> MODULE_PARM_DESC(cpoint_count, " Crash Point Count, number of times the "\
> "crash point is to be hit to trigger action");
>
> +/* For test debug reporting. */
> +char *lkdtm_kernel_info;
>
> /* Return the crashtype number or NULL if the name is invalid */
> static const struct crashtype *find_crashtype(const char *name)
> @@ -490,6 +493,11 @@ static int __init lkdtm_module_init(void)
> crash_count = cpoint_count;
> #endif
>
> + /* Common initialization. */
> + lkdtm_kernel_info = kasprintf(GFP_KERNEL, "kernel (%s %s)",
> + init_uts_ns.name.release,
> + init_uts_ns.name.machine);
> +
> /* Handle test-specific initialization. */
> lkdtm_bugs_init(&recur_count);
> lkdtm_perms_init();
> @@ -538,6 +546,8 @@ static void __exit lkdtm_module_exit(void)
> if (lkdtm_kprobe != NULL)
> unregister_kprobe(lkdtm_kprobe);
>
> + kfree(lkdtm_kernel_info);
> +
> pr_info("Crash point unregistered\n");
> }
>
> diff --git a/drivers/misc/lkdtm/lkdtm.h b/drivers/misc/lkdtm/lkdtm.h
> index d7d64d9765eb..c212a253edde 100644
> --- a/drivers/misc/lkdtm/lkdtm.h
> +++ b/drivers/misc/lkdtm/lkdtm.h
> @@ -5,17 +5,17 @@
> #define pr_fmt(fmt) "lkdtm: " fmt
>
> #include <linux/kernel.h>
> -#include <generated/compile.h>
> -#include <generated/utsrelease.h>
>
> -#define LKDTM_KERNEL "kernel (" UTS_RELEASE " " UTS_MACHINE ")"
> +extern char *lkdtm_kernel_info;
>
> #define pr_expected_config(kconfig) \
> { \
> if (IS_ENABLED(kconfig)) \
> - pr_err("Unexpected! This " LKDTM_KERNEL " was built with " #kconfig "=y\n"); \
> + pr_err("Unexpected! This %s was built with " #kconfig "=y\n", \
> + lkdtm_kernel_info); \
> else \
> - pr_warn("This is probably expected, since this " LKDTM_KERNEL " was built *without* " #kconfig "=y\n"); \
> + pr_warn("This is probably expected, since this %s was built *without* " #kconfig "=y\n", \
> + lkdtm_kernel_info); \
> }
>
> #ifndef MODULE
> @@ -25,24 +25,30 @@ int lkdtm_check_bool_cmdline(const char *param);
> if (IS_ENABLED(kconfig)) { \
> switch (lkdtm_check_bool_cmdline(param)) { \
> case 0: \
> - pr_warn("This is probably expected, since this " LKDTM_KERNEL " was built with " #kconfig "=y but booted with '" param "=N'\n"); \
> + pr_warn("This is probably expected, since this %s was built with " #kconfig "=y but booted with '" param "=N'\n", \
> + lkdtm_kernel_info); \
> break; \
> case 1: \
> - pr_err("Unexpected! This " LKDTM_KERNEL " was built with " #kconfig "=y and booted with '" param "=Y'\n"); \
> + pr_err("Unexpected! This %s was built with " #kconfig "=y and booted with '" param "=Y'\n", \
> + lkdtm_kernel_info); \
> break; \
> default: \
> - pr_err("Unexpected! This " LKDTM_KERNEL " was built with " #kconfig "=y (and booted without '" param "' specified)\n"); \
> + pr_err("Unexpected! This %s was built with " #kconfig "=y (and booted without '" param "' specified)\n", \
> + lkdtm_kernel_info); \
> } \
> } else { \
> switch (lkdtm_check_bool_cmdline(param)) { \
> case 0: \
> - pr_warn("This is probably expected, as this " LKDTM_KERNEL " was built *without* " #kconfig "=y and booted with '" param "=N'\n"); \
> + pr_warn("This is probably expected, as this %s was built *without* " #kconfig "=y and booted with '" param "=N'\n", \
> + lkdtm_kernel_info); \
> break; \
> case 1: \
> - pr_err("Unexpected! This " LKDTM_KERNEL " was built *without* " #kconfig "=y but booted with '" param "=Y'\n"); \
> + pr_err("Unexpected! This %s was built *without* " #kconfig "=y but booted with '" param "=Y'\n", \
> + lkdtm_kernel_info); \
> break; \
> default: \
> - pr_err("This is probably expected, since this " LKDTM_KERNEL " was built *without* " #kconfig "=y (and booted without '" param "' specified)\n"); \
> + pr_err("This is probably expected, since this %s was built *without* " #kconfig "=y (and booted without '" param "' specified)\n", \
> + lkdtm_kernel_info); \
> break; \
> } \
> } \
> --
> 2.30.2
>
--
Kees Cook
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] lkdtm: Use init_uts_ns.name instead of macros
2021-09-09 15:49 ` Kees Cook
@ 2021-09-09 16:02 ` Greg Kroah-Hartman
2021-09-09 16:08 ` Mark Brown
0 siblings, 1 reply; 6+ messages in thread
From: Greg Kroah-Hartman @ 2021-09-09 16:02 UTC (permalink / raw)
To: Kees Cook; +Cc: Arnd Bergmann, linux-kernel, linux-hardening
On Thu, Sep 09, 2021 at 08:49:57AM -0700, Kees Cook wrote:
> On Wed, Sep 01, 2021 at 04:34:06PM -0700, Kees Cook wrote:
> > Using generated/compile.h triggered a full LKDTM rebuild with every
> > build. Avoid this by using the exported strings instead.
> >
> > Fixes: b8661450bc7f ("lkdtm: Add kernel version to failure hints")
> > Signed-off-by: Kees Cook <keescook@chromium.org>
>
> Hi Greg,
>
> Your bot said "please wait, the merge window is open", but it'd be really
> nice to get this into -rc1 to avoid annoying people doing rebuilds...
>
> :)
I'm not supposed to be adding new patches to my tree during this period
of time in the merge window.
I can't see a rebuild locally here without this patch attached, so how
much of a problem is it right now?
And isn't -rc2 ok?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] lkdtm: Use init_uts_ns.name instead of macros
2021-09-09 16:02 ` Greg Kroah-Hartman
@ 2021-09-09 16:08 ` Mark Brown
2021-09-09 17:26 ` Kees Cook
0 siblings, 1 reply; 6+ messages in thread
From: Mark Brown @ 2021-09-09 16:08 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Kees Cook, Arnd Bergmann, linux-kernel, linux-hardening
[-- Attachment #1: Type: text/plain, Size: 359 bytes --]
On Thu, Sep 09, 2021 at 06:02:09PM +0200, Greg Kroah-Hartman wrote:
> I can't see a rebuild locally here without this patch attached, so how
> much of a problem is it right now?
It's triggering for me all the time here FWIW.
> And isn't -rc2 ok?
Lots of trees base off -rc1 so unless people change their workflow to
merge up -rc2 it'll impact submitters.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] lkdtm: Use init_uts_ns.name instead of macros
2021-09-09 16:08 ` Mark Brown
@ 2021-09-09 17:26 ` Kees Cook
2021-09-10 15:10 ` Greg Kroah-Hartman
0 siblings, 1 reply; 6+ messages in thread
From: Kees Cook @ 2021-09-09 17:26 UTC (permalink / raw)
To: Mark Brown
Cc: Greg Kroah-Hartman, Arnd Bergmann, linux-kernel, linux-hardening
On Thu, Sep 09, 2021 at 05:08:59PM +0100, Mark Brown wrote:
> On Thu, Sep 09, 2021 at 06:02:09PM +0200, Greg Kroah-Hartman wrote:
>
> > I can't see a rebuild locally here without this patch attached, so how
> > much of a problem is it right now?
>
> It's triggering for me all the time here FWIW.
Right, if you have CONFIG_LKDTM!=n it'll show up (e.g. with an
all*config build).
> > And isn't -rc2 ok?
>
> Lots of trees base off -rc1 so unless people change their workflow to
> merge up -rc2 it'll impact submitters.
Right, that's why I was suggesting it.
--
Kees Cook
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] lkdtm: Use init_uts_ns.name instead of macros
2021-09-09 17:26 ` Kees Cook
@ 2021-09-10 15:10 ` Greg Kroah-Hartman
0 siblings, 0 replies; 6+ messages in thread
From: Greg Kroah-Hartman @ 2021-09-10 15:10 UTC (permalink / raw)
To: Kees Cook; +Cc: Mark Brown, Arnd Bergmann, linux-kernel, linux-hardening
On Thu, Sep 09, 2021 at 10:26:18AM -0700, Kees Cook wrote:
> On Thu, Sep 09, 2021 at 05:08:59PM +0100, Mark Brown wrote:
> > On Thu, Sep 09, 2021 at 06:02:09PM +0200, Greg Kroah-Hartman wrote:
> >
> > > I can't see a rebuild locally here without this patch attached, so how
> > > much of a problem is it right now?
> >
> > It's triggering for me all the time here FWIW.
>
> Right, if you have CONFIG_LKDTM!=n it'll show up (e.g. with an
> all*config build).
>
> > > And isn't -rc2 ok?
> >
> > Lots of trees base off -rc1 so unless people change their workflow to
> > merge up -rc2 it'll impact submitters.
>
> Right, that's why I was suggesting it.
Ok, let me run it through 0-day right now and see if anything blows
up...
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-09-10 15:10 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-01 23:34 [PATCH] lkdtm: Use init_uts_ns.name instead of macros Kees Cook
2021-09-09 15:49 ` Kees Cook
2021-09-09 16:02 ` Greg Kroah-Hartman
2021-09-09 16:08 ` Mark Brown
2021-09-09 17:26 ` Kees Cook
2021-09-10 15:10 ` Greg Kroah-Hartman
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.