Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp860555imj; Fri, 15 Feb 2019 08:01:18 -0800 (PST) X-Google-Smtp-Source: AHgI3IZzdPQLM/caVZhJwl3H5TyPMcq7T6XLoVtfqNL4MpUcTwT0mCvfXhV9cP57ijPfuzwNu/CL X-Received: by 2002:a62:564d:: with SMTP id k74mr1973268pfb.19.1550246478614; Fri, 15 Feb 2019 08:01:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550246478; cv=none; d=google.com; s=arc-20160816; b=tG9lwa58pFg2ReN8EmggkyCbNtG3JBbo6azeuO+TmabWdcnNvsVepZ3l8IBhFK+Wow Y1w8zy+PLszfiN2pfAdjGV7Mqt5zwKOaVrx7VWAcJDX9hUmthNVJkhw4z+vUnbSnn2y4 nJIPUMn30UOp/dnB5nSu3IRDognDTIlRFnak2PdN0QMTmxvqtgJtV0eJ3LHgZeOBba3/ UjNadJQAPJJOXMwMJ36DI6plA9cFWPxTW/6Gshi5Vm2RMl5k7c8XN22VahNiXx8Lm6q6 iA9fGV1kvmrFYD5cjeunFO/HudOKeEa1pwmrCeTgN0K+mnbQA12F4I1Lhs4vyYEhwEQV 9ltg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=ch7EoHne4Vn78A7u+E0nGHclRQLHFZUXvP490sZagxI=; b=wCpcscNBprj0heknW5IfRx4mgZ9O2wPkF2R6/l7FgaeUyZH3xgoZQFW+3C893StEKF 13YHibT6taCQmn8AZENPWksnN+zGeztOD13Owx90D9NMBlb6kkg/+8f8coMhTSN6oASy bVM8DkF4W3ubGZIXJLM3rPFO6akgQKBXHAaqPXi7aKDKi2cPH7yHlGQfdN6BvfnF9C3W +01C3xI4L+lZ06QXZ7oMyPbZBwmtMZnOkEOTXEiJ7CwO31/bdWvgGtXOranHpgI29A4u qLi2M+meQSxStm3Q5DoEcl0ziAvICYBhwvLWr5XyhGLI9kZ8whczkGK9fc02jXZIBnBf Mihw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y15si5649244pgf.321.2019.02.15.08.01.01; Fri, 15 Feb 2019 08:01:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405477AbfBOKBh (ORCPT + 99 others); Fri, 15 Feb 2019 05:01:37 -0500 Received: from relay.sw.ru ([185.231.240.75]:33698 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726159AbfBOKBh (ORCPT ); Fri, 15 Feb 2019 05:01:37 -0500 Received: from [172.16.25.12] by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1guaJA-0003fU-Ra; Fri, 15 Feb 2019 13:01:24 +0300 Subject: Re: [PATCH v5 3/3] powerpc/32: Add KASAN support To: Christophe Leroy , Daniel Axtens , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Nicholas Piggin , "Aneesh Kumar K.V" , Alexander Potapenko , Dmitry Vyukov Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, linux-mm@kvack.org References: <3429fe33b68206ecc2a725a740937bbaef2d1ac8.1549935251.git.christophe.leroy@c-s.fr> <8736oq3u2r.fsf@dja-thinkpad.axtens.net> From: Andrey Ryabinin Message-ID: Date: Fri, 15 Feb 2019 13:01:46 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/15/19 11:41 AM, Christophe Leroy wrote: > > > Le 14/02/2019 à 23:04, Daniel Axtens a écrit : >> Hi Christophe, >> >>> --- a/arch/powerpc/include/asm/string.h >>> +++ b/arch/powerpc/include/asm/string.h >>> @@ -27,6 +27,20 @@ extern int memcmp(const void *,const void *,__kernel_size_t); >>>   extern void * memchr(const void *,int,__kernel_size_t); >>>   extern void * memcpy_flushcache(void *,const void *,__kernel_size_t); >>>   +void *__memset(void *s, int c, __kernel_size_t count); >>> +void *__memcpy(void *to, const void *from, __kernel_size_t n); >>> +void *__memmove(void *to, const void *from, __kernel_size_t n); >>> + >>> +#if defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__) >>> +/* >>> + * For files that are not instrumented (e.g. mm/slub.c) we >>> + * should use not instrumented version of mem* functions. >>> + */ >>> +#define memcpy(dst, src, len) __memcpy(dst, src, len) >>> +#define memmove(dst, src, len) __memmove(dst, src, len) >>> +#define memset(s, c, n) __memset(s, c, n) >>> +#endif >>> + >> >> I'm finding that I miss tests like 'kasan test: kasan_memcmp >> out-of-bounds in memcmp' because the uninstrumented asm version is used >> instead of an instrumented C version. I ended up guarding the relevant >> __HAVE_ARCH_x symbols behind a #ifndef CONFIG_KASAN and only exporting >> the arch versions if we're not compiled with KASAN. >> >> I find I need to guard and unexport strncpy, strncmp, memchr and >> memcmp. Do you need to do this on 32bit as well, or are those tests >> passing anyway for some reason? > > Indeed, I didn't try the KASAN test module recently, because my configs don't have CONFIG_MODULE by default. > > Trying to test it now, I am discovering that module loading oopses with latest version of my series, I need to figure out exactly why. Here below the oops by modprobing test_module (the one supposed to just say hello to the world). > > What we see is an access to the RO kasan zero area. > > The shadow mem is 0xf7c00000..0xffc00000 > Linear kernel memory is shadowed by 0xf7c00000-0xf8bfffff > 0xf8c00000-0xffc00000 is shadowed read only by the kasan zero page. > > Why is kasan trying to access that ? Isn't kasan supposed to not check stuff in vmalloc area ? It tries to poison global variables in modules. If module is in vmalloc, than it will try to poison vmalloc. Given that the vmalloc area is not so big on 32bits, the easiest solution is to cover all vmalloc with RW shadow.