[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAG_fn=X71NCOnqNrtU9rJ4eeGZsxLCxKT=Cq9J9dq9q+Re9syA@mail.gmail.com>
Date: Tue, 19 Mar 2024 13:38:45 +0100
From: Alexander Potapenko <glider@...gle.com>
To: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Tetsuo Handa <penguin-kernel@...ove.sakura.ne.jp>, Marco Elver <elver@...gle.com>,
Dmitry Vyukov <dvyukov@...gle.com>, kasan-dev <kasan-dev@...glegroups.com>,
LKML <linux-kernel@...r.kernel.org>, "the arch/x86 maintainers" <x86@...nel.org>,
Thomas Gleixner <tglx@...utronix.de>, Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>, "H. Peter Anvin" <hpa@...or.com>
Subject: Re: [PATCH v2] x86: disable non-instrumented version of copy_mc when
KMSAN is enabled
On Thu, Mar 7, 2024 at 1:09 AM Linus Torvalds
<torvalds@...ux-foundation.org> wrote:
>
> On Wed, 6 Mar 2024 at 14:08, Tetsuo Handa
> <penguin-kernel@...ove.sakura.ne.jp> wrote:
> >
> > Something like below one?
>
> I'd rather leave the regular fallbacks (to memcpy and copy_to_user())
> alone, and I'd just put the
>
> kmsan_memmove(dst, src, len - ret);
>
> etc in the places that currently just call the MC copy functions.
(sorry for being late to the party)
We should probably use <linux/instrumented.h> here, as other tools
(KASAN and KCSAN) do not instrument copy_mc_to_kernel() either, and
might benefit from the same checks.
Something along the lines of:
================================
static __always_inline void
instrument_memcpy_before(const void *to, const void *from, unsigned long n)
{
kasan_check_write(to, n);
kasan_check_read(from, n);
kcsan_check_write(to, n);
kcsan_check_read(from, n);
}
static __always_inline void instrument_memcpy_after(const void *to,
const void *from,
unsigned long n,
unsigned long left)
{
kmsan_memcpy(to, n - left);
}
================================
(with kmsan_memcpy() working as Tetsuo described).
We can also update copy_mc_fragile_handle_tail() and copy_mc_to_user()
to call the instrumentation hooks.
Let me send the patches.
Powered by blists - more mailing lists