[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a3a5e118-e6da-8d6d-5073-931653fa2808@free.fr>
Date: Mon, 30 Sep 2019 10:57:39 +0200
From: Marc Gonzalez <marc.w.gonzalez@...e.fr>
To: Walter Wu <walter-zh.wu@...iatek.com>,
Dmitry Vyukov <dvyukov@...gle.com>
Cc: LKML <linux-kernel@...r.kernel.org>,
kasan-dev <kasan-dev@...glegroups.com>,
Alexander Potapenko <glider@...gle.com>,
Matthias Brugger <matthias.bgg@...il.com>,
Andrey Ryabinin <aryabinin@...tuozzo.com>,
Linux ARM <linux-arm-kernel@...ts.infradead.org>
Subject: Re: [PATCH] kasan: fix the missing underflow in memmove and memcpy
with CONFIG_KASAN_GENERIC=y
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.
Powered by blists - more mailing lists