From patchwork Mon Sep 2 11:20:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Axtens X-Patchwork-Id: 11126375 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1496C14DE for ; Mon, 2 Sep 2019 11:21:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AAE3D2190F for ; Mon, 2 Sep 2019 11:21:22 +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="Rhhm4VfH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AAE3D2190F 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 CE55D6B0003; Mon, 2 Sep 2019 07:21:21 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C95FB6B0006; Mon, 2 Sep 2019 07:21:21 -0400 (EDT) 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 BAC3C6B0007; Mon, 2 Sep 2019 07:21:21 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0043.hostedemail.com [216.40.44.43]) by kanga.kvack.org (Postfix) with ESMTP id 9A2AA6B0003 for ; Mon, 2 Sep 2019 07:21:21 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id 4E08A6122 for ; Mon, 2 Sep 2019 11:21:21 +0000 (UTC) X-FDA: 75889739562.03.jeans78_28d740640ed53 X-Spam-Summary: 2,0,0,8192d376ffdbc848,d41d8cd98f00b204,dja@axtens.net,:kasan-dev@googlegroups.com::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:linuxppc-dev@lists.ozlabs.org:gor@linux.ibm.com:dja@axtens.net,RULES_HIT:41:355:379:541:800:966:967:973:982:988:989:1260:1311:1314:1345:1437:1515:1535:1543:1711:1730:1747:1777:1792:1801:2194:2196:2199:2200:2393:2525:2559:2568:2570:2629:2682:2685:2703:2859:2903:2911:2933:2937:2939:2942:2945:2947:2951:2954:3022:3355:3622:3865:3866:3867:3868:3870:3871:3872:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4117:4321:4385:4425:4605:5007:6117:6119:6261:7875:7903:9025:9040:9121:10004:11658:12048:12219:13161:13229,0,RBL:209.85.215.195:@axtens.net:.lbl8.mailshell.net-62.14.175.100 66.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFt ime:80,L X-HE-Tag: jeans78_28d740640ed53 X-Filterd-Recvd-Size: 6511 Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Mon, 2 Sep 2019 11:21:20 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id d10so2783268pgo.5 for ; Mon, 02 Sep 2019 04:21:20 -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:mime-version :content-transfer-encoding; bh=73TlGEwK6oKiZ/rkmArAnsPJNae2N4hkEOloXefysjM=; b=Rhhm4VfHtnyt2JvxlWHInpQFUnr4IjDvHWve41dxBUjTRnX5YIUfmoLpYdhbRpEJ96 zotNlyxp8TbUzVMrvwyf5jDhkEgrcZpw2iXUuuh78i2YhYA59nQowTqs9xosiwspC3w0 nBWXVcjWjD3udTsye61lFsb+3l/t2DzQkiMKM= 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:mime-version :content-transfer-encoding; bh=73TlGEwK6oKiZ/rkmArAnsPJNae2N4hkEOloXefysjM=; b=Vi8wk0YXp2LxtPOyHubZvumi2K+BS8EOhzsRny2sHVaRDYmR2hFBVqfpNK91SBZtAd 7jojiunasyJGorxQNE8gQiQgW04A8Mzs0Uxxr1ZQa3QliqPZ8Oy/UoW1s3tjwCO79G4Q 7I1qh1o/WzK8g0lPQxf+RCu1tK/S3mgGrekd/pIsvMWmGTvpIWPnQOKVXK8l1I7+Emx8 UZ6LLVOAg81EFaDssyx2el8sbYtePrvVjRjnELFDoS92LaTkkPhiHz54EHAm4d/cWLwU YqGsGnfMm26txqh9xNfksrH9/vnPb+rw4NVP1nRSo4N7AcneEzyjEZZQIfVtTDoLiJa3 sTTg== X-Gm-Message-State: APjAAAXqmfOFs/ZbLTDGq06Cpf/Dv5nq6D+S4bP5VQtS8CR9QqGVZ46g rOmM6p+UoGBgYgHO9ZFJEuDNbw== X-Google-Smtp-Source: APXvYqyyJrIGNF/49jX946xepT3hLe7HM0PDMzFhBMdhjz56mjhnOrOqjg9qT8NraW9rYZyehdy5AA== X-Received: by 2002:a62:80cb:: with SMTP id j194mr34723282pfd.183.1567423279444; Mon, 02 Sep 2019 04:21:19 -0700 (PDT) Received: from localhost (ppp167-251-205.static.internode.on.net. [59.167.251.205]) by smtp.gmail.com with ESMTPSA id x12sm1054597pff.49.2019.09.02.04.21.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2019 04:21:18 -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 v6 0/5] kasan: support backing vmalloc space with real shadow memory Date: Mon, 2 Sep 2019 21:20:23 +1000 Message-Id: <20190902112028.23773-1-dja@axtens.net> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 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: Currently, vmalloc space is backed by the early shadow page. This means that kasan is incompatible with VMAP_STACK. This series provides a mechanism to back vmalloc space with real, dynamically allocated memory. I have only wired up x86, because that's the only currently supported arch I can work with easily, but it's very easy to wire up other architectures, and it appears that there is some work-in-progress code to do this on arm64 and s390. This has been discussed before in the context of VMAP_STACK: - https://bugzilla.kernel.org/show_bug.cgi?id=202009 - https://lkml.org/lkml/2018/7/22/198 - https://lkml.org/lkml/2019/7/19/822 In terms of implementation details: Most mappings in vmalloc space are small, requiring less than a full page of shadow space. Allocating a full shadow page per mapping would therefore be wasteful. Furthermore, to ensure that different mappings use different shadow pages, mappings would have to be aligned to KASAN_SHADOW_SCALE_SIZE * PAGE_SIZE. Instead, share backing space across multiple mappings. Allocate a backing page when a mapping in vmalloc space uses a particular page of the shadow region. This page can be shared by other vmalloc mappings later on. We hook in to the vmap infrastructure to lazily clean up unused shadow memory. v1: https://lore.kernel.org/linux-mm/20190725055503.19507-1-dja@axtens.net/ v2: https://lore.kernel.org/linux-mm/20190729142108.23343-1-dja@axtens.net/ Address review comments: - Patch 1: use kasan_unpoison_shadow's built-in handling of ranges that do not align to a full shadow byte - Patch 3: prepopulate pgds rather than faulting things in v3: https://lore.kernel.org/linux-mm/20190731071550.31814-1-dja@axtens.net/ Address comments from Mark Rutland: - kasan_populate_vmalloc is a better name - handle concurrency correctly - various nits and cleanups - relax module alignment in KASAN_VMALLOC case v4: https://lore.kernel.org/linux-mm/20190815001636.12235-1-dja@axtens.net/ Changes to patch 1 only: - Integrate Mark's rework, thanks Mark! - handle the case where kasan_populate_shadow might fail - poision shadow on free, allowing the alloc path to just unpoision memory that it uses v5: https://lore.kernel.org/linux-mm/20190830003821.10737-1-dja@axtens.net/ Address comments from Christophe Leroy: - Fix some issues with my descriptions in commit messages and docs - Dynamically free unused shadow pages by hooking into the vmap book-keeping - Split out the test into a separate patch - Optional patch to track the number of pages allocated - minor checkpatch cleanups v6: Properly guard freeing pages in patch 1, drop debugging code. Daniel Axtens (5): kasan: support backing vmalloc space with real shadow memory kasan: add test for vmalloc fork: support VMAP_STACK with KASAN_VMALLOC x86/kasan: support KASAN_VMALLOC kasan debug: track pages allocated for vmalloc shadow Documentation/dev-tools/kasan.rst | 63 ++++++++++++ arch/Kconfig | 9 +- arch/x86/Kconfig | 1 + arch/x86/mm/kasan_init_64.c | 60 +++++++++++ include/linux/kasan.h | 31 ++++++ include/linux/moduleloader.h | 2 +- include/linux/vmalloc.h | 12 +++ kernel/fork.c | 4 + lib/Kconfig.kasan | 16 +++ lib/test_kasan.c | 26 +++++ mm/kasan/common.c | 165 ++++++++++++++++++++++++++++++ mm/kasan/generic_report.c | 3 + mm/kasan/kasan.h | 1 + mm/vmalloc.c | 45 +++++++- 14 files changed, 432 insertions(+), 6 deletions(-)