Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1690505 > unrolled thread

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

Started byDmitry Vyukov <dvyukov@google.com>
First post2017-07-18 19:20 +0200
Last post2017-07-18 19:20 +0200
Articles 1 — 1 participant

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH] lib/strscpy: avoid KASAN false positive Dmitry Vyukov <dvyukov@google.com> - 2017-07-18 19:20 +0200

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

FromDmitry Vyukov <dvyukov@google.com>
Date2017-07-18 19:20 +0200
SubjectRe: [PATCH] lib/strscpy: avoid KASAN false positive
Message-ID<u4Ekb-5e8-31@gated-at.bofh.it>
On Tue, Jul 18, 2017 at 7:15 PM, Andrey Ryabinin
<aryabinin@virtuozzo.com> wrote:
> strscpy() performs the word-at-a-time optimistic reads. So it may
> may access the memory past the end of the object, which is perfectly fine
> since strscpy() doesn't use that (past-the-end) data and makes sure the
> optimistic read won't cross a page boundary.
>
> But KASAN doesn't know anything about that so it will complain.
> Let's just fallback to the byte-at-a-time reads under CONFIG_KASAN=y
> to avoid false-positives.

Acked-by: Dmitry Vyukov <dvyukov@google.com>

> Reported-by: Dave Jones <davej@codemonkey.org.uk>
> Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
> ---
>  lib/string.c | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/lib/string.c b/lib/string.c
> index ebbb99c775bd..8b93d2519d5a 100644
> --- a/lib/string.c
> +++ b/lib/string.c
> @@ -199,6 +199,13 @@ ssize_t strscpy(char *dest, const char *src, size_t count)
>                 max = 0;
>  #endif
>
> +       /*
> +        * KASAN won't be happy about word-at-a-time
> +        * optimistic reads, so let's avoid them.
> +        */
> +       if (IS_ENABLED(CONFIG_KASAN))
> +               max = 0;
> +
>         while (max >= sizeof(unsigned long)) {
>                 unsigned long c, data;
>
> --
> 2.13.0
>

[toc] | [standalone]


Back to top | Article view | linux.kernel


csiph-web