Message ID | 1d87f0d5a282d9e8d14d408ac6d63462129f524c.1603372719.git.andreyknvl@google.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | kasan: hardware tag-based mode for production use on arm64 | expand |
On Thu, Oct 22, 2020 at 3:19 PM Andrey Konovalov <andreyknvl@google.com> wrote: > > Tag-based KASAN modes are fully initialized with kasan_init_tags(), > while the generic mode only requireds kasan_init(). Move the > initialization message for tag-based modes into kasan_init_tags(). > > Also fix pr_fmt() usage for KASAN code: generic mode doesn't need it, Why doesn't it need it? What's the difference with tag modes? > tag-based modes should use "kasan:" instead of KBUILD_MODNAME. With generic KASAN I currently see: [ 0.571473][ T0] kasan: KernelAddressSanitizer initialized So KBUILD_MODNAME somehow works. Is there some difference between files? > Signed-off-by: Andrey Konovalov <andreyknvl@google.com> > Link: https://linux-review.googlesource.com/id/Idfd1e50625ffdf42dfc3dbf7455b11bd200a0a49 > --- > arch/arm64/mm/kasan_init.c | 3 +++ > mm/kasan/generic.c | 2 -- > mm/kasan/hw_tags.c | 4 ++++ > mm/kasan/sw_tags.c | 4 +++- > 4 files changed, 10 insertions(+), 3 deletions(-) > > diff --git a/arch/arm64/mm/kasan_init.c b/arch/arm64/mm/kasan_init.c > index b6b9d55bb72e..8f17fa834b62 100644 > --- a/arch/arm64/mm/kasan_init.c > +++ b/arch/arm64/mm/kasan_init.c > @@ -290,5 +290,8 @@ void __init kasan_init(void) > { > kasan_init_shadow(); > kasan_init_depth(); > +#if defined(CONFIG_KASAN_GENERIC) > + /* CONFIG_KASAN_SW/HW_TAGS also requires kasan_init_tags(). */ A bit cleaner way may be to introduce kasan_init_early() and kasan_init_late(). Late() will do tag init and always print the message. > pr_info("KernelAddressSanitizer initialized\n"); > +#endif > } > diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c > index de6b3f03a023..d259e4c3aefd 100644 > --- a/mm/kasan/generic.c > +++ b/mm/kasan/generic.c > @@ -9,8 +9,6 @@ > * Andrey Konovalov <andreyknvl@gmail.com> > */ > > -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt > - > #include <linux/export.h> > #include <linux/interrupt.h> > #include <linux/init.h> > diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c > index 0128062320d5..b372421258c8 100644 > --- a/mm/kasan/hw_tags.c > +++ b/mm/kasan/hw_tags.c > @@ -6,6 +6,8 @@ > * Author: Andrey Konovalov <andreyknvl@google.com> > */ > > +#define pr_fmt(fmt) "kasan: " fmt > + > #include <linux/kasan.h> > #include <linux/kernel.h> > #include <linux/memory.h> > @@ -18,6 +20,8 @@ > void __init kasan_init_tags(void) > { > init_tags(KASAN_TAG_MAX); > + > + pr_info("KernelAddressSanitizer initialized\n"); > } > > void *kasan_reset_tag(const void *addr) > diff --git a/mm/kasan/sw_tags.c b/mm/kasan/sw_tags.c > index bf1422282bb5..099af6dc8f7e 100644 > --- a/mm/kasan/sw_tags.c > +++ b/mm/kasan/sw_tags.c > @@ -6,7 +6,7 @@ > * Author: Andrey Konovalov <andreyknvl@google.com> > */ > > -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt > +#define pr_fmt(fmt) "kasan: " fmt > > #include <linux/export.h> > #include <linux/interrupt.h> > @@ -41,6 +41,8 @@ void __init kasan_init_tags(void) > > for_each_possible_cpu(cpu) > per_cpu(prng_state, cpu) = (u32)get_cycles(); > + > + pr_info("KernelAddressSanitizer initialized\n"); > } > > /* > -- > 2.29.0.rc1.297.gfa9743e501-goog >
On Wed, Oct 28, 2020 at 11:56 AM Dmitry Vyukov <dvyukov@google.com> wrote: > > On Thu, Oct 22, 2020 at 3:19 PM Andrey Konovalov <andreyknvl@google.com> wrote: > > > > Tag-based KASAN modes are fully initialized with kasan_init_tags(), > > while the generic mode only requireds kasan_init(). Move the > > initialization message for tag-based modes into kasan_init_tags(). > > > > Also fix pr_fmt() usage for KASAN code: generic mode doesn't need it, > > Why doesn't it need it? What's the difference with tag modes? I need to reword the patch descriptions: it's not the mode that doesn't need it, it's the generic.c file, as it doesn't use any pr_*() functions. > > > tag-based modes should use "kasan:" instead of KBUILD_MODNAME. > > With generic KASAN I currently see: > > [ 0.571473][ T0] kasan: KernelAddressSanitizer initialized > > So KBUILD_MODNAME somehow works. Is there some difference between files? That code is printed from arch/xxx/mm/kasan_init*.c, which has its own pr_fmt defined. > > > Signed-off-by: Andrey Konovalov <andreyknvl@google.com> > > Link: https://linux-review.googlesource.com/id/Idfd1e50625ffdf42dfc3dbf7455b11bd200a0a49 > > --- > > arch/arm64/mm/kasan_init.c | 3 +++ > > mm/kasan/generic.c | 2 -- > > mm/kasan/hw_tags.c | 4 ++++ > > mm/kasan/sw_tags.c | 4 +++- > > 4 files changed, 10 insertions(+), 3 deletions(-) > > > > diff --git a/arch/arm64/mm/kasan_init.c b/arch/arm64/mm/kasan_init.c > > index b6b9d55bb72e..8f17fa834b62 100644 > > --- a/arch/arm64/mm/kasan_init.c > > +++ b/arch/arm64/mm/kasan_init.c > > @@ -290,5 +290,8 @@ void __init kasan_init(void) > > { > > kasan_init_shadow(); > > kasan_init_depth(); > > +#if defined(CONFIG_KASAN_GENERIC) > > + /* CONFIG_KASAN_SW/HW_TAGS also requires kasan_init_tags(). */ > > A bit cleaner way may be to introduce kasan_init_early() and > kasan_init_late(). Late() will do tag init and always print the > message. It appears we'll also need kasan_init_even_later() for some MTE-related stuff. I'll try to figure out some sane naming scheme here and include it into the next version.
On Thu, Oct 29, 2020 at 9:14 PM Andrey Konovalov <andreyknvl@google.com> wrote: > > On Wed, Oct 28, 2020 at 11:56 AM Dmitry Vyukov <dvyukov@google.com> wrote: > > > > On Thu, Oct 22, 2020 at 3:19 PM Andrey Konovalov <andreyknvl@google.com> wrote: > > > > > > Tag-based KASAN modes are fully initialized with kasan_init_tags(), > > > while the generic mode only requireds kasan_init(). Move the > > > initialization message for tag-based modes into kasan_init_tags(). > > > > > > Also fix pr_fmt() usage for KASAN code: generic mode doesn't need it, > > > > Why doesn't it need it? What's the difference with tag modes? > > I need to reword the patch descriptions: it's not the mode that > doesn't need it, it's the generic.c file, as it doesn't use any pr_*() > functions. > > > > > > tag-based modes should use "kasan:" instead of KBUILD_MODNAME. > > > > With generic KASAN I currently see: > > > > [ 0.571473][ T0] kasan: KernelAddressSanitizer initialized > > > > So KBUILD_MODNAME somehow works. Is there some difference between files? > > That code is printed from arch/xxx/mm/kasan_init*.c, which has its own > pr_fmt defined. > > > > > > Signed-off-by: Andrey Konovalov <andreyknvl@google.com> > > > Link: https://linux-review.googlesource.com/id/Idfd1e50625ffdf42dfc3dbf7455b11bd200a0a49 > > > --- > > > arch/arm64/mm/kasan_init.c | 3 +++ > > > mm/kasan/generic.c | 2 -- > > > mm/kasan/hw_tags.c | 4 ++++ > > > mm/kasan/sw_tags.c | 4 +++- > > > 4 files changed, 10 insertions(+), 3 deletions(-) > > > > > > diff --git a/arch/arm64/mm/kasan_init.c b/arch/arm64/mm/kasan_init.c > > > index b6b9d55bb72e..8f17fa834b62 100644 > > > --- a/arch/arm64/mm/kasan_init.c > > > +++ b/arch/arm64/mm/kasan_init.c > > > @@ -290,5 +290,8 @@ void __init kasan_init(void) > > > { > > > kasan_init_shadow(); > > > kasan_init_depth(); > > > +#if defined(CONFIG_KASAN_GENERIC) > > > + /* CONFIG_KASAN_SW/HW_TAGS also requires kasan_init_tags(). */ > > > > A bit cleaner way may be to introduce kasan_init_early() and > > kasan_init_late(). Late() will do tag init and always print the > > message. > > It appears we'll also need kasan_init_even_later() for some > MTE-related stuff. I'll try to figure out some sane naming scheme here > and include it into the next version. Actually, it looks like some arches already have kasan_init_early/late() along with kasan_init(). I'd say we better keep those for generic KASAN mode, and kasan_init_tags() for tag-based modes.
diff --git a/arch/arm64/mm/kasan_init.c b/arch/arm64/mm/kasan_init.c index b6b9d55bb72e..8f17fa834b62 100644 --- a/arch/arm64/mm/kasan_init.c +++ b/arch/arm64/mm/kasan_init.c @@ -290,5 +290,8 @@ void __init kasan_init(void) { kasan_init_shadow(); kasan_init_depth(); +#if defined(CONFIG_KASAN_GENERIC) + /* CONFIG_KASAN_SW/HW_TAGS also requires kasan_init_tags(). */ pr_info("KernelAddressSanitizer initialized\n"); +#endif } diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index de6b3f03a023..d259e4c3aefd 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -9,8 +9,6 @@ * Andrey Konovalov <andreyknvl@gmail.com> */ -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt - #include <linux/export.h> #include <linux/interrupt.h> #include <linux/init.h> diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c index 0128062320d5..b372421258c8 100644 --- a/mm/kasan/hw_tags.c +++ b/mm/kasan/hw_tags.c @@ -6,6 +6,8 @@ * Author: Andrey Konovalov <andreyknvl@google.com> */ +#define pr_fmt(fmt) "kasan: " fmt + #include <linux/kasan.h> #include <linux/kernel.h> #include <linux/memory.h> @@ -18,6 +20,8 @@ void __init kasan_init_tags(void) { init_tags(KASAN_TAG_MAX); + + pr_info("KernelAddressSanitizer initialized\n"); } void *kasan_reset_tag(const void *addr) diff --git a/mm/kasan/sw_tags.c b/mm/kasan/sw_tags.c index bf1422282bb5..099af6dc8f7e 100644 --- a/mm/kasan/sw_tags.c +++ b/mm/kasan/sw_tags.c @@ -6,7 +6,7 @@ * Author: Andrey Konovalov <andreyknvl@google.com> */ -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#define pr_fmt(fmt) "kasan: " fmt #include <linux/export.h> #include <linux/interrupt.h> @@ -41,6 +41,8 @@ void __init kasan_init_tags(void) for_each_possible_cpu(cpu) per_cpu(prng_state, cpu) = (u32)get_cycles(); + + pr_info("KernelAddressSanitizer initialized\n"); } /*
Tag-based KASAN modes are fully initialized with kasan_init_tags(), while the generic mode only requireds kasan_init(). Move the initialization message for tag-based modes into kasan_init_tags(). Also fix pr_fmt() usage for KASAN code: generic mode doesn't need it, tag-based modes should use "kasan:" instead of KBUILD_MODNAME. Signed-off-by: Andrey Konovalov <andreyknvl@google.com> Link: https://linux-review.googlesource.com/id/Idfd1e50625ffdf42dfc3dbf7455b11bd200a0a49 --- arch/arm64/mm/kasan_init.c | 3 +++ mm/kasan/generic.c | 2 -- mm/kasan/hw_tags.c | 4 ++++ mm/kasan/sw_tags.c | 4 +++- 4 files changed, 10 insertions(+), 3 deletions(-)