linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Walter Wu <walter-zh.wu@mediatek.com>
To: Marc Gonzalez <marc.w.gonzalez@free.fr>
Cc: LKML <linux-kernel@vger.kernel.org>,
	kasan-dev <kasan-dev@googlegroups.com>,
	Alexander Potapenko <glider@google.com>,
	Linux ARM <linux-arm-kernel@lists.infradead.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	Andrey Ryabinin <aryabinin@virtuozzo.com>,
	Dmitry Vyukov <dvyukov@google.com>
Subject: Re: [PATCH] kasan: fix the missing underflow in memmove and memcpy with CONFIG_KASAN_GENERIC=y
Date: Tue, 1 Oct 2019 10:36:40 +0800	[thread overview]
Message-ID: <1569897400.17361.27.camel@mtksdccf07> (raw)
In-Reply-To: <a3a5e118-e6da-8d6d-5073-931653fa2808@free.fr>

On Mon, 2019-09-30 at 10:57 +0200, Marc Gonzalez wrote:
> On 30/09/2019 06:36, Walter Wu wrote:
> 
> >  bool check_memory_region(unsigned long addr, size_t size, bool write,
> >                                 unsigned long ret_ip)
> >  {
> > +       if (long(size) < 0) {
> > +               kasan_report_invalid_size(src, dest, len, _RET_IP_);
> > +               return false;
> > +       }
> > +
> >         return check_memory_region_inline(addr, size, write, ret_ip);
> >  }
> 
> Is it expected that memcpy/memmove may sometimes (incorrectly) be passed
> a negative value? (It would indeed turn up as a "large" size_t)
> 
> IMO, casting to long is suspicious.
> 
> There seem to be some two implicit assumptions.
> 
> 1) size >= ULONG_MAX/2 is invalid input
> 2) casting a size >= ULONG_MAX/2 to long yields a negative value
> 
> 1) seems reasonable because we can't copy more than half of memory to
> the other half of memory. I suppose the constraint could be even tighter,
> but it's not clear where to draw the line, especially when considering
> 32b vs 64b arches.
> 
> 2) is implementation-defined, and gcc works "as expected" (clang too
> probably) https://gcc.gnu.org/onlinedocs/gcc/Integers-implementation.html
> 
> A comment might be warranted to explain the rationale.
> Regards.

Thanks for your suggestion.
Yes, It is passed a negative value issue in memcpy/memmove/memset.
Our current idea should be assumption 1 and only consider 64b arch,
because KASAN only supports 64b. In fact, we really can't use so much
memory in 64b arch. so assumption 1 make sense.




_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2019-10-01  2:37 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-27  3:43 Walter Wu
2019-09-27 13:07 ` Dmitry Vyukov
2019-09-27 14:22   ` Walter Wu
2019-09-27 19:41     ` Dmitry Vyukov
2019-09-30  4:36       ` Walter Wu
2019-09-30  8:57         ` Marc Gonzalez
2019-10-01  2:36           ` Walter Wu [this message]
2019-10-01  3:01             ` Dmitry Vyukov
2019-10-01  3:18               ` Walter Wu
2019-10-02 12:15         ` Walter Wu
2019-10-02 13:57           ` Dmitry Vyukov
2019-10-03  2:17             ` Walter Wu
2019-10-03  6:26               ` Dmitry Vyukov
2019-10-03  9:38                 ` Walter Wu
2019-10-03 13:51                   ` Walter Wu
2019-10-03 14:53                     ` Dmitry Vyukov
2019-10-04  4:42                       ` Walter Wu
2019-10-04  8:02                         ` Walter Wu
2019-10-04  9:18                           ` Dmitry Vyukov
2019-10-04  9:44                             ` Walter Wu
2019-10-04  9:54                               ` Dmitry Vyukov
2019-10-04 12:05                                 ` Walter Wu
2019-10-04 13:52                                   ` Dmitry Vyukov
2019-10-07  3:22                                     ` Walter Wu
2019-10-07  7:29                                       ` Dmitry Vyukov
2019-10-07  8:18                                         ` Walter Wu
2019-10-07  8:24                                           ` Dmitry Vyukov
2019-10-07  8:51                                             ` Walter Wu
2019-10-07  8:54                                               ` Dmitry Vyukov
2019-10-07  9:03                                                 ` Walter Wu
2019-10-07  9:10                                                   ` Dmitry Vyukov
2019-10-07  9:28                                                     ` Walter Wu
2019-10-07  9:50                                                       ` Walter Wu
2019-10-07 10:51                                                         ` Dmitry Vyukov
2019-10-07 12:03                                                           ` Walter Wu
2019-10-07 12:19                                                             ` Dmitry Vyukov
2019-10-07 12:32                                                               ` Walter Wu
2019-10-07 13:33                                                                 ` Dmitry Vyukov
2019-10-08  6:15                                                                   ` Walter Wu
2019-10-08  9:47                                                                     ` Qian Cai
2019-10-08 11:02                                                                       ` Walter Wu
2019-10-08 11:42                                                                         ` Qian Cai
2019-10-08 12:07                                                                           ` Walter Wu
2019-10-08 12:11                                                                           ` Dmitry Vyukov
2019-10-14  2:19                                                                             ` Walter Wu

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=1569897400.17361.27.camel@mtksdccf07 \
    --to=walter-zh.wu@mediatek.com \
    --cc=aryabinin@virtuozzo.com \
    --cc=dvyukov@google.com \
    --cc=glider@google.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marc.w.gonzalez@free.fr \
    --cc=matthias.bgg@gmail.com \
    --subject='Re: [PATCH] kasan: fix the missing underflow in memmove and memcpy with CONFIG_KASAN_GENERIC=y' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).