lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Wed, 20 Mar 2024 10:29:03 +0100
From: Alexander Potapenko <glider@...gle.com>
To: Tetsuo Handa <penguin-kernel@...ove.sakura.ne.jp>
Cc: akpm@...ux-foundation.org, linux-kernel@...r.kernel.org, 
	linux-mm@...ck.org, kasan-dev@...glegroups.com, tglx@...utronix.de, 
	x86@...nel.org, Linus Torvalds <torvalds@...ux-foundation.org>, 
	Dmitry Vyukov <dvyukov@...gle.com>, Marco Elver <elver@...gle.com>
Subject: Re: [PATCH v1 3/3] x86: call instrumentation hooks from copy_mc.c

On Wed, Mar 20, 2024 at 4:54 AM Tetsuo Handa
<penguin-kernel@...ove.sakura.ne.jp> wrote:
>
> On 2024/03/20 1:36, Alexander Potapenko wrote:
> > @@ -61,10 +62,20 @@ unsigned long copy_mc_enhanced_fast_string(void *dst, const void *src, unsigned
> >   */
> >  unsigned long __must_check copy_mc_to_kernel(void *dst, const void *src, unsigned len)
> >  {
> > -     if (copy_mc_fragile_enabled)
> > -             return copy_mc_fragile(dst, src, len);
> > -     if (static_cpu_has(X86_FEATURE_ERMS))
> > -             return copy_mc_enhanced_fast_string(dst, src, len);
> > +     unsigned long ret;
> > +
> > +     if (copy_mc_fragile_enabled) {
> > +             instrument_memcpy_before(dst, src, len);
>
> I feel that instrument_memcpy_before() needs to be called *after*
> copy_mc_fragile() etc. , for we can't predict how many bytes will
> copy_mc_fragile() etc. actually copy.

That's why we have both _before() and _after(). We can discuss what
checks need to be done before and after the memcpy call, but calling
instrument_memcpy_before() after copy_mc_fragile() is
counterintuitive.

For KMSAN it is indeed important to only handle `len-ret` bytes that
were actually copied. We want the instrumentation to update the
metadata without triggering an immediate error report, so the update
better be consistent with what the kernel actually did with the
memory.

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.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ