From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
To: Alexander Potapenko <glider@google.com>
Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, kasan-dev@googlegroups.com,
tglx@linutronix.de, x86@kernel.org,
Linus Torvalds <torvalds@linux-foundation.org>,
Dmitry Vyukov <dvyukov@google.com>,
Marco Elver <elver@google.com>
Subject: Re: [PATCH v1 3/3] x86: call instrumentation hooks from copy_mc.c
Date: Wed, 20 Mar 2024 19:39:49 +0900 [thread overview]
Message-ID: <dce41a35-aa2a-4e34-944b-7a6879f07448@I-love.SAKURA.ne.jp> (raw)
In-Reply-To: <CAG_fn=UAsTnuZb+p17X+_LN+wY7Anh3OzjHxMEw9Z-A=sJV0UQ@mail.gmail.com>
On 2024/03/20 18:29, Alexander Potapenko wrote:
> But for KASAN/KCSAN we can afford more aggressive checks.
> First, if we postpone them after the actual memory accesses happen,
> the kernel may panic on the invalid access without a decent error
> report.
> Second, even if in a particular case only `len-ret` bytes were copied,
> the caller probably expected both `src` and `dst` to have `len`
> addressable bytes.
> Checking for the whole length in this case is more likely to detect a
> real error than produce a false positive.
KASAN/KCSAN care about whether the requested address range is accessible but
do not care about whether the requested address range was actually accessed?
By the way, we have the same problem for copy_page() and I was thinking about
https://lkml.kernel.org/r/1a817eb5-7cd8-44d6-b409-b3bc3f377cb9@I-love.SAKURA.ne.jp .
But given that instrument_memcpy_{before,after} are added,
how do we want to use instrument_memcpy_{before,after} for copy_page() ?
Should we rename assembly version of copy_page() so that we don't need to use
tricky wrapping like below?
diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
index cc6b8e087192..b9b794656880 100644
--- a/arch/x86/include/asm/page_64.h
+++ b/arch/x86/include/asm/page_64.h
@@ -9,6 +9,7 @@
#include <asm/alternative.h>
#include <linux/kmsan-checks.h>
+#include <linux/instrumented.h>
/* duplicated to the one in bootmem.h */
extern unsigned long max_pfn;
@@ -59,6 +60,13 @@ static inline void clear_page(void *page)
}
void copy_page(void *to, void *from);
+#define copy_page(to, from) do { \
+ void *_to = (to); \
+ void *_from = (from); \
+ instrument_memcpy_before(_to, _from, PAGE_SIZE); \
+ copy_page(_to, _from); \
+ instrument_memcpy_after(_to, _from, PAGE_SIZE, 0); \
+} while (0)
#ifdef CONFIG_X86_5LEVEL
/*
next prev parent reply other threads:[~2024-03-20 10:40 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-19 16:36 [PATCH v1 1/3] mm: kmsan: implement kmsan_memmove() Alexander Potapenko
2024-03-19 16:36 ` [PATCH v1 2/3] instrumented.h: add instrument_memcpy_before, instrument_memcpy_after Alexander Potapenko
2024-03-19 17:52 ` Linus Torvalds
2024-03-20 9:00 ` Alexander Potapenko
2024-03-19 16:36 ` [PATCH v1 3/3] x86: call instrumentation hooks from copy_mc.c Alexander Potapenko
2024-03-19 17:58 ` Linus Torvalds
2024-03-20 10:12 ` Alexander Potapenko
2024-03-20 3:54 ` Tetsuo Handa
2024-03-20 9:29 ` Alexander Potapenko
2024-03-20 10:39 ` Tetsuo Handa [this message]
2024-03-20 12:06 ` Alexander Potapenko
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=dce41a35-aa2a-4e34-944b-7a6879f07448@I-love.SAKURA.ne.jp \
--to=penguin-kernel@i-love.sakura.ne.jp \
--cc=akpm@linux-foundation.org \
--cc=dvyukov@google.com \
--cc=elver@google.com \
--cc=glider@google.com \
--cc=kasan-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=x86@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