From patchwork Tue Feb 19 17:23:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10820493 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 044461399 for ; Tue, 19 Feb 2019 17:23:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE9E32D0DD for ; Tue, 19 Feb 2019 17:23:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DC6922D164; Tue, 19 Feb 2019 17:23:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 708242D0F2 for ; Tue, 19 Feb 2019 17:23:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 55F888E0004; Tue, 19 Feb 2019 12:23:11 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 449908E0002; Tue, 19 Feb 2019 12:23:11 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2EB1C8E0004; Tue, 19 Feb 2019 12:23:11 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by kanga.kvack.org (Postfix) with ESMTP id C79328E0002 for ; Tue, 19 Feb 2019 12:23:10 -0500 (EST) Received: by mail-wr1-f69.google.com with SMTP id z13so5878922wrp.5 for ; Tue, 19 Feb 2019 09:23:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:message-id:in-reply-to:references :from:subject:to:cc:date; bh=um9yCYwOJ1SkZMPifhMErWXIPjN8RMbQWLCsWKAg55E=; b=qWXSir8PMxQu3g3ABVOUEUvFpQRihSKklEApuzGEVTqW+y8WA7e1nVClDnhYGc8gwl +PXH8utP3nOtDoCGKK/fX9y7zXQGJjvITAPh5z46keoc1dqrWXwvK6RXC2c4j6JbQduA CZCcAz8/V0Dfox8ztOf4YM6SQjbcjQHut8mLnVObFPW3eIlJ556YQX8g/CNplJFpQ+YN V2/QyebhtchOUbpwOeMbxVnoB9viM+dVpw8nnJm6ghF6nI1QMM7PejtzOinD9KnfXx/Y Pm7QeRsxxlqAIkBzoKiw2hcihofTKB1QGNpR6Fy8wDozKKH+gcSWKiM2xa4srcJDYOr6 1lwg== X-Gm-Message-State: AHQUAuZdiVu4rt365wgt7qR/95y3k5FHzLBghgjuZLJ2AK2s0tdj9cdH yKTd/ccD9oiRK3eR74yVTouT02cIP8cAcwLjjvFQ43sWWZ4AudUQEx3MlKx67FWWhNHx4Mh+rn+ lD+fyHOFHkq+ZvdfE3TpmY3csWRhOqTQJkkOw+p3n19gE1UZ1YxfBf7gEXYQMGYN1ww== X-Received: by 2002:adf:9e47:: with SMTP id v7mr22268427wre.190.1550596990241; Tue, 19 Feb 2019 09:23:10 -0800 (PST) X-Google-Smtp-Source: AHgI3IazzgEvSUQEtY7LL46gmQUoogRfF5jgplawqya5gu175ymsrKzul6qQ2riltZxGuOx0kTIW X-Received: by 2002:adf:9e47:: with SMTP id v7mr22268384wre.190.1550596989306; Tue, 19 Feb 2019 09:23:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550596989; cv=none; d=google.com; s=arc-20160816; b=L2YqYRCKHdo83p0YIjvZe2qvNa/cwqXT2bMtRWhhve2w6AZ2cDDfthevYTI/fVCG85 04/cAHrYGkW4WFw+MsnmS9hkguYxGfJrzbhEicjrfhKbHs6zfwydSUdifUFyqWGcjc3b RK4+nTyuWsXvH7xMSBdcKpZpikPMZSGzcJ997ZValbf07ojQnu+EvL/pYXd6PY2DxjQL V4wbpUFQ0BqPMAR8WJAunPXyjeG1v+OodLs05GRLcw7j4H9NbByF5TKqQ4xbjIjyB9l1 +arHSUl6ljxVxXXQd9suwq6jcT86wLM6+0feytu8pH3cPECGRQ6eglOWL9v4xs7iWK6R anjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:cc:to:subject:from:references:in-reply-to:message-id :dkim-signature; bh=um9yCYwOJ1SkZMPifhMErWXIPjN8RMbQWLCsWKAg55E=; b=Gls+37nI60yPOhjpz0jS/xoECsde8o3bs+yHVqU4cgRzdKUe2CDoBKYQQBFYkyC3fd Lc+gcMHOd0xFtTHVy+/xzy2cEyj2W53fmBD++dd6bDrBzvd4c6CZPNEUgYn/TqxE0r1h pUFEFqdaK5IMN5BqlvNPgqd+6dWxhQ0zvJwZ4vVhNxqMSu7x2nGluW3AI+RccPlEm0Ke OwZjrvmAVGyC10FJ9DtH9tkoGmYBIuIhsmO/2dbG+zKhRP4YTG0lv14Lz2HHx5RGxb0n qViskzWNGSdfehk/3fw9qxqkmIjVSK20rur+X81o1/+DSVXEFBKJQibOtZT3t90bsNws Itsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=UKna5p+M; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from pegase1.c-s.fr (pegase1.c-s.fr. [93.17.236.30]) by mx.google.com with ESMTPS id n2si1800876wmi.149.2019.02.19.09.23.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Feb 2019 09:23:09 -0800 (PST) Received-SPF: pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) client-ip=93.17.236.30; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=UKna5p+M; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 443ncq1Y0Rz9v4wh; Tue, 19 Feb 2019 18:23:07 +0100 (CET) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=UKna5p+M; dkim-adsp=pass; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id 5pShGomqr3uf; Tue, 19 Feb 2019 18:23:07 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 443ncq0LHYz9v4wf; Tue, 19 Feb 2019 18:23:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1550596987; bh=um9yCYwOJ1SkZMPifhMErWXIPjN8RMbQWLCsWKAg55E=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=UKna5p+MS8RXPp9xPoQwFfi6FnUmsVZC46q+/SXqCjiHhfWDEHY1fuAfUl10D5Bi3 /vXvh22F8XGovC16LyB47MF2/KhQyk/BnG0e5z35tqtbvHneQuT0HodSwxFoGqFEk5 PFurz5vgUBLmY4XfyoQ2buu8m06OuGyP+zBA0uEE= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id A77F78B7FE; Tue, 19 Feb 2019 18:23:08 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id XNx_RUqqrE9o; Tue, 19 Feb 2019 18:23:08 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 743128B7F9; Tue, 19 Feb 2019 18:23:08 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 5715C6E81D; Tue, 19 Feb 2019 17:23:08 +0000 (UTC) Message-Id: <906bdd0dde64a05b7a1d399ee57a0c3a34a094b8.1550596242.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v6 1/6] powerpc/mm: prepare kernel for KAsan on PPC32 To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Nicholas Piggin , Aneesh Kumar K.V , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Daniel Axtens Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Date: Tue, 19 Feb 2019 17:23:08 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP In kernel/cputable.c, explicitly use memcpy() in order to allow GCC to replace it with __memcpy() when KASAN is selected. Since commit 400c47d81ca38 ("powerpc32: memset: only use dcbz once cache is enabled"), memset() can be used before activation of the cache, so no need to use memset_io() for zeroing the BSS. Acked-by: Dmitry Vyukov Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/cputable.c | 13 ++++++++++--- arch/powerpc/kernel/setup_32.c | 6 ++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/arch/powerpc/kernel/cputable.c b/arch/powerpc/kernel/cputable.c index 1eab54bc6ee9..cd12f362b61f 100644 --- a/arch/powerpc/kernel/cputable.c +++ b/arch/powerpc/kernel/cputable.c @@ -2147,7 +2147,11 @@ void __init set_cur_cpu_spec(struct cpu_spec *s) struct cpu_spec *t = &the_cpu_spec; t = PTRRELOC(t); - *t = *s; + /* + * use memcpy() instead of *t = *s so that GCC replaces it + * by __memcpy() when KASAN is active + */ + memcpy(t, s, sizeof(*t)); *PTRRELOC(&cur_cpu_spec) = &the_cpu_spec; } @@ -2161,8 +2165,11 @@ static struct cpu_spec * __init setup_cpu_spec(unsigned long offset, t = PTRRELOC(t); old = *t; - /* Copy everything, then do fixups */ - *t = *s; + /* + * Copy everything, then do fixups. Use memcpy() instead of *t = *s + * so that GCC replaces it by __memcpy() when KASAN is active + */ + memcpy(t, s, sizeof(*t)); /* * If we are overriding a previous value derived from the real diff --git a/arch/powerpc/kernel/setup_32.c b/arch/powerpc/kernel/setup_32.c index 947f904688b0..5e761eb16a6d 100644 --- a/arch/powerpc/kernel/setup_32.c +++ b/arch/powerpc/kernel/setup_32.c @@ -73,10 +73,8 @@ notrace unsigned long __init early_init(unsigned long dt_ptr) { unsigned long offset = reloc_offset(); - /* First zero the BSS -- use memset_io, some platforms don't have - * caches on yet */ - memset_io((void __iomem *)PTRRELOC(&__bss_start), 0, - __bss_stop - __bss_start); + /* First zero the BSS */ + memset(PTRRELOC(&__bss_start), 0, __bss_stop - __bss_start); /* * Identify the CPU type and fix up code sections From patchwork Tue Feb 19 17:23:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10820495 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E80436C2 for ; Tue, 19 Feb 2019 17:23:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CEE7F2D18E for ; Tue, 19 Feb 2019 17:23:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CCD312D19D; Tue, 19 Feb 2019 17:23:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4254B2D18E for ; Tue, 19 Feb 2019 17:23:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9CA898E0005; Tue, 19 Feb 2019 12:23:13 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8E1EB8E0002; Tue, 19 Feb 2019 12:23:13 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 734CB8E0005; Tue, 19 Feb 2019 12:23:13 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by kanga.kvack.org (Postfix) with ESMTP id 1673D8E0002 for ; Tue, 19 Feb 2019 12:23:13 -0500 (EST) Received: by mail-wr1-f72.google.com with SMTP id f4so9239292wrj.11 for ; Tue, 19 Feb 2019 09:23:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:message-id:in-reply-to:references :from:subject:to:cc:date; bh=31DOHOTY8TAFQbUw3ju2ZitoNlqS/Q9KBZdABQSjtuY=; b=DqqHfWEaoID6t5sICO1szqeo2LWSqrtx0wty6fgN68vuhJEGnEN82RLql8a637D9OX 1kvhA3eN2CvT8DGcWP7MaQoVvESlwqZeS2GSxugsKdk1lHBftH4lICOjAvKjADSXSBbb xs8iynJ/8saNNmoA6guilOD07rZo02eHRATfiq/4k+UAlfVFOGO8NgQwehp8ifuLNGU+ G16L+PWImVBCc9QnmdGd4lmdn2tGx6j7FWybwTM8iF0XcE1s5C6F/ODnMgME7B3QtjXn 2IEt/vqAPP1MhZsv33wuY1TyKESBaRBw3IuAh7LzmeP8xs9ZWMnr9Be4qiMycA8jpVEr +CCA== X-Gm-Message-State: AHQUAuZK1ZaMor5naeUZlXh6Yqm8I53krt9WWsO+kHFpKxOjAC53UfBC Au7rUpHrJonc1jTX4h6wcVqHMKL0Qq9OfaZK7fJ7ezKTYcCcl/iqPtXk6USZ0HwUjN8mK7Qbatq 4Ij+80/IxUk9QrTuS3vDABFx2HGSfa1ka5fKfxxb/hB+hKT8QaZ1G9wPFPW5m9a42Vg== X-Received: by 2002:a1c:f509:: with SMTP id t9mr3826372wmh.76.1550596992598; Tue, 19 Feb 2019 09:23:12 -0800 (PST) X-Google-Smtp-Source: AHgI3IZBlNtOKdWMGXwXLENxRPlJt0uuL4DPNYbmW6UzR+1RvAiXUEHJrJfAY+VYwyUhph6qZXzD X-Received: by 2002:a1c:f509:: with SMTP id t9mr3826315wmh.76.1550596991430; Tue, 19 Feb 2019 09:23:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550596991; cv=none; d=google.com; s=arc-20160816; b=wC9t19wkbIF2cr8e8A0eU8T55mKJD/uwkHR2X5/qIuSklepmc2A8lD0/JHye/aBnzt vfcKt9idG/zLErDXmE5NMQ1VbZBVoNjkeYyBNR8uHqAWgSXuDW/sVFbj8nSAu6O2T9mA UQr3hZ/cNQ/OMmI6BcYRW1ZwYRZTOrIlomKDG9sfFPHOfiPXqUZe8E5RtubKqMA4e/xX YDuQYkIOk3gcCotTBXvKZ1s5L9aO6LtGO8NQrOyiM7VVKMMvqb20QLo6BgNYq8LUJa8N xl2z9HXaKxYxdq8T5k1a2aJHTHAEPZzUP8G9m5fvEvMA1slWE/MZ1aOYe6E0ggCfocA5 63wA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:cc:to:subject:from:references:in-reply-to:message-id :dkim-signature; bh=31DOHOTY8TAFQbUw3ju2ZitoNlqS/Q9KBZdABQSjtuY=; b=aGxdrfenWhZas665JQsfL977dZx/KJ0i2w2I5JleboqBV5ZaYpbHZ/GPMw1XoTjSzq 2r50oXOHjhBeI2co74w0b9hOZzHyDo0kPoqpAP3EV9zJu/c4TbSASNkd3/tTC/HBCl1h zsjeYKj76krCZXsazuAZW5Gx5ZYRpKFKtkr2NlQzZZNSnauH9zi4pFB/yjtcJeElVjVR /k73BdcbjvbkGhu7Ly+8ysHn61RYaK/EsVn67VGJJPIzG6CT/bniUIhvbUhoULl8tjQu iL04YX6EHbRnwyBXX/MO2NQJGL6gKEsQVoHiPkFIYMF2CBwWFhVssE8DQqbexXAwpFeF Q9uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=eeyCfSIW; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from pegase1.c-s.fr ([93.17.236.30]) by mx.google.com with ESMTPS id y7si1219323wrr.182.2019.02.19.09.23.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Feb 2019 09:23:11 -0800 (PST) Received-SPF: pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) client-ip=93.17.236.30; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=eeyCfSIW; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 443ncs1wXHz9v4wj; Tue, 19 Feb 2019 18:23:09 +0100 (CET) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=eeyCfSIW; dkim-adsp=pass; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id NCfK9Cf0tjfn; Tue, 19 Feb 2019 18:23:09 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 443ncs0h5Hz9v4wf; Tue, 19 Feb 2019 18:23:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1550596989; bh=31DOHOTY8TAFQbUw3ju2ZitoNlqS/Q9KBZdABQSjtuY=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=eeyCfSIWTvudaQye+j75JBejWpowCePo06pzvNaHZE9zrJtNT9Gp6pp9Bg7hxckIM 19cNQByqbDCTRfrxe+fkaVAQhxyp/aVaNfrs+uJNv9w6+2BeHUdZCV7GSVzTV9IYYH rZShjWWGuxczfMabwwXpSORweBAJD4gbz78QHC9o= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id B49B28B7FE; Tue, 19 Feb 2019 18:23:10 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id PNPdzjkKRflZ; Tue, 19 Feb 2019 18:23:10 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 757D98B7F9; Tue, 19 Feb 2019 18:23:10 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 5C83E6E81D; Tue, 19 Feb 2019 17:23:10 +0000 (UTC) Message-Id: In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v6 2/6] powerpc/32: Move early_init() in a separate file To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Nicholas Piggin , Aneesh Kumar K.V , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Daniel Axtens Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Date: Tue, 19 Feb 2019 17:23:10 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP In preparation of KASAN, move early_init() into a separate file in order to allow deactivation of KASAN for that function. Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/Makefile | 2 +- arch/powerpc/kernel/early_32.c | 36 ++++++++++++++++++++++++++++++++++++ arch/powerpc/kernel/setup_32.c | 26 -------------------------- 3 files changed, 37 insertions(+), 27 deletions(-) create mode 100644 arch/powerpc/kernel/early_32.c diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile index cb7f0bb9ee71..879b36602748 100644 --- a/arch/powerpc/kernel/Makefile +++ b/arch/powerpc/kernel/Makefile @@ -93,7 +93,7 @@ extra-y += vmlinux.lds obj-$(CONFIG_RELOCATABLE) += reloc_$(BITS).o -obj-$(CONFIG_PPC32) += entry_32.o setup_32.o +obj-$(CONFIG_PPC32) += entry_32.o setup_32.o early_32.o obj-$(CONFIG_PPC64) += dma-iommu.o iommu.o obj-$(CONFIG_KGDB) += kgdb.o obj-$(CONFIG_BOOTX_TEXT) += btext.o diff --git a/arch/powerpc/kernel/early_32.c b/arch/powerpc/kernel/early_32.c new file mode 100644 index 000000000000..3482118ffe76 --- /dev/null +++ b/arch/powerpc/kernel/early_32.c @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Early init before relocation + */ + +#include +#include +#include +#include +#include + +/* + * We're called here very early in the boot. + * + * Note that the kernel may be running at an address which is different + * from the address that it was linked at, so we must use RELOC/PTRRELOC + * to access static data (including strings). -- paulus + */ +notrace unsigned long __init early_init(unsigned long dt_ptr) +{ + unsigned long offset = reloc_offset(); + + /* First zero the BSS */ + memset(PTRRELOC(&__bss_start), 0, __bss_stop - __bss_start); + + /* + * Identify the CPU type and fix up code sections + * that depend on which cpu we have. + */ + identify_cpu(offset, mfspr(SPRN_PVR)); + + apply_feature_fixups(); + + return KERNELBASE + offset; +} diff --git a/arch/powerpc/kernel/setup_32.c b/arch/powerpc/kernel/setup_32.c index 5e761eb16a6d..b46a9a33225b 100644 --- a/arch/powerpc/kernel/setup_32.c +++ b/arch/powerpc/kernel/setup_32.c @@ -63,32 +63,6 @@ EXPORT_SYMBOL(DMA_MODE_READ); EXPORT_SYMBOL(DMA_MODE_WRITE); /* - * We're called here very early in the boot. - * - * Note that the kernel may be running at an address which is different - * from the address that it was linked at, so we must use RELOC/PTRRELOC - * to access static data (including strings). -- paulus - */ -notrace unsigned long __init early_init(unsigned long dt_ptr) -{ - unsigned long offset = reloc_offset(); - - /* First zero the BSS */ - memset(PTRRELOC(&__bss_start), 0, __bss_stop - __bss_start); - - /* - * Identify the CPU type and fix up code sections - * that depend on which cpu we have. - */ - identify_cpu(offset, mfspr(SPRN_PVR)); - - apply_feature_fixups(); - - return KERNELBASE + offset; -} - - -/* * This is run before start_kernel(), the kernel has been relocated * and we are running with enough of the MMU enabled to have our * proper kernel virtual addresses From patchwork Tue Feb 19 17:23:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10820497 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6517B1399 for ; Tue, 19 Feb 2019 17:23:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 44EA52CC0A for ; Tue, 19 Feb 2019 17:23:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4212F2D1B4; Tue, 19 Feb 2019 17:23:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 619AC2D12C for ; Tue, 19 Feb 2019 17:23:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E17E78E0006; Tue, 19 Feb 2019 12:23:15 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D75AF8E0002; Tue, 19 Feb 2019 12:23:15 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BC37D8E0006; Tue, 19 Feb 2019 12:23:15 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by kanga.kvack.org (Postfix) with ESMTP id 621778E0002 for ; Tue, 19 Feb 2019 12:23:15 -0500 (EST) Received: by mail-wr1-f69.google.com with SMTP id s5so9253664wrp.17 for ; Tue, 19 Feb 2019 09:23:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:message-id:in-reply-to:references :from:subject:to:cc:date; bh=qsRhj0vXokqCATs6bD55xa5yiXGxn2ORcM7fglpoAKM=; b=XGlKvF6H0X+sovX6rJE1khOGpqQ9/Xv9kEFwYdANgtpwbZ0iiQKfyHXIt2oOqfYDkc 0snHkaYPDibxay83WLla2QNc0Cl8rKz1a2YZKgIfVJFAhrzClOBzCGIqcygXpAr+r/j1 OefUlUuNOsu3PTjmHePd7wWKk55o7F1C8okqWPLtcY6njn0R30KfVgapaZLQS8jV3v0K qabis269oMk8bkXjpva9rf8RCe4GXGqDjGzaIB79T99OdCcCaxSYVh44ArZjqLciBfFN 1CqaKb6tc3C4kIB9NnlU4NHEoe3xzFirAGnNklpbcLpZMpwNWTEyfP8U9MVLFBfgDcTx 2uRg== X-Gm-Message-State: AHQUAuaznIuKv5a1p8Xg1mNSzX7pndUqSDQ9buCelTt4yum7pW2IkeTA idHY66Kg///kozU8ZjH9PBQ4eIONJNtoGPy2QQb+PfD/vdG0zmu3yFYHZaTTET4VvcTgM1g27yr 9lIh5v5beZO5M9cvbf+XDbIBtMkR3Z4LfxYJkJKmSU7NxchYbSCIbyx7KRW0TQGp6JQ== X-Received: by 2002:adf:f487:: with SMTP id l7mr20630740wro.86.1550596994876; Tue, 19 Feb 2019 09:23:14 -0800 (PST) X-Google-Smtp-Source: AHgI3IZl4SM8lSpLsMr05Cw7kNz+ypyK6unowIjOdWTFDDwiF8sLEdVfdQ6bgiHfsRKat22pYft+ X-Received: by 2002:adf:f487:: with SMTP id l7mr20630682wro.86.1550596993604; Tue, 19 Feb 2019 09:23:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550596993; cv=none; d=google.com; s=arc-20160816; b=GfEExaFLFnLFEt9E81+/5nMdFDpS7cOl0aUAeVHYiEAQT0eMdZvt4gfcOfE1CV5Gaw rKeG+Wd7kTbIpWShIncOivF2JMar9jxMFE9aF+WCSG0TXOeoK7LLpJEP9qw29CGAL1FE CjudVPMshX0xdOWqDxPgdzZy7qLsqYkOX0wxfwW0R/VLd7J8XFBhJEfE0Oma5Srqc+IF J72+Zsto9y54R4BOUIkxzo2fUjwc3d/0dxjHXSaMLzwuUO24JIUgFmOgJmi45JVRn/Ay n3OueR6Xi9n+r+Ymelil5NXYVjoeUj/ECgpJ460u4ka2DN1Vdrzqj4eHCjxXZYjafWnq ni3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:cc:to:subject:from:references:in-reply-to:message-id :dkim-signature; bh=qsRhj0vXokqCATs6bD55xa5yiXGxn2ORcM7fglpoAKM=; b=MOepLlxLvren+Vmf4FbcyGfv/yWNcVx0CMywFrmPs9oAiAmsvpdcqtB/DhNoqUg7QW wF1CXtzfydnjbHd0NQ0h/z8DKniDlHzBeL8KwnAazKWzgcGDvg38V4CQLNWomNpcJwXM EsvgMTD4xgvkmeoDT+sQMbXElhYkUFozD0S6gDiKKycNKbSvvtSTaGCgOEfvg5UW9n6o uRnGj+RLXjQc3yK40t79cloJ1mnw7wOQgaCi8I8rWY4Z0zDZY49V0rB7ED3A8qkJr6bk zEeOfoq8nUGJDMNIOZx9Zk9GHeEjoE2TC4drWu+gDVcNLYov0NBZt1B0KeRA3lLfugYW P9Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=Z2NizKa3; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from pegase1.c-s.fr ([93.17.236.30]) by mx.google.com with ESMTPS id c8si11570828wrp.231.2019.02.19.09.23.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Feb 2019 09:23:13 -0800 (PST) Received-SPF: pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) client-ip=93.17.236.30; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=Z2NizKa3; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 443ncv2MCnz9v4wm; Tue, 19 Feb 2019 18:23:11 +0100 (CET) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=Z2NizKa3; dkim-adsp=pass; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id GeAwTSXGJhWu; Tue, 19 Feb 2019 18:23:11 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 443ncv19Xyz9v4wf; Tue, 19 Feb 2019 18:23:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1550596991; bh=qsRhj0vXokqCATs6bD55xa5yiXGxn2ORcM7fglpoAKM=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=Z2NizKa3yuDfh2pE1+/fIpyRr/azwvHaG3JNm+r3KovQVMXsp7pMSRLqeLHuB1r9n zJ7E4c0RRMi1Vo/lQ6DowJqNR1u0auTNOC0jOjqYWcf1ezy+m0AiXjGrSEoci+tb+5 FqvNMe5flGBdHn4dslC2suk2SERroSS/9EBwj/ng= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id C8DBC8B7FE; Tue, 19 Feb 2019 18:23:12 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id 2ysJhypZQCmG; Tue, 19 Feb 2019 18:23:12 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 7E3B28B7F9; Tue, 19 Feb 2019 18:23:12 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 61E2A6E81D; Tue, 19 Feb 2019 17:23:12 +0000 (UTC) Message-Id: <303c3f274e7d165b955ba6d23b399e055b6e650f.1550596242.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v6 3/6] powerpc: prepare string/mem functions for KASAN To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Nicholas Piggin , Aneesh Kumar K.V , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Daniel Axtens Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Date: Tue, 19 Feb 2019 17:23:12 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP CONFIG_KASAN implements wrappers for memcpy() memmove() and memset() Those wrappers are doing the verification then call respectively __memcpy() __memmove() and __memset(). The arches are therefore expected to rename their optimised functions that way. For files on which KASAN is inhibited, #defines are used to allow them to directly call optimised versions of the functions without going through the KASAN wrappers. See 393f203f5fd5 ("x86_64: kasan: add interceptors for memset/memmove/memcpy functions") for details. Other string / mem functions do not (yet) have kasan wrappers, we therefore have to fallback to the generic versions when KASAN is active, otherwise KASAN checks will be skipped. Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/kasan.h | 15 +++++++++++++++ arch/powerpc/include/asm/string.h | 26 ++++++++++++++++++++++++-- arch/powerpc/kernel/prom_init_check.sh | 10 +++++++++- arch/powerpc/lib/Makefile | 8 ++++++-- arch/powerpc/lib/copy_32.S | 13 +++++++------ arch/powerpc/lib/mem_64.S | 8 ++++---- arch/powerpc/lib/memcpy_64.S | 4 ++-- 7 files changed, 67 insertions(+), 17 deletions(-) create mode 100644 arch/powerpc/include/asm/kasan.h diff --git a/arch/powerpc/include/asm/kasan.h b/arch/powerpc/include/asm/kasan.h new file mode 100644 index 000000000000..2efd0e42cfc9 --- /dev/null +++ b/arch/powerpc/include/asm/kasan.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_KASAN_H +#define __ASM_KASAN_H + +#ifdef CONFIG_KASAN +#define _GLOBAL_KASAN(fn) .weak fn ; _GLOBAL(__##fn) ; _GLOBAL(fn) +#define _GLOBAL_KASAN_TOC(fn) .weak fn ; _GLOBAL_TOC(__##fn) ; _GLOBAL_TOC(fn) +#define EXPORT_SYMBOL_KASAN(fn) EXPORT_SYMBOL(__##fn) ; EXPORT_SYMBOL(fn) +#else +#define _GLOBAL_KASAN(fn) _GLOBAL(fn) +#define _GLOBAL_KASAN_TOC(fn) _GLOBAL_TOC(fn) +#define EXPORT_SYMBOL_KASAN(fn) EXPORT_SYMBOL(fn) +#endif + +#endif diff --git a/arch/powerpc/include/asm/string.h b/arch/powerpc/include/asm/string.h index 1647de15a31e..2aa9ea6751cd 100644 --- a/arch/powerpc/include/asm/string.h +++ b/arch/powerpc/include/asm/string.h @@ -4,13 +4,16 @@ #ifdef __KERNEL__ +#ifndef CONFIG_KASAN #define __HAVE_ARCH_STRNCPY #define __HAVE_ARCH_STRNCMP +#define __HAVE_ARCH_MEMCHR +#define __HAVE_ARCH_MEMCMP +#endif + #define __HAVE_ARCH_MEMSET #define __HAVE_ARCH_MEMCPY #define __HAVE_ARCH_MEMMOVE -#define __HAVE_ARCH_MEMCMP -#define __HAVE_ARCH_MEMCHR #define __HAVE_ARCH_MEMSET16 #define __HAVE_ARCH_MEMCPY_FLUSHCACHE @@ -27,6 +30,25 @@ 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) + +#ifndef __NO_FORTIFY +#define __NO_FORTIFY /* FORTIFY_SOURCE uses __builtin_memcpy, etc. */ +#endif + +#endif + #ifdef CONFIG_PPC64 #define __HAVE_ARCH_MEMSET32 #define __HAVE_ARCH_MEMSET64 diff --git a/arch/powerpc/kernel/prom_init_check.sh b/arch/powerpc/kernel/prom_init_check.sh index 667df97d2595..da6bb16e0876 100644 --- a/arch/powerpc/kernel/prom_init_check.sh +++ b/arch/powerpc/kernel/prom_init_check.sh @@ -16,8 +16,16 @@ # If you really need to reference something from prom_init.o add # it to the list below: +grep CONFIG_KASAN=y .config >/dev/null +if [ $? -eq 0 ] +then + MEMFCT="__memcpy __memset" +else + MEMFCT="memcpy memset" +fi + WHITELIST="add_reloc_offset __bss_start __bss_stop copy_and_flush -_end enter_prom memcpy memset reloc_offset __secondary_hold +_end enter_prom $MEMFCT reloc_offset __secondary_hold __secondary_hold_acknowledge __secondary_hold_spinloop __start strcmp strcpy strlcpy strlen strncmp strstr kstrtobool logo_linux_clut224 reloc_got2 kernstart_addr memstart_addr linux_banner _stext diff --git a/arch/powerpc/lib/Makefile b/arch/powerpc/lib/Makefile index 3bf9fc6fd36c..ee08a7e1bcdf 100644 --- a/arch/powerpc/lib/Makefile +++ b/arch/powerpc/lib/Makefile @@ -8,7 +8,11 @@ ccflags-$(CONFIG_PPC64) := $(NO_MINIMAL_TOC) CFLAGS_REMOVE_code-patching.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_feature-fixups.o = $(CC_FLAGS_FTRACE) -obj-y += string.o alloc.o code-patching.o feature-fixups.o +obj-y += alloc.o code-patching.o feature-fixups.o + +ifndef CONFIG_KASAN +obj-y += string.o memcmp_$(BITS).o +endif obj-$(CONFIG_PPC32) += div64.o copy_32.o crtsavres.o strlen_32.o @@ -33,7 +37,7 @@ obj64-$(CONFIG_ALTIVEC) += vmx-helper.o obj64-$(CONFIG_KPROBES_SANITY_TEST) += test_emulate_step.o obj-y += checksum_$(BITS).o checksum_wrappers.o \ - string_$(BITS).o memcmp_$(BITS).o + string_$(BITS).o obj-y += sstep.o ldstfp.o quad.o obj64-y += quad.o diff --git a/arch/powerpc/lib/copy_32.S b/arch/powerpc/lib/copy_32.S index ba66846fe973..57f48d99fbe3 100644 --- a/arch/powerpc/lib/copy_32.S +++ b/arch/powerpc/lib/copy_32.S @@ -14,6 +14,7 @@ #include #include #include +#include #define COPY_16_BYTES \ lwz r7,4(r4); \ @@ -91,7 +92,7 @@ EXPORT_SYMBOL(memset16) * We therefore skip the optimised bloc that uses dcbz. This jump is * replaced by a nop once cache is active. This is done in machine_init() */ -_GLOBAL(memset) +_GLOBAL_KASAN(memset) cmplwi 0,r5,4 blt 7f @@ -150,7 +151,7 @@ _GLOBAL(memset) 9: stbu r4,1(r6) bdnz 9b blr -EXPORT_SYMBOL(memset) +EXPORT_SYMBOL_KASAN(memset) /* * This version uses dcbz on the complete cache lines in the @@ -163,12 +164,12 @@ EXPORT_SYMBOL(memset) * We therefore jump to generic_memcpy which doesn't use dcbz. This jump is * replaced by a nop once cache is active. This is done in machine_init() */ -_GLOBAL(memmove) +_GLOBAL_KASAN(memmove) cmplw 0,r3,r4 bgt backwards_memcpy /* fall through */ -_GLOBAL(memcpy) +_GLOBAL_KASAN(memcpy) 1: b generic_memcpy patch_site 1b, patch__memcpy_nocache @@ -242,8 +243,8 @@ _GLOBAL(memcpy) stbu r0,1(r6) bdnz 40b 65: blr -EXPORT_SYMBOL(memcpy) -EXPORT_SYMBOL(memmove) +EXPORT_SYMBOL_KASAN(memcpy) +EXPORT_SYMBOL_KASAN(memmove) generic_memcpy: srwi. r7,r5,3 diff --git a/arch/powerpc/lib/mem_64.S b/arch/powerpc/lib/mem_64.S index 3c3be02f33b7..57c8a940c29c 100644 --- a/arch/powerpc/lib/mem_64.S +++ b/arch/powerpc/lib/mem_64.S @@ -30,7 +30,7 @@ EXPORT_SYMBOL(__memset16) EXPORT_SYMBOL(__memset32) EXPORT_SYMBOL(__memset64) -_GLOBAL(memset) +_GLOBAL_KASAN(memset) neg r0,r3 rlwimi r4,r4,8,16,23 andi. r0,r0,7 /* # bytes to be 8-byte aligned */ @@ -95,9 +95,9 @@ _GLOBAL(memset) 10: bflr 31 stb r4,0(r6) blr -EXPORT_SYMBOL(memset) +EXPORT_SYMBOL_KASAN(memset) -_GLOBAL_TOC(memmove) +_GLOBAL_TOC_KASAN(memmove) cmplw 0,r3,r4 bgt backwards_memcpy b memcpy @@ -138,4 +138,4 @@ _GLOBAL(backwards_memcpy) beq 2b mtctr r7 b 1b -EXPORT_SYMBOL(memmove) +EXPORT_SYMBOL_KASAN(memmove) diff --git a/arch/powerpc/lib/memcpy_64.S b/arch/powerpc/lib/memcpy_64.S index 273ea67e60a1..2d5358cee711 100644 --- a/arch/powerpc/lib/memcpy_64.S +++ b/arch/powerpc/lib/memcpy_64.S @@ -18,7 +18,7 @@ #endif .align 7 -_GLOBAL_TOC(memcpy) +_GLOBAL_TOC_KASAN(memcpy) BEGIN_FTR_SECTION #ifdef __LITTLE_ENDIAN__ cmpdi cr7,r5,0 @@ -229,4 +229,4 @@ END_FTR_SECTION_IFCLR(CPU_FTR_UNALIGNED_LD_STD) 4: ld r3,-STACKFRAMESIZE+STK_REG(R31)(r1) /* return dest pointer */ blr #endif -EXPORT_SYMBOL(memcpy) +EXPORT_SYMBOL_KASAN(memcpy) From patchwork Tue Feb 19 17:23:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10820499 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AA3E81399 for ; Tue, 19 Feb 2019 17:23:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 85C472D193 for ; Tue, 19 Feb 2019 17:23:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 83C112D1A5; Tue, 19 Feb 2019 17:23:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 001C22D19E for ; Tue, 19 Feb 2019 17:23:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DEB6B8E0007; Tue, 19 Feb 2019 12:23:18 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D76168E0002; Tue, 19 Feb 2019 12:23:18 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AB37D8E0007; Tue, 19 Feb 2019 12:23:18 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by kanga.kvack.org (Postfix) with ESMTP id 387C08E0002 for ; Tue, 19 Feb 2019 12:23:18 -0500 (EST) Received: by mail-wm1-f72.google.com with SMTP id f193so969917wme.8 for ; Tue, 19 Feb 2019 09:23:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:message-id:in-reply-to:references :from:subject:to:cc:date; bh=Yw2ZtQrJ1HYjYkdCLzo3FNLSK6gpGmVkHVd7ituMUWY=; b=it1O/pTCryZ5V371uTFND0WrmyFg8tNsggzS/lE/QvV8LDidw/szEBjIx1ZUF7RJ8h Lyi9jNxc/Kzo+daNVSAWBUfwI/rQaIt1WqApjwglgTwNxwZhRvV9qGqIaCdwZvaz51QV exNF2qrHOcgXEY8esWu6YByp7sLY8hJ+E9AziVVQQjJ17AHPrCXT6l4BLwQoa5/ZCy8V zgukvJal2rHBKgn9dG9zHLyoowoIcgTmNX9yPvAo+Kr+PfcfhtmKsAkqMQ1Y0ol8Flh3 WvDEJGxe7UrIea5AIJ5tDsHUm3EeLrkDiqQjbuy8C/3yILlG9t9zaqyJcxgnaNMOxFNW isqg== X-Gm-Message-State: AHQUAuYCbhXDpKmaOK98CcHdN0tRvnTF12XBj5wHfGC3uqeUjN6iuezZ YYDyGPKSS8ej12qLUUBcMpgGnDAr+kEMMQXyFIGQuCMeQ697jUWiBNOXbczeMVTIS9CLxBq+b5l a6qMazx4WbqXtiN2nfimAWXkKbg15wbVYDTM187o+ccyD8bytVOeJ61/WhA/TYvq9Cw== X-Received: by 2002:a1c:f901:: with SMTP id x1mr3643122wmh.84.1550596997677; Tue, 19 Feb 2019 09:23:17 -0800 (PST) X-Google-Smtp-Source: AHgI3IZx/8XAoIgcjCBDjSCKkkmikg0+JbsrJMqxF/m/68joIfLS4WjQvXDeW1eAcbizAnDq5XKI X-Received: by 2002:a1c:f901:: with SMTP id x1mr3643041wmh.84.1550596995674; Tue, 19 Feb 2019 09:23:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550596995; cv=none; d=google.com; s=arc-20160816; b=GL0WpvN3PyYcFagtx9u7q2mAOvGuTO4i3NjyGy0bDrZqlodnpJk3gFLrQ5GCCkDRQ3 iy0WF+ziLnWCoPiBOqyUKrEV/eLz2Hm4ieDAwE9dPThukhDbbNL3cjrXUrjf3EkX8zAw jhBykGjsx/dIzrGbdiT+kto3sdQ+gB/qDHJ2H+mIoXCWoEgExeEmzh7eC9BhEMXqffjz 7fomaeV6D9rEe47JIqehsAOWekjuJ6w4YcZUabKnEqRCRy0O+Yae0pf29vh8llTYs9sv 8aisqA3fOoloB8pC3edxpZKehJmselTjYUWD8F+z/VC3ZjHgZusHu0pRecJWgyLoqcZn auHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:cc:to:subject:from:references:in-reply-to:message-id :dkim-signature; bh=Yw2ZtQrJ1HYjYkdCLzo3FNLSK6gpGmVkHVd7ituMUWY=; b=iKMbT4/ulH3zCjMgeNEggBGTlwyBE/sTux6yH8FvFdOmqB56m5mK9B7CHdeex+kA3K Wnvy58xLUgZqTMKUbxkP1y6ccpYIue7Z6HUHAlNgNOgs3iVdzE62IimyIHeJ2nqgNnPr uW3gf02CXOfbSVNBfxVXnYs/8XfHjt3OmN/rORkF+cdkpG1xHTuiHm/4O7HxyjYwd0KG whF4L1EO9sekS9sAYCS8DxBTCEm3vngUj5jbKuBbDebuuqkQM6wv8WpKw87zZyl/im9P hGQdetcMBmnEXIIunQqfSoOh75OM1KeuFTvLGh59TzsGFQh89AdhQ2+ktvShJyzepLp7 8txQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=lZqqumOq; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from pegase1.c-s.fr (pegase1.c-s.fr. [93.17.236.30]) by mx.google.com with ESMTPS id t26si1827319wmj.126.2019.02.19.09.23.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Feb 2019 09:23:15 -0800 (PST) Received-SPF: pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) client-ip=93.17.236.30; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=lZqqumOq; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 443ncx3gmdz9v4wn; Tue, 19 Feb 2019 18:23:13 +0100 (CET) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=lZqqumOq; dkim-adsp=pass; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id mlDnaT9CFsDG; Tue, 19 Feb 2019 18:23:13 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 443ncx2XC1z9v4wf; Tue, 19 Feb 2019 18:23:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1550596993; bh=Yw2ZtQrJ1HYjYkdCLzo3FNLSK6gpGmVkHVd7ituMUWY=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=lZqqumOq6PMrhqsmWZo01352DCKv7o5Ra/5njZJvl+TReTFxEfRv7vRepDoLd5+5f FO3VLtB4GpYOOuVd9OH6UTbDktQYGXdhvkuJtiMafH7E7EYCbNEOtrJQ231P0iqTUG oY7kCB5htNYWVGl7VnHmM9o/96cwdUcO+LWThJp0= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id F3B8E8B7FE; Tue, 19 Feb 2019 18:23:14 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id a-4ips5300rl; Tue, 19 Feb 2019 18:23:14 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 8F3358B7F9; Tue, 19 Feb 2019 18:23:14 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 683996E81D; Tue, 19 Feb 2019 17:23:14 +0000 (UTC) Message-Id: In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v6 4/6] powerpc/32: Add KASAN support To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Nicholas Piggin , Aneesh Kumar K.V , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Daniel Axtens Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Date: Tue, 19 Feb 2019 17:23:14 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This patch adds KASAN support for PPC32. The KASAN shadow area is located between the vmalloc area and the fixmap area. KASAN_SHADOW_OFFSET is calculated in asm/kasan.h and extracted by Makefile prepare rule via asm-offsets.h For modules, the shadow area is allocated at module_alloc(). Note that on book3s it will only work on the 603 because the other ones use hash table and can therefore not share a single PTE table covering the entire early KASAN shadow area. Signed-off-by: Christophe Leroy --- arch/powerpc/Kconfig | 1 + arch/powerpc/Makefile | 7 ++ arch/powerpc/include/asm/book3s/32/pgtable.h | 2 + arch/powerpc/include/asm/highmem.h | 10 +- arch/powerpc/include/asm/kasan.h | 23 ++++ arch/powerpc/include/asm/nohash/32/pgtable.h | 2 + arch/powerpc/include/asm/setup.h | 5 + arch/powerpc/kernel/Makefile | 9 +- arch/powerpc/kernel/asm-offsets.c | 4 + arch/powerpc/kernel/head_32.S | 3 + arch/powerpc/kernel/head_40x.S | 3 + arch/powerpc/kernel/head_44x.S | 3 + arch/powerpc/kernel/head_8xx.S | 3 + arch/powerpc/kernel/head_fsl_booke.S | 3 + arch/powerpc/kernel/setup-common.c | 2 + arch/powerpc/lib/Makefile | 8 ++ arch/powerpc/mm/Makefile | 1 + arch/powerpc/mm/kasan/Makefile | 5 + arch/powerpc/mm/kasan/kasan_init_32.c | 147 ++++++++++++++++++++++++++ arch/powerpc/mm/mem.c | 4 + arch/powerpc/mm/ptdump/dump_linuxpagetables.c | 8 ++ arch/powerpc/purgatory/Makefile | 3 + arch/powerpc/xmon/Makefile | 1 + 23 files changed, 253 insertions(+), 4 deletions(-) create mode 100644 arch/powerpc/mm/kasan/Makefile create mode 100644 arch/powerpc/mm/kasan/kasan_init_32.c diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 08908219fba9..850b06def84f 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -175,6 +175,7 @@ config PPC select GENERIC_TIME_VSYSCALL select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_JUMP_LABEL + select HAVE_ARCH_KASAN if PPC32 select HAVE_ARCH_KGDB select HAVE_ARCH_MMAP_RND_BITS select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile index ac033341ed55..f0738099e31e 100644 --- a/arch/powerpc/Makefile +++ b/arch/powerpc/Makefile @@ -427,6 +427,13 @@ else endif endif +ifdef CONFIG_KASAN +prepare: kasan_prepare + +kasan_prepare: prepare0 + $(eval KASAN_SHADOW_OFFSET = $(shell awk '{if ($$2 == "KASAN_SHADOW_OFFSET") print $$3;}' include/generated/asm-offsets.h)) +endif + # Check toolchain versions: # - gcc-4.6 is the minimum kernel-wide version so nothing required. checkbin: diff --git a/arch/powerpc/include/asm/book3s/32/pgtable.h b/arch/powerpc/include/asm/book3s/32/pgtable.h index 49d76adb9bc5..4543016f80ca 100644 --- a/arch/powerpc/include/asm/book3s/32/pgtable.h +++ b/arch/powerpc/include/asm/book3s/32/pgtable.h @@ -141,6 +141,8 @@ static inline bool pte_user(pte_t pte) */ #ifdef CONFIG_HIGHMEM #define KVIRT_TOP PKMAP_BASE +#elif defined(CONFIG_KASAN) +#define KVIRT_TOP KASAN_SHADOW_START #else #define KVIRT_TOP (0xfe000000UL) /* for now, could be FIXMAP_BASE ? */ #endif diff --git a/arch/powerpc/include/asm/highmem.h b/arch/powerpc/include/asm/highmem.h index a4b65b186ec6..483b90025bef 100644 --- a/arch/powerpc/include/asm/highmem.h +++ b/arch/powerpc/include/asm/highmem.h @@ -28,6 +28,7 @@ #include #include #include +#include extern pte_t *kmap_pte; extern pgprot_t kmap_prot; @@ -50,10 +51,15 @@ extern pte_t *pkmap_page_table; #define PKMAP_ORDER 9 #endif #define LAST_PKMAP (1 << PKMAP_ORDER) +#ifdef CONFIG_KASAN +#define PKMAP_TOP KASAN_SHADOW_START +#else +#define PKMAP_TOP FIXADDR_START +#endif #ifndef CONFIG_PPC_4K_PAGES -#define PKMAP_BASE (FIXADDR_START - PAGE_SIZE*(LAST_PKMAP + 1)) +#define PKMAP_BASE (PKMAP_TOP - PAGE_SIZE*(LAST_PKMAP + 1)) #else -#define PKMAP_BASE ((FIXADDR_START - PAGE_SIZE*(LAST_PKMAP + 1)) & PMD_MASK) +#define PKMAP_BASE ((PKMAP_TOP - PAGE_SIZE*(LAST_PKMAP + 1)) & PMD_MASK) #endif #define LAST_PKMAP_MASK (LAST_PKMAP-1) #define PKMAP_NR(virt) ((virt-PKMAP_BASE) >> PAGE_SHIFT) diff --git a/arch/powerpc/include/asm/kasan.h b/arch/powerpc/include/asm/kasan.h index 2efd0e42cfc9..0bc9148f5d87 100644 --- a/arch/powerpc/include/asm/kasan.h +++ b/arch/powerpc/include/asm/kasan.h @@ -12,4 +12,27 @@ #define EXPORT_SYMBOL_KASAN(fn) EXPORT_SYMBOL(fn) #endif +#ifndef __ASSEMBLY__ + +#include +#include + +#define KASAN_SHADOW_SCALE_SHIFT 3 + +#define KASAN_SHADOW_OFFSET (KASAN_SHADOW_START - \ + (PAGE_OFFSET >> KASAN_SHADOW_SCALE_SHIFT)) + +#define KASAN_SHADOW_END (KASAN_SHADOW_START + KASAN_SHADOW_SIZE) + +#include + +#define KASAN_SHADOW_START (ALIGN_DOWN(FIXADDR_START - KASAN_SHADOW_SIZE, \ + PGDIR_SIZE)) + +#define KASAN_SHADOW_SIZE ((~0UL - PAGE_OFFSET + 1) >> KASAN_SHADOW_SCALE_SHIFT) + +void kasan_early_init(void); +void kasan_init(void); + +#endif /* __ASSEMBLY */ #endif diff --git a/arch/powerpc/include/asm/nohash/32/pgtable.h b/arch/powerpc/include/asm/nohash/32/pgtable.h index bed433358260..b3b52f02be1a 100644 --- a/arch/powerpc/include/asm/nohash/32/pgtable.h +++ b/arch/powerpc/include/asm/nohash/32/pgtable.h @@ -71,6 +71,8 @@ extern int icache_44x_need_flush; */ #ifdef CONFIG_HIGHMEM #define KVIRT_TOP PKMAP_BASE +#elif defined(CONFIG_KASAN) +#define KVIRT_TOP KASAN_SHADOW_START #else #define KVIRT_TOP (0xfe000000UL) /* for now, could be FIXMAP_BASE ? */ #endif diff --git a/arch/powerpc/include/asm/setup.h b/arch/powerpc/include/asm/setup.h index 65676e2325b8..da7768aa996a 100644 --- a/arch/powerpc/include/asm/setup.h +++ b/arch/powerpc/include/asm/setup.h @@ -74,6 +74,11 @@ static inline void setup_spectre_v2(void) {}; #endif void do_btb_flush_fixups(void); +#ifndef CONFIG_KASAN +static inline void kasan_early_init(void) { } +static inline void kasan_init(void) { } +#endif + #endif /* !__ASSEMBLY__ */ #endif /* _ASM_POWERPC_SETUP_H */ diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile index 879b36602748..fc4c42262694 100644 --- a/arch/powerpc/kernel/Makefile +++ b/arch/powerpc/kernel/Makefile @@ -16,8 +16,9 @@ CFLAGS_prom_init.o += -fPIC CFLAGS_btext.o += -fPIC endif -CFLAGS_cputable.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) -CFLAGS_prom_init.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) +CFLAGS_early_32.o += -DDISABLE_BRANCH_PROFILING +CFLAGS_cputable.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) -DDISABLE_BRANCH_PROFILING +CFLAGS_prom_init.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) -DDISABLE_BRANCH_PROFILING CFLAGS_btext.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) CFLAGS_prom.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) @@ -31,6 +32,10 @@ CFLAGS_REMOVE_btext.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_prom.o = $(CC_FLAGS_FTRACE) endif +KASAN_SANITIZE_early_32.o := n +KASAN_SANITIZE_cputable.o := n +KASAN_SANITIZE_prom_init.o := n + obj-y := cputable.o ptrace.o syscalls.o \ irq.o align.o signal_32.o pmc.o vdso.o \ process.o systbl.o idle.o \ diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c index 9ffc72ded73a..846fb30b1190 100644 --- a/arch/powerpc/kernel/asm-offsets.c +++ b/arch/powerpc/kernel/asm-offsets.c @@ -783,5 +783,9 @@ int main(void) DEFINE(VIRT_IMMR_BASE, (u64)__fix_to_virt(FIX_IMMR_BASE)); #endif +#ifdef CONFIG_KASAN + DEFINE(KASAN_SHADOW_OFFSET, KASAN_SHADOW_OFFSET); +#endif + return 0; } diff --git a/arch/powerpc/kernel/head_32.S b/arch/powerpc/kernel/head_32.S index 05b08db3901d..0ec9dec06bc2 100644 --- a/arch/powerpc/kernel/head_32.S +++ b/arch/powerpc/kernel/head_32.S @@ -962,6 +962,9 @@ start_here: * Do early platform-specific initialization, * and set up the MMU. */ +#ifdef CONFIG_KASAN + bl kasan_early_init +#endif li r3,0 mr r4,r31 bl machine_init diff --git a/arch/powerpc/kernel/head_40x.S b/arch/powerpc/kernel/head_40x.S index b19d78410511..5d6ff8fa7e2b 100644 --- a/arch/powerpc/kernel/head_40x.S +++ b/arch/powerpc/kernel/head_40x.S @@ -848,6 +848,9 @@ start_here: /* * Decide what sort of machine this is and initialize the MMU. */ +#ifdef CONFIG_KASAN + bl kasan_early_init +#endif li r3,0 mr r4,r31 bl machine_init diff --git a/arch/powerpc/kernel/head_44x.S b/arch/powerpc/kernel/head_44x.S index bf23c19c92d6..7ca14dff6192 100644 --- a/arch/powerpc/kernel/head_44x.S +++ b/arch/powerpc/kernel/head_44x.S @@ -203,6 +203,9 @@ _ENTRY(_start); /* * Decide what sort of machine this is and initialize the MMU. */ +#ifdef CONFIG_KASAN + bl kasan_early_init +#endif li r3,0 mr r4,r31 bl machine_init diff --git a/arch/powerpc/kernel/head_8xx.S b/arch/powerpc/kernel/head_8xx.S index fe2857ef0309..88f0cb34cef4 100644 --- a/arch/powerpc/kernel/head_8xx.S +++ b/arch/powerpc/kernel/head_8xx.S @@ -823,6 +823,9 @@ start_here: /* * Decide what sort of machine this is and initialize the MMU. */ +#ifdef CONFIG_KASAN + bl kasan_early_init +#endif li r3,0 mr r4,r31 bl machine_init diff --git a/arch/powerpc/kernel/head_fsl_booke.S b/arch/powerpc/kernel/head_fsl_booke.S index 2386ce2a9c6e..4f4585a68850 100644 --- a/arch/powerpc/kernel/head_fsl_booke.S +++ b/arch/powerpc/kernel/head_fsl_booke.S @@ -274,6 +274,9 @@ set_ivor: /* * Decide what sort of machine this is and initialize the MMU. */ +#ifdef CONFIG_KASAN + bl kasan_early_init +#endif mr r3,r30 mr r4,r31 bl machine_init diff --git a/arch/powerpc/kernel/setup-common.c b/arch/powerpc/kernel/setup-common.c index ca00fbb97cf8..16ff1ea66805 100644 --- a/arch/powerpc/kernel/setup-common.c +++ b/arch/powerpc/kernel/setup-common.c @@ -978,6 +978,8 @@ void __init setup_arch(char **cmdline_p) paging_init(); + kasan_init(); + /* Initialize the MMU context management stuff. */ mmu_context_init(); diff --git a/arch/powerpc/lib/Makefile b/arch/powerpc/lib/Makefile index ee08a7e1bcdf..7efbd5122c74 100644 --- a/arch/powerpc/lib/Makefile +++ b/arch/powerpc/lib/Makefile @@ -8,6 +8,14 @@ ccflags-$(CONFIG_PPC64) := $(NO_MINIMAL_TOC) CFLAGS_REMOVE_code-patching.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_feature-fixups.o = $(CC_FLAGS_FTRACE) +KASAN_SANITIZE_code-patching.o := n +KASAN_SANITIZE_feature-fixups.o := n + +ifdef CONFIG_KASAN +CFLAGS_code-patching.o += -DDISABLE_BRANCH_PROFILING +CFLAGS_feature-fixups.o += -DDISABLE_BRANCH_PROFILING +endif + obj-y += alloc.o code-patching.o feature-fixups.o ifndef CONFIG_KASAN diff --git a/arch/powerpc/mm/Makefile b/arch/powerpc/mm/Makefile index ee1efa3b3382..292b96ce1efc 100644 --- a/arch/powerpc/mm/Makefile +++ b/arch/powerpc/mm/Makefile @@ -47,3 +47,4 @@ obj-$(CONFIG_PPC_COPRO_BASE) += copro_fault.o obj-$(CONFIG_SPAPR_TCE_IOMMU) += mmu_context_iommu.o obj-$(CONFIG_PPC_PTDUMP) += ptdump/ obj-$(CONFIG_PPC_MEM_KEYS) += pkeys.o +obj-$(CONFIG_KASAN) += kasan/ diff --git a/arch/powerpc/mm/kasan/Makefile b/arch/powerpc/mm/kasan/Makefile new file mode 100644 index 000000000000..6577897673dd --- /dev/null +++ b/arch/powerpc/mm/kasan/Makefile @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 + +KASAN_SANITIZE := n + +obj-$(CONFIG_PPC32) += kasan_init_32.o diff --git a/arch/powerpc/mm/kasan/kasan_init_32.c b/arch/powerpc/mm/kasan/kasan_init_32.c new file mode 100644 index 000000000000..495c908d6ee6 --- /dev/null +++ b/arch/powerpc/mm/kasan/kasan_init_32.c @@ -0,0 +1,147 @@ +// SPDX-License-Identifier: GPL-2.0 + +#define DISABLE_BRANCH_PROFILING + +#include +#include +#include +#include +#include +#include + +void __init kasan_early_init(void) +{ + unsigned long addr = KASAN_SHADOW_START; + unsigned long end = KASAN_SHADOW_END; + unsigned long next; + pmd_t *pmd = pmd_offset(pud_offset(pgd_offset_k(addr), addr), addr); + int i; + phys_addr_t pa = __pa(kasan_early_shadow_page); + + BUILD_BUG_ON(KASAN_SHADOW_START & ~PGDIR_MASK); + + if (early_mmu_has_feature(MMU_FTR_HPTE_TABLE)) + panic("KASAN not supported with Hash MMU\n"); + + for (i = 0; i < PTRS_PER_PTE; i++) + __set_pte_at(&init_mm, (unsigned long)kasan_early_shadow_page, + kasan_early_shadow_pte + i, + pfn_pte(PHYS_PFN(pa), PAGE_KERNEL), 0); + + do { + next = pgd_addr_end(addr, end); + pmd_populate_kernel(&init_mm, pmd, kasan_early_shadow_pte); + } while (pmd++, addr = next, addr != end); +} + +static void __ref *kasan_get_one_page(void) +{ + if (slab_is_available()) + return (void *)__get_free_page(GFP_KERNEL|__GFP_ZERO); + + return memblock_alloc(PAGE_SIZE, PAGE_SIZE); +} + +static int __ref kasan_init_region(void *start, size_t size) +{ + void *end = start + size; + unsigned long k_start, k_end, k_cur, k_next; + pmd_t *pmd; + void *block = NULL; + + if (start >= end) + return 0; + + k_start = (unsigned long)kasan_mem_to_shadow(start); + k_end = (unsigned long)kasan_mem_to_shadow(end); + pmd = pmd_offset(pud_offset(pgd_offset_k(k_start), k_start), k_start); + + for (k_cur = k_start; k_cur != k_end; k_cur = k_next, pmd++) { + k_next = pgd_addr_end(k_cur, k_end); + if ((void *)pmd_page_vaddr(*pmd) == kasan_early_shadow_pte) { + pte_t *new = pte_alloc_one_kernel(&init_mm); + + if (!new) + return -ENOMEM; + memcpy(new, kasan_early_shadow_pte, PTE_TABLE_SIZE); + pmd_populate_kernel(&init_mm, pmd, new); + } + }; + + if (!slab_is_available()) + block = memblock_alloc(k_end - k_start, PAGE_SIZE); + + for (k_cur = k_start; k_cur < k_end; k_cur += PAGE_SIZE) { + void *va = block ? block + k_cur - k_start : + kasan_get_one_page(); + pte_t pte = pfn_pte(PHYS_PFN(__pa(va)), PAGE_KERNEL); + + if (!va) + return -ENOMEM; + + pmd = pmd_offset(pud_offset(pgd_offset_k(k_cur), k_cur), k_cur); + pte_update(pte_offset_kernel(pmd, k_cur), ~0, pte_val(pte)); + } + flush_tlb_kernel_range(k_start, k_end); + return 0; +} + +static void __init kasan_remap_early_shadow_ro(void) +{ + unsigned long k_cur; + phys_addr_t pa = __pa(kasan_early_shadow_page); + int i; + + for (i = 0; i < PTRS_PER_PTE; i++) + ptep_set_wrprotect(&init_mm, 0, kasan_early_shadow_pte + i); + + for (k_cur = PAGE_OFFSET & PAGE_MASK; k_cur; k_cur += PAGE_SIZE) { + pmd_t *pmd = pmd_offset(pud_offset(pgd_offset_k(k_cur), k_cur), k_cur); + pte_t *ptep = pte_offset_kernel(pmd, k_cur); + + if ((void *)pmd_page_vaddr(*pmd) == kasan_early_shadow_pte) + continue; + if ((pte_val(*ptep) & PAGE_MASK) != pa) + continue; + + ptep_set_wrprotect(&init_mm, k_cur, ptep); + } + flush_tlb_mm(&init_mm); +} + +void __init kasan_init(void) +{ + struct memblock_region *reg; + + for_each_memblock(memory, reg) { + int ret = kasan_init_region(__va(reg->base), reg->size); + + if (ret) + panic("kasan: kasan_init_region() failed"); + } + + kasan_remap_early_shadow_ro(); + + clear_page(kasan_early_shadow_page); + + /* At this point kasan is fully initialized. Enable error messages */ + init_task.kasan_depth = 0; + pr_info("KASAN init done\n"); +} + +#ifdef CONFIG_MODULES +void *module_alloc(unsigned long size) +{ + void *base = vmalloc_exec(size); + + if (!base) + return NULL; + + if (!kasan_init_region(base, size)) + return base; + + vfree(base); + + return NULL; +} +#endif diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c index 81f251fc4169..1bb055775e60 100644 --- a/arch/powerpc/mm/mem.c +++ b/arch/powerpc/mm/mem.c @@ -336,6 +336,10 @@ void __init mem_init(void) pr_info(" * 0x%08lx..0x%08lx : highmem PTEs\n", PKMAP_BASE, PKMAP_ADDR(LAST_PKMAP)); #endif /* CONFIG_HIGHMEM */ +#ifdef CONFIG_KASAN + pr_info(" * 0x%08lx..0x%08lx : kasan shadow mem\n", + KASAN_SHADOW_START, KASAN_SHADOW_END); +#endif #ifdef CONFIG_NOT_COHERENT_CACHE pr_info(" * 0x%08lx..0x%08lx : consistent mem\n", IOREMAP_TOP, IOREMAP_TOP + CONFIG_CONSISTENT_SIZE); diff --git a/arch/powerpc/mm/ptdump/dump_linuxpagetables.c b/arch/powerpc/mm/ptdump/dump_linuxpagetables.c index b0da447197d4..4a03910974e2 100644 --- a/arch/powerpc/mm/ptdump/dump_linuxpagetables.c +++ b/arch/powerpc/mm/ptdump/dump_linuxpagetables.c @@ -94,6 +94,10 @@ static struct addr_marker address_markers[] = { { 0, "Consistent mem start" }, { 0, "Consistent mem end" }, #endif +#ifdef CONFIG_KASAN + { 0, "kasan shadow mem start" }, + { 0, "kasan shadow mem end" }, +#endif #ifdef CONFIG_HIGHMEM { 0, "Highmem PTEs start" }, { 0, "Highmem PTEs end" }, @@ -316,6 +320,10 @@ static void populate_markers(void) address_markers[i++].start_address = IOREMAP_TOP + CONFIG_CONSISTENT_SIZE; #endif +#ifdef CONFIG_KASAN + address_markers[i++].start_address = KASAN_SHADOW_START; + address_markers[i++].start_address = KASAN_SHADOW_END; +#endif #ifdef CONFIG_HIGHMEM address_markers[i++].start_address = PKMAP_BASE; address_markers[i++].start_address = PKMAP_ADDR(LAST_PKMAP); diff --git a/arch/powerpc/purgatory/Makefile b/arch/powerpc/purgatory/Makefile index 4314ba5baf43..7c6d8b14f440 100644 --- a/arch/powerpc/purgatory/Makefile +++ b/arch/powerpc/purgatory/Makefile @@ -1,4 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 + +KASAN_SANITIZE := n + targets += trampoline.o purgatory.ro kexec-purgatory.c LDFLAGS_purgatory.ro := -e purgatory_start -r --no-undefined diff --git a/arch/powerpc/xmon/Makefile b/arch/powerpc/xmon/Makefile index 878f9c1d3615..064f7062c0a3 100644 --- a/arch/powerpc/xmon/Makefile +++ b/arch/powerpc/xmon/Makefile @@ -6,6 +6,7 @@ subdir-ccflags-y := $(call cc-disable-warning, builtin-requires-header) GCOV_PROFILE := n UBSAN_SANITIZE := n +KASAN_SANITIZE := n # Disable ftrace for the entire directory ORIG_CFLAGS := $(KBUILD_CFLAGS) From patchwork Tue Feb 19 17:23:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10820501 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B1AF66C2 for ; Tue, 19 Feb 2019 17:23:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 91F2A2D157 for ; Tue, 19 Feb 2019 17:23:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F8EC2D1C0; Tue, 19 Feb 2019 17:23:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ECF9D2D1C0 for ; Tue, 19 Feb 2019 17:23:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7A8708E0002; Tue, 19 Feb 2019 12:23:19 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7079F8E0008; Tue, 19 Feb 2019 12:23:19 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A9C08E0002; Tue, 19 Feb 2019 12:23:19 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by kanga.kvack.org (Postfix) with ESMTP id F3AB78E0008 for ; Tue, 19 Feb 2019 12:23:18 -0500 (EST) Received: by mail-wm1-f71.google.com with SMTP id q126so970561wme.7 for ; Tue, 19 Feb 2019 09:23:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:message-id:in-reply-to:references :from:subject:to:cc:date; bh=RqJsxIhTANQKnqRZhq3GM2+DKQlwq3Vr2BGgpdQ32hQ=; b=ZzMV+oUHrMfvQi4SVuw7RPRUYdngYI+5FAjwmCnYnp1khFnzfvyFzDmP0Gm+2Pc6ad m1Jn7QnBBwHPz4rlPSHr5pY/kchWAUayzgoKqdbI5fGGmxHcYGgYEKmVMpwMccG4oriN 04ht0bX0K9T9zxkwQ/BHjMciddl4OI6jy2KbPAv1+iWBNoUKwJJI0UFyMvxPVM8Fvl+d /MCpQ54tg9TilEcuYMtPE+5nkh31pA301Nnd2k/53QsvrrdpVetfL5u6LXkWwN8kQQXF f0ymRd6rcnF7sE/Pk/EfY/Uc99tNaTgN3qnGE8E7YSGX7UASjLnqkt57oEIZRJLoO8ig qmSA== X-Gm-Message-State: AHQUAuaPqtDXBm09j3gOwC5A7BXyUzjoqnUe6lwhsbTVF9eVFcA5vRVA YL2AFHLSoe/3q3gpmwbynsxSEpnigAJyp7J1WYZUzmk/ZefZ4u21x/vS6jeOAZQNI7/93pzFGSc q0kzFkKCQ27AwQ5ClgqgoWt56qRU/A2K+JGqC/j6G00YNYgvmZu4lrOZlBZCaLacu1g== X-Received: by 2002:a1c:7511:: with SMTP id o17mr3559824wmc.42.1550596998499; Tue, 19 Feb 2019 09:23:18 -0800 (PST) X-Google-Smtp-Source: AHgI3IZCqUe91RsuhoZ635R0k7KRV2tzLJzL6xBKUqYmf/W3D+UwEn11cTeg272zwY94abgJtuiz X-Received: by 2002:a1c:7511:: with SMTP id o17mr3559775wmc.42.1550596997493; Tue, 19 Feb 2019 09:23:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550596997; cv=none; d=google.com; s=arc-20160816; b=EOnwA4r/++ecA0HOahs75Q+ooAp1ckIx2L3+5VAMqQanpbTt1/XBTc7xjdxZ76bDde 4vl7JIHg5rjtGixXLAi4TjWdBVep1N4NbgcIcLHGylPkCk2joCVArPvrDlBGsuT2IC90 S0SpGUXN/TrkeCMTE8wz2D3zDjgsW1wg/ETYuvu8lBRjEvSyVkszA37r0DfKfE7B5tv3 9gwKwD9IxUP7KP5T0B0JcmWiDakfqDcZUi9i6iBD1oneLh2bPSCAvqOMmpqINP5Vp95n IBSUnCQ1Iof2vnSwUyDN6kNri3ogZm4ThHDzcsLnguHvt08eXsS0SuQxYl8IL4XIrgaa nkww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:cc:to:subject:from:references:in-reply-to:message-id :dkim-signature; bh=RqJsxIhTANQKnqRZhq3GM2+DKQlwq3Vr2BGgpdQ32hQ=; b=T7bcTcvsuc0EA17RHj4L4uEqP3KjL8FppQPJkTBG4u+l3TOHIPCUxYvOOV86xtARIO GN+V4bCpnrqIpbYxIm79QhioLqlOTwWiOkMEzq0IuvyWPNm+obRFkAX8EE5wA+zPMZU9 vsncMkz8wXkkrwtgyrrhXwLwgWBMVKpOlF1nikK03gLgh13pFMGFr1+FpLoa44dbiuqT yzsvnGXbYr8Gj9q3d8AiumoBt0eqsM7gCkWZ3VQJfof+bVQNquPkSIGUxMVA0US7Wl0D l7ov9cClqd65CdGdc0e0FYLbnh1oV9dyCfKBDQ5JMX/NACgxuQg1fz5vskWbdR09KkQj vhLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=DeIcy5m6; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from pegase1.c-s.fr (pegase1.c-s.fr. [93.17.236.30]) by mx.google.com with ESMTPS id p185si1868763wme.188.2019.02.19.09.23.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Feb 2019 09:23:17 -0800 (PST) Received-SPF: pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) client-ip=93.17.236.30; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=DeIcy5m6; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 443ncz2CDBz9v4wg; Tue, 19 Feb 2019 18:23:15 +0100 (CET) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=DeIcy5m6; dkim-adsp=pass; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id CpEQ0pBH1KSX; Tue, 19 Feb 2019 18:23:15 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 443ncz12hqz9v4wf; Tue, 19 Feb 2019 18:23:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1550596995; bh=RqJsxIhTANQKnqRZhq3GM2+DKQlwq3Vr2BGgpdQ32hQ=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=DeIcy5m6M9wZSKEodSFq/7LxoFd+RwflVuC7e9pIaf5A4sLTdV+IovFCpLtsjQACt loLCSLdw72urjv816h9J4pZK1G1ePq00eTG5KUdOWNc200bArr6smG9T8/IY8q4Ley PhbLP/uxG1CE95fSdKO7k6PvHs/jTgd9H/ZB6eQo= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id C10178B7FE; Tue, 19 Feb 2019 18:23:16 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id ZTiqLc4V9f7e; Tue, 19 Feb 2019 18:23:16 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 913578B7F9; Tue, 19 Feb 2019 18:23:16 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 6E4BF6E81D; Tue, 19 Feb 2019 17:23:16 +0000 (UTC) Message-Id: <7f8dfeeb13b54f9518f78d9c8550a3769d144fc3.1550596242.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v6 5/6] kasan: allow architectures to provide an outline readiness check To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Nicholas Piggin , Aneesh Kumar K.V , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Daniel Axtens Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Date: Tue, 19 Feb 2019 17:23:16 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Daniel Axtens In powerpc (as I understand it), we spend a lot of time in boot running in real mode before MMU paging is initalised. During this time we call a lot of generic code, including printk(). If we try to access the shadow region during this time, things fail. My attempts to move early init before the first printk have not been successful. (Both previous RFCs for ppc64 - by 2 different people - have needed this trick too!) So, allow architectures to define a kasan_arch_is_ready() hook that bails out of check_memory_region_inline() unless the arch has done all of the init. Link: https://lore.kernel.org/patchwork/patch/592820/ # ppc64 hash series Link: https://patchwork.ozlabs.org/patch/795211/ # ppc radix series Originally-by: Balbir Singh Cc: Aneesh Kumar K.V Signed-off-by: Daniel Axtens [check_return_arch_not_ready() ==> static inline kasan_arch_is_ready()] Signed-off-by: Christophe Leroy --- include/linux/kasan.h | 4 ++++ mm/kasan/generic.c | 3 +++ 2 files changed, 7 insertions(+) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index b40ea104dd36..b91c40af9f31 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -14,6 +14,10 @@ struct task_struct; #include #include +#ifndef kasan_arch_is_ready +static inline bool kasan_arch_is_ready(void) { return true; } +#endif + extern unsigned char kasan_early_shadow_page[PAGE_SIZE]; extern pte_t kasan_early_shadow_pte[PTRS_PER_PTE]; extern pmd_t kasan_early_shadow_pmd[PTRS_PER_PMD]; diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index ccb6207276e3..696c2f5b902b 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -170,6 +170,9 @@ static __always_inline void check_memory_region_inline(unsigned long addr, size_t size, bool write, unsigned long ret_ip) { + if (!kasan_arch_is_ready()) + return; + if (unlikely(size == 0)) return; From patchwork Tue Feb 19 17:23:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10820507 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AC6DA1575 for ; Tue, 19 Feb 2019 17:23:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8EA892D153 for ; Tue, 19 Feb 2019 17:23:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C36B2D10F; Tue, 19 Feb 2019 17:23:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EBC142D1A8 for ; Tue, 19 Feb 2019 17:23:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C3F6E8E0009; Tue, 19 Feb 2019 12:23:21 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B9FAD8E0008; Tue, 19 Feb 2019 12:23:21 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A15E78E0009; Tue, 19 Feb 2019 12:23:21 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by kanga.kvack.org (Postfix) with ESMTP id 39BD58E0008 for ; Tue, 19 Feb 2019 12:23:21 -0500 (EST) Received: by mail-wr1-f69.google.com with SMTP id s5so9253767wrp.17 for ; Tue, 19 Feb 2019 09:23:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:message-id:in-reply-to:references :from:subject:to:cc:date; bh=Jv4JVBbRhfA3gyIP1EYU/TxFEfL2VMG+F/ri6hG6mlk=; b=QXakC02qSsvZm1AeDiKCAQ0fi7k94IQuCPXVTPeDj7z3leJqc6DRolxs5ub40pKg3w 3vaTYHqQGYSpoOUtPtBGHgl9hQegi3YcfcHhDl9F18KZY0VD5rcSIZ4aH5ktlm6w0dmP W3/KHGg6T0fhwpdU1EQGNX2P1Ui9qlZu8fD9KNUfkYMb6cbArH4bUnoqkNTH32MSoABQ I31zD/Oexn1rQQ0SnyiATa2utO0oRbJeq4I8rc2ILrCqQrMBROG39psySBAZ9roj8mhL pXP0jqJRQa59FGdUHThkmWujmkn5W/M/beNjKIGd6fyKPXmMPRMl1UO3fK4BsMr6x12o aHdg== X-Gm-Message-State: AHQUAuY0sbi+mY6hiFSNi8XFSWUPDuK4mmwQTPU0/IMb2UufQXmNzdIt c6mTgw5DqG7qbslE67PQkrrR4iYjATYuOd2apWHAZJfNJIVC4MSOTmdvvIrEtBDTZHfMxL1hTND J5dbytG0VnwPySkgHOwArxHiadnYVDe58u+N3L+DOXfjcw4GUb4XLY3iNmjedPKNxyw== X-Received: by 2002:adf:b646:: with SMTP id i6mr22254774wre.262.1550597000748; Tue, 19 Feb 2019 09:23:20 -0800 (PST) X-Google-Smtp-Source: AHgI3IacvXQHs8do7PtUQnJDJfBlZEnFg5xShTWUmx6GcIpWcOwy3yxl8sMykxfeHZge56PX1u4I X-Received: by 2002:adf:b646:: with SMTP id i6mr22254725wre.262.1550596999768; Tue, 19 Feb 2019 09:23:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550596999; cv=none; d=google.com; s=arc-20160816; b=eiHdbf8calKGkO2ujfJJehf0MxPT+RmKId0JQIVhWCepS1/9/O4HZbpdA5FGTNYBmc 8NZc8yPcp2vMRu0IB0dUUOhb5PRi46u2TitW9iLTtWopJosAyG622kpmtS+a7Ec9ak75 /tgSVB0VIJ7OuIV+HeMnx0U1WkleU9NTvKiTwe7R1BJg68glpMqyjXQa8+cPMfeJRJNr Ycd3ZpwQBfxO8e31Gmpr8JSs7NfUOURB5lm5MBkqIG/2rVw9hBLdp9v8Pp3o09qIrG6k P5vV73pi8MPXQX6VR7bQDUhgdWURtjbUjIjU2PmfYVNF+eDVn6R6n+YgPTf3WcI9bmK+ 6H9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:cc:to:subject:from:references:in-reply-to:message-id :dkim-signature; bh=Jv4JVBbRhfA3gyIP1EYU/TxFEfL2VMG+F/ri6hG6mlk=; b=GavkRj+C1DPHZFTPVdb2qgQNTIlYmvV41VGdHee62zpd6f46xpFVPVXm+qH+zDMoDZ Uo72FHBeWQ9XxX8TyUc83tG7MoBYH++SH0qjtFTiIlvCDfzIKOnhaeopdD++O8337NLG i8MD+5gjHJc6Ow1Gq8gWiD9Cmn1z+QoF8U+KX+k67FlB45fumq8e3s4aG/B+34tjn5aN 8Wi/G97TA4nQvKBtCqJGHZlzqHCavJ+UZziG8klhWuUjnTmtek98ZbxUxmZYrTFN4F9z 1jFHR8r83yPMXWPy3CZXvK1qWosgGzX8MKaRHFmSaAa736TdVKhQYt3m6B+DI2PqhAJr 0c2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=aF0T3QOn; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from pegase1.c-s.fr (pegase1.c-s.fr. [93.17.236.30]) by mx.google.com with ESMTPS id n3si1836126wmh.25.2019.02.19.09.23.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Feb 2019 09:23:19 -0800 (PST) Received-SPF: pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) client-ip=93.17.236.30; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=aF0T3QOn; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 443nd13SlVz9v4wh; Tue, 19 Feb 2019 18:23:17 +0100 (CET) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=aF0T3QOn; dkim-adsp=pass; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id z64kTG7dNlcw; Tue, 19 Feb 2019 18:23:17 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 443nd12Ljjz9v4wf; Tue, 19 Feb 2019 18:23:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1550596997; bh=Jv4JVBbRhfA3gyIP1EYU/TxFEfL2VMG+F/ri6hG6mlk=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=aF0T3QOn8yGPZr6IFDElhGbGr/VoMO6mCmlKI6jNFM9Qdog2yFGH0s/P8D6Ar94AI Qjq7crncHc1zDoznvtPGtj/Riko/lE89rVwNOlc+P/hEh//fv8QMfyzgAHiDgtFu7y pkiWOojNjzKmExJ2CQRq19MknrgXXM7ilApNjnjY= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id EA8828B7FE; Tue, 19 Feb 2019 18:23:18 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id 0MSO2AGC11U1; Tue, 19 Feb 2019 18:23:18 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id A1DFD8B7F9; Tue, 19 Feb 2019 18:23:18 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 739186E81D; Tue, 19 Feb 2019 17:23:18 +0000 (UTC) Message-Id: <4256ccd5f58f58f13ff06bfcf86fab06d52a86d2.1550596242.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v6 6/6] powerpc/32: enable CONFIG_KASAN for book3s hash To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Nicholas Piggin , Aneesh Kumar K.V , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Daniel Axtens Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Date: Tue, 19 Feb 2019 17:23:18 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP The challenge with book3s/32 is that the hash table management has to be set up before being able to use KASAN. This patch adds a kasan_arch_is_ready() helper to defer the activation of KASAN until paging is ready. This limits KASAN to KASAN_MINIMAL mode. The downside of it is that the 603, which doesn't use hash table, also gets downgraded to KASAN_MINIMAL because this is no way to activate full support dynamically because that's compiled-in. Signed-off-by: Christophe Leroy --- arch/powerpc/Makefile | 2 ++ arch/powerpc/include/asm/kasan.h | 13 +++++++++++++ arch/powerpc/mm/kasan/kasan_init_32.c | 27 +++++++++++++++++++++++++-- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile index f0738099e31e..06d085558d21 100644 --- a/arch/powerpc/Makefile +++ b/arch/powerpc/Makefile @@ -428,11 +428,13 @@ endif endif ifdef CONFIG_KASAN +ifndef CONFIG_PPC_BOOK3S_32 prepare: kasan_prepare kasan_prepare: prepare0 $(eval KASAN_SHADOW_OFFSET = $(shell awk '{if ($$2 == "KASAN_SHADOW_OFFSET") print $$3;}' include/generated/asm-offsets.h)) endif +endif # Check toolchain versions: # - gcc-4.6 is the minimum kernel-wide version so nothing required. diff --git a/arch/powerpc/include/asm/kasan.h b/arch/powerpc/include/asm/kasan.h index 0bc9148f5d87..97b5ccf0702f 100644 --- a/arch/powerpc/include/asm/kasan.h +++ b/arch/powerpc/include/asm/kasan.h @@ -16,6 +16,7 @@ #include #include +#include #define KASAN_SHADOW_SCALE_SHIFT 3 @@ -34,5 +35,17 @@ void kasan_early_init(void); void kasan_init(void); +extern struct static_key_false powerpc_kasan_enabled_key; + +static inline bool kasan_arch_is_ready(void) +{ + if (!IS_ENABLED(CONFIG_BOOK3S_32)) + return true; + if (static_branch_likely(&powerpc_kasan_enabled_key)) + return true; + return false; +} +#define kasan_arch_is_ready kasan_arch_is_ready + #endif /* __ASSEMBLY */ #endif diff --git a/arch/powerpc/mm/kasan/kasan_init_32.c b/arch/powerpc/mm/kasan/kasan_init_32.c index 495c908d6ee6..f24f8f56d450 100644 --- a/arch/powerpc/mm/kasan/kasan_init_32.c +++ b/arch/powerpc/mm/kasan/kasan_init_32.c @@ -9,6 +9,9 @@ #include #include +/* Used by BOOK3S_32 only */ +DEFINE_STATIC_KEY_FALSE(powerpc_kasan_enabled_key); + void __init kasan_early_init(void) { unsigned long addr = KASAN_SHADOW_START; @@ -21,7 +24,7 @@ void __init kasan_early_init(void) BUILD_BUG_ON(KASAN_SHADOW_START & ~PGDIR_MASK); if (early_mmu_has_feature(MMU_FTR_HPTE_TABLE)) - panic("KASAN not supported with Hash MMU\n"); + return; for (i = 0; i < PTRS_PER_PTE; i++) __set_pte_at(&init_mm, (unsigned long)kasan_early_shadow_page, @@ -32,6 +35,22 @@ void __init kasan_early_init(void) next = pgd_addr_end(addr, end); pmd_populate_kernel(&init_mm, pmd, kasan_early_shadow_pte); } while (pmd++, addr = next, addr != end); + + if (IS_ENABLED(CONFIG_PPC_BOOK3S_32)) { + jump_label_init(); + static_branch_enable(&powerpc_kasan_enabled_key); + } +} + +static void __init kasan_late_init(void) +{ + unsigned long addr; + phys_addr_t pa = __pa(kasan_early_shadow_page); + + for (addr = KASAN_SHADOW_START; addr < KASAN_SHADOW_END; addr += PAGE_SIZE) + map_kernel_page(addr, pa, PAGE_KERNEL_RO); + + static_branch_enable(&powerpc_kasan_enabled_key); } static void __ref *kasan_get_one_page(void) @@ -113,6 +132,9 @@ void __init kasan_init(void) { struct memblock_region *reg; + if (early_mmu_has_feature(MMU_FTR_HPTE_TABLE)) + kasan_late_init(); + for_each_memblock(memory, reg) { int ret = kasan_init_region(__va(reg->base), reg->size); @@ -120,7 +142,8 @@ void __init kasan_init(void) panic("kasan: kasan_init_region() failed"); } - kasan_remap_early_shadow_ro(); + if (!early_mmu_has_feature(MMU_FTR_HPTE_TABLE)) + kasan_remap_early_shadow_ro(); clear_page(kasan_early_shadow_page);