linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrey Konovalov <andreyknvl@google.com>
To: Marco Elver <elver@google.com>
Cc: Kees Cook <keescook@chromium.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	LKML <linux-kernel@vger.kernel.org>,
	kasan-dev <kasan-dev@googlegroups.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Dmitry Vyukov <dvyukov@google.com>,
	clang-built-linux <clang-built-linux@googlegroups.com>
Subject: Re: [PATCH] lkdtm: disable KASAN for rodata.o
Date: Tue, 15 Dec 2020 15:00:52 +0100	[thread overview]
Message-ID: <CAAeHK+x3w=rw3Jk3Zg-Q2H6iboWH3dqGvgm9ZXxsCaBGGzR9JA@mail.gmail.com> (raw)
In-Reply-To: <20201214191413.3164796-1-elver@google.com>

On Mon, Dec 14, 2020 at 8:15 PM Marco Elver <elver@google.com> wrote:
>
> Building lkdtm with KASAN and Clang 11 or later results in the following
> error when attempting to load the module:
>
>   kernel tried to execute NX-protected page - exploit attempt? (uid: 0)
>   BUG: unable to handle page fault for address: ffffffffc019cd70
>   #PF: supervisor instruction fetch in kernel mode
>   #PF: error_code(0x0011) - permissions violation
>   ...
>   RIP: 0010:asan.module_ctor+0x0/0xffffffffffffa290 [lkdtm]
>   ...
>   Call Trace:
>    do_init_module+0x17c/0x570
>    load_module+0xadee/0xd0b0
>    __x64_sys_finit_module+0x16c/0x1a0
>    do_syscall_64+0x34/0x50
>    entry_SYSCALL_64_after_hwframe+0x44/0xa9
>
> The reason is that rodata.o generates a dummy function that lives in
> .rodata to validate that .rodata can't be executed; however, Clang 11
> adds KASAN globals support by generating module constructors to
> initialize globals redzones. When Clang 11 adds a module constructor to
> rodata.o, it is also added to .rodata: any attempt to call it on
> initialization results in the above error.
>
> Therefore, disable KASAN instrumentation for rodata.o.
>
> Signed-off-by: Marco Elver <elver@google.com>
> ---
>  drivers/misc/lkdtm/Makefile | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/misc/lkdtm/Makefile b/drivers/misc/lkdtm/Makefile
> index c70b3822013f..1c4c7aca0026 100644
> --- a/drivers/misc/lkdtm/Makefile
> +++ b/drivers/misc/lkdtm/Makefile
> @@ -11,6 +11,7 @@ lkdtm-$(CONFIG_LKDTM)         += usercopy.o
>  lkdtm-$(CONFIG_LKDTM)          += stackleak.o
>  lkdtm-$(CONFIG_LKDTM)          += cfi.o
>
> +KASAN_SANITIZE_rodata.o                := n
>  KASAN_SANITIZE_stackleak.o     := n
>  KCOV_INSTRUMENT_rodata.o       := n
>
>
> base-commit: 2c85ebc57b3e1817b6ce1a6b703928e113a90442
> --
> 2.29.2.684.gfbc64c5ab5-goog
>

Reviewed-by: Andrey Konovalov <andreyknvl@google.com>

Thanks for taking care of this!

      reply	other threads:[~2020-12-15 14:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-14 19:14 [PATCH] lkdtm: disable KASAN for rodata.o Marco Elver
2020-12-15 14:00 ` Andrey Konovalov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAAeHK+x3w=rw3Jk3Zg-Q2H6iboWH3dqGvgm9ZXxsCaBGGzR9JA@mail.gmail.com' \
    --to=andreyknvl@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=clang-built-linux@googlegroups.com \
    --cc=dvyukov@google.com \
    --cc=elver@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kasan-dev@googlegroups.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).