From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83AA5CA9ED1 for ; Thu, 31 Oct 2019 09:39:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 47A342083E for ; Thu, 31 Oct 2019 09:39:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=axtens.net header.i=@axtens.net header.b="eV1YePql" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 47A342083E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=axtens.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D77DF6B000D; Thu, 31 Oct 2019 05:39:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D296E6B000E; Thu, 31 Oct 2019 05:39:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C19136B0010; Thu, 31 Oct 2019 05:39:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0081.hostedemail.com [216.40.44.81]) by kanga.kvack.org (Postfix) with ESMTP id A12F96B000D for ; Thu, 31 Oct 2019 05:39:30 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 3C1AB181AF5C1 for ; Thu, 31 Oct 2019 09:39:30 +0000 (UTC) X-FDA: 76103582100.16.crate42_700735e3e4f4d X-HE-Tag: crate42_700735e3e4f4d X-Filterd-Recvd-Size: 5077 Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Thu, 31 Oct 2019 09:39:29 +0000 (UTC) Received: by mail-pf1-f193.google.com with SMTP id q26so3965735pfn.11 for ; Thu, 31 Oct 2019 02:39:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=v18HXwwUv8fdcmaD7WznN2j7mmagzU8FAwS/lrMAbV8=; b=eV1YePqlbyO7tj1kbB9uk7OP/edmTARvYsB9Zgi7PH5bknrFXg/tJPOc7emhOO4x5j KtyJj8T2PfQws87ybdR8idy8g57nveDsfrqx/ExGASQ3uibiJe4goUkyOdBsJ/O6tM75 VsNL8fB1S0lA/l67fDIo2fDZfwDm47jbBhpzA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=v18HXwwUv8fdcmaD7WznN2j7mmagzU8FAwS/lrMAbV8=; b=hCw27RPkQ5VbCMiYT8rXY1r+w/uGQ/HVRsdXnqTKSx7vduopp1m8l21mERGVVs8R/S fSJ7Qu67ZeSalsziqpWA73rxM017O6kNqYKlywKwwxDOwt8BaigI2CsGJG/CT4j/VGYK AR7lnm1a6Jy0ECnZDQuIMqFdwHGztAewYaFwpLOLm3P1Aw0FY1fPAb2SkZePKGXyEQOI hmzlBsTIiux0mukC0yONlWSXUpVBICZxvpDgfYFWwArBtkyMgBGdSWIAT4yyjwP+6ZsP JO0ozC/KLuPtcDNx/ReYtMxjJ2OQ6uNr8L+Cdm3kTmfA8l30vLKIfnvqtu5DPdgtd+q6 rAEw== X-Gm-Message-State: APjAAAU0Kh29QMKpv+Lql+M86+/Q2XUtDB+BCmQZ0FqPx9xxmm/Ng1DC S2w6nzqQczYuKuaLjj1X7dAH5g== X-Google-Smtp-Source: APXvYqzcQf2seyFm3b/JjsEvVOy0D7utuomMGdhHrdtSNRCDKkdOsqd1sFCDqTrjR6KoKB+g/V5A2A== X-Received: by 2002:a62:2f43:: with SMTP id v64mr91811pfv.13.1572514768894; Thu, 31 Oct 2019 02:39:28 -0700 (PDT) Received: from localhost (2001-44b8-1113-6700-783a-2bb9-f7cb-7c3c.static.ipv6.internode.on.net. [2001:44b8:1113:6700:783a:2bb9:f7cb:7c3c]) by smtp.gmail.com with ESMTPSA id p1sm2503669pfb.112.2019.10.31.02.39.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2019 02:39:28 -0700 (PDT) From: Daniel Axtens To: kasan-dev@googlegroups.com, linux-mm@kvack.org, x86@kernel.org, aryabinin@virtuozzo.com, glider@google.com, luto@kernel.org, linux-kernel@vger.kernel.org, mark.rutland@arm.com, dvyukov@google.com, christophe.leroy@c-s.fr Cc: linuxppc-dev@lists.ozlabs.org, gor@linux.ibm.com, Daniel Axtens Subject: [PATCH v11 3/4] fork: support VMAP_STACK with KASAN_VMALLOC Date: Thu, 31 Oct 2019 20:39:08 +1100 Message-Id: <20191031093909.9228-4-dja@axtens.net> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191031093909.9228-1-dja@axtens.net> References: <20191031093909.9228-1-dja@axtens.net> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: Supporting VMAP_STACK with KASAN_VMALLOC is straightforward: - clear the shadow region of vmapped stacks when swapping them in - tweak Kconfig to allow VMAP_STACK to be turned on with KASAN Reviewed-by: Dmitry Vyukov Reviewed-by: Andrey Ryabinin Signed-off-by: Daniel Axtens --- arch/Kconfig | 9 +++++---- kernel/fork.c | 4 ++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index 5f8a5d84dbbe..2d914990402f 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -843,16 +843,17 @@ config HAVE_ARCH_VMAP_STACK config VMAP_STACK default y bool "Use a virtually-mapped stack" - depends on HAVE_ARCH_VMAP_STACK && !KASAN + depends on HAVE_ARCH_VMAP_STACK + depends on !KASAN || KASAN_VMALLOC ---help--- Enable this if you want the use virtually-mapped kernel stacks with guard pages. This causes kernel stack overflows to be caught immediately rather than causing difficult-to-diagnose corruption. =20 - This is presently incompatible with KASAN because KASAN expects - the stack to map directly to the KASAN shadow map using a formula - that is incorrect if the stack is in vmalloc space. + To use this with KASAN, the architecture must support backing + virtual mappings with real shadow memory, and KASAN_VMALLOC must + be enabled. =20 config ARCH_OPTIONAL_KERNEL_RWX def_bool n diff --git a/kernel/fork.c b/kernel/fork.c index 4b2a82eda8e5..0eef4243019c 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -94,6 +94,7 @@ #include #include #include +#include =20 #include #include @@ -224,6 +225,9 @@ static unsigned long *alloc_thread_stack_node(struct = task_struct *tsk, int node) if (!s) continue; =20 + /* Clear the KASAN shadow of the stack. */ + kasan_unpoison_shadow(s->addr, THREAD_SIZE); + /* Clear stale pointers from reused stack. */ memset(s->addr, 0, THREAD_SIZE); =20 --=20 2.20.1