Re: [PATCH] lib/strscpy: avoid KASAN false positive

From: Linus Torvalds
Date: Tue Jul 18 2017 - 13:22:51 EST


On Tue, Jul 18, 2017 at 10:15 AM, Andrey Ryabinin
<aryabinin@xxxxxxxxxxxxx> wrote:
>
> + /*
> + * KASAN won't be happy about word-at-a-time
> + * optimistic reads, so let's avoid them.
> + */
> + if (IS_ENABLED(CONFIG_KASAN))
> + max = 0;
> +

No, please don't.

Two reasons:

(a) it turns out that KASAN doesn't actually warn about this when
there aren't buggy users (because we only do word-at-a-time in the
spacified-to-be-safe region anyway).

(b) havign automated testing that then just changes semantics and
implementation of what is tested is a bad bad bad idea.

So (a) says that we shouldn't need it in the first place, and (b) says
that we should avoid KASAN changing behavior unless we absolutely
*have* to.

In fact, I think we should *never* have that kind of "KASAN changes
semantics". If there is some particular load that is known to be
problematic for KASAN, we *still* shouldn't change semantics, we
should just mark that single load as being unchecked by KASAN.

Linus