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=-6.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 7DD10ECE599 for ; Thu, 17 Oct 2019 01:25:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3D7C421928 for ; Thu, 17 Oct 2019 01:25:30 +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="YSJ6KAHi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3D7C421928 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 E79938E0009; Wed, 16 Oct 2019 21:25:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E28BF8E0001; Wed, 16 Oct 2019 21:25:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D17668E0009; Wed, 16 Oct 2019 21:25:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0107.hostedemail.com [216.40.44.107]) by kanga.kvack.org (Postfix) with ESMTP id AD8D28E0001 for ; Wed, 16 Oct 2019 21:25:29 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id 532A65DEE for ; Thu, 17 Oct 2019 01:25:29 +0000 (UTC) X-FDA: 76051533978.18.arm15_4cf7632c2c13a X-HE-Tag: arm15_4cf7632c2c13a X-Filterd-Recvd-Size: 4955 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by imf07.hostedemail.com (Postfix) with ESMTP for ; Thu, 17 Oct 2019 01:25:28 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id q5so491329pfg.13 for ; Wed, 16 Oct 2019 18:25:28 -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=1Qk9PXHlMYGMSaAT4No+OXlpNbokcwpw05BcYMTN8o0=; b=YSJ6KAHiGnESyfIOPhPKg1SYOVmjMBpomipuFXEhixlmLzKVW8KvRvn5hHyn6j2Y1i p0eSmpQseV9wxx3eeTbQ1axx5VnzPdFc8iQC+dfYkX4tE20eVuU8xw8dU0mQPGkNS4RJ MaD1w2zcSOG1GUeN4MR3fRhoXpOaM2LU5n7Zc= 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=1Qk9PXHlMYGMSaAT4No+OXlpNbokcwpw05BcYMTN8o0=; b=XL+GTgG5bS60oMS5y0hFgjCJJEABA9U1RCOYlKoG688vag/w9xgODAnm+B7TUhUXKA 6qmIHpN5Csq7rgjD5uCWyFjU9RT7KNXLBZKOg/1Fyzo5/XirHl3pMgwNQFoOZ9TpqExX 3afrzlTxCJ3qFbL5ePe78XmiU2Eh3uCkgLzB1f2gqZt0eHLjShh5uWwbgtF2ak5yUMGD XLdGUZ7p5ieJSBEWX/fB7mGguztAt2D6xabc+bXPpo15jMU31KVPl06yNJ+iFhgZrD9i iQy6mG1faAuZbXX1J8c+GpxtIqJkUcmvZDzJx4nBDVa/n04oQrCQ0JY/Gj3jkPG2dkiu rplw== X-Gm-Message-State: APjAAAUlIyRWHZpWQ+EwVL4SkGVypksqNTUKqAwYJiXk7eDCweGU35by 6/KRPD1PQs+iLaAqZ61NDZluog== X-Google-Smtp-Source: APXvYqxXibUE0U8yVD2FdPr0YPQf1k44k2wbp/Do/vRXY+EPhK1zFPUYH2gqnpMbv50YR9NpPNR7KQ== X-Received: by 2002:a17:90a:868b:: with SMTP id p11mr1154784pjn.58.1571275527734; Wed, 16 Oct 2019 18:25:27 -0700 (PDT) Received: from localhost (ppp167-251-205.static.internode.on.net. [59.167.251.205]) by smtp.gmail.com with ESMTPSA id 127sm351343pfy.56.2019.10.16.18.25.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Oct 2019 18:25:27 -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 v9 3/5] fork: support VMAP_STACK with KASAN_VMALLOC Date: Thu, 17 Oct 2019 12:25:04 +1100 Message-Id: <20191017012506.28503-4-dja@axtens.net> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191017012506.28503-1-dja@axtens.net> References: <20191017012506.28503-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 Signed-off-by: Daniel Axtens --- arch/Kconfig | 9 +++++---- kernel/fork.c | 4 ++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git arch/Kconfig arch/Kconfig index 5f8a5d84dbbe..2d914990402f 100644 --- arch/Kconfig +++ 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 kernel/fork.c kernel/fork.c index bcdf53125210..484ca6b0ae6c 100644 --- kernel/fork.c +++ 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