Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp5631538ybi; Wed, 31 Jul 2019 00:41:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqwhc7PSt3jqoQtxtqb79+jzHaNbeaJy4iOrBwtlGRfRnn5pKMEynDVsa5AxjXBV+rkviwMJ X-Received: by 2002:a17:90a:b00b:: with SMTP id x11mr1532007pjq.120.1564558905322; Wed, 31 Jul 2019 00:41:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564558905; cv=none; d=google.com; s=arc-20160816; b=rsNxewXXkj1+6v+LAciO/95RWtCCa40b/hU5MMz5h6lMBmPBHWcTSFETu57F1fzHBo PldiUBdVlWy2J05J4eE9jBJdqesBqwoq78d8Zvs8ilA6JA1xRYFMIhECHw+GlvXs9GdD N/TsApOkkKcYpRvkMIjOTuowqGcpHm8JuZ4MMF6SB0g3KuJLosTUtmnV1JTabOIpqkbp 308rL2n6gZbQ9IlTKiiIxRYSLLzK0YLCoGM6BZ9WOLdparJHyiL2DaPZzU6R+/8x8fu0 e+bqqEMC7/pfTuitFMhPR2qvyOJZEyzAZeuL6GFRarrARZb43tNFCJ2vo84XuZEK0z8E kQHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=w7zQctoUbbEOIFpo2YzbJpxQDN+pRrmLCUjs8vOkAsU=; b=qw9hjetUzPS081sth1KzjbNs8OCYoxYoRk7BvhtgmOzGwwEZR4DSsds07IE0SBLCaL ETL/+gtsSa/nIgMbbVmd+z1d3OGww4Q6xbWmo6C8Mp8bwYN0qdM4qdrMSh1yrabH4jYV 5rK85Awsc2E1qaxL2okxxXyk6Jh8OaJVoBpDbSGi2w/utEpwOrVJUJIBOwNCjjgfqctt SHqaD81lgeSWAAsSjzBA/LmrdqV4+LxaFedMgoAimYszsXg0sOamz3iECrXNhazc+Lth 19aUGAbw9t9i5ViofrjgqKcAPsCdjLRTVwTKGz8LI/Zrdw4xIAb1DOnQWBAQXhP9T/c/ fJhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@axtens.net header.s=google header.b=Vb4l6hRe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s8si963624pjb.40.2019.07.31.00.41.29; Wed, 31 Jul 2019 00:41:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@axtens.net header.s=google header.b=Vb4l6hRe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727984AbfGaHQG (ORCPT + 99 others); Wed, 31 Jul 2019 03:16:06 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:40609 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727961AbfGaHQF (ORCPT ); Wed, 31 Jul 2019 03:16:05 -0400 Received: by mail-pf1-f193.google.com with SMTP id p184so31329820pfp.7 for ; Wed, 31 Jul 2019 00:16:04 -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=w7zQctoUbbEOIFpo2YzbJpxQDN+pRrmLCUjs8vOkAsU=; b=Vb4l6hReLTp+4x430W2Q9iCkhEPhmle92DV4T4Oq0+uq8zWtE92+0O6qof/DPoNPyF YdRUYu/PcneNAH0iqXabGkesddRL+oLpR9N90INnd+Y3Fss+aGSOqXY5POFTJWjEGn2i 0MAVCK7UhOW7Qx8U8eyASdlV+21e9EzlwRo/E= 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=w7zQctoUbbEOIFpo2YzbJpxQDN+pRrmLCUjs8vOkAsU=; b=jH+4k9HvZ1ePuMzqa9D2cqzKwOmXISgGZZdHN8IgPnp0hE4dTdsc3MpNYNRXVYvyCT Q8MGiB5Cu/HP+HIs/+3+jwPMhq/UMfTHsngVbucfLDhfdgl9Q+LGooi7l08lWIoNN/Fh w51y7sHPpUEVUZQguDx2u+i0Aw6O4J45PXbFaxL62ba8jBc10lcY9AHv+VkoQe3OMS5c aCieEW6CJUeBjINT0C+zy1bEVgrc05YtsixYf3IIXRgBjf1ZhL7XTLkpHr11k9Vk/qU8 p2x4WGHM5Spvausp+/CJyNoJ+vMZLWU8oC711cK35uV2LdQtRdT9HXYBvZv7BQa0D2Gs S8IA== X-Gm-Message-State: APjAAAW/h1JYSFbrDSMbwCp6l7BGquQtsIyzI78mA/RmRJKU8zFbPJN1 N7qOpla4XEMn/w63lxToOiE= X-Received: by 2002:a63:e807:: with SMTP id s7mr109013541pgh.194.1564557364627; Wed, 31 Jul 2019 00:16:04 -0700 (PDT) Received: from localhost (ppp167-251-205.static.internode.on.net. [59.167.251.205]) by smtp.gmail.com with ESMTPSA id f32sm597045pgb.21.2019.07.31.00.16.03 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 00:16:03 -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 Cc: Daniel Axtens Subject: [PATCH v3 2/3] fork: support VMAP_STACK with KASAN_VMALLOC Date: Wed, 31 Jul 2019 17:15:49 +1000 Message-Id: <20190731071550.31814-3-dja@axtens.net> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731071550.31814-1-dja@axtens.net> References: <20190731071550.31814-1-dja@axtens.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 a/arch/Kconfig b/arch/Kconfig index a7b57dd42c26..e791196005e1 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -825,16 +825,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. - 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. config ARCH_OPTIONAL_KERNEL_RWX def_bool n diff --git a/kernel/fork.c b/kernel/fork.c index d8ae0f1b4148..ce3150fe8ff2 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -94,6 +94,7 @@ #include #include #include +#include #include #include @@ -215,6 +216,9 @@ static unsigned long *alloc_thread_stack_node(struct task_struct *tsk, int node) if (!s) continue; + /* 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); -- 2.20.1