From patchwork Mon Sep 21 13:26:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Elver X-Patchwork-Id: 11789859 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 EA9CD112C for ; Mon, 21 Sep 2020 13:26:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AD1A6222BB for ; Mon, 21 Sep 2020 13:26:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="h0DABlib" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AD1A6222BB Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C0249900062; Mon, 21 Sep 2020 09:26:53 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B8933900059; Mon, 21 Sep 2020 09:26:53 -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 9DEE0900062; Mon, 21 Sep 2020 09:26:53 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0120.hostedemail.com [216.40.44.120]) by kanga.kvack.org (Postfix) with ESMTP id 7BB41900059 for ; Mon, 21 Sep 2020 09:26:53 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 3E7C11EE6 for ; Mon, 21 Sep 2020 13:26:53 +0000 (UTC) X-FDA: 77287143906.09.skate72_42125c227145 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin09.hostedemail.com (Postfix) with ESMTP id 1D0C6180AD801 for ; Mon, 21 Sep 2020 13:26:53 +0000 (UTC) X-Spam-Summary: 1,0,0,75208c69c559c47d,d41d8cd98f00b204,3g6poxwukcbqy5fyb08805y.w86527eh-664fuw4.8b0@flex--elver.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:966:973:988:989:1260:1277:1313:1314:1345:1359:1437:1516:1518:1535:1542:1593:1594:1711:1730:1747:1777:1792:2194:2196:2199:2200:2393:2553:2559:2562:2693:2903:3138:3139:3140:3141:3142:3152:3353:3865:3866:3867:3870:3871:3872:3874:4250:4321:4385:5007:6261:6653:6742:6743:7576:7903:8603:9969:10004:10400:11026:11473:11658:11914:12043:12296:12297:12438:12555:12679:12895:13153:13228:14093:14096:14097:14181:14394:14659:14721:21080:21444:21451:21627:21990:30045:30054:30056:30090,0,RBL:209.85.219.74:@flex--elver.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04y8cbrje1hmthu8tn3o8sedwrrd9ypydqxnwiehwy5oidq4nfdtuhubnoo4xiq.yakkon4e4xwx9dnfzb14mgsqby5m95dxbfc788dza1p5b4tnumwfwiz99ujjeqo.a-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MS BL:0,DNS X-HE-Tag: skate72_42125c227145 X-Filterd-Recvd-Size: 5905 Received: from mail-qv1-f74.google.com (mail-qv1-f74.google.com [209.85.219.74]) by imf50.hostedemail.com (Postfix) with ESMTP for ; Mon, 21 Sep 2020 13:26:52 +0000 (UTC) Received: by mail-qv1-f74.google.com with SMTP id w32so8754297qvw.8 for ; Mon, 21 Sep 2020 06:26:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=k1T9dYB7DJoZ+u+nVe3kaxMkFtqFlEoHZfLN0p/pvEE=; b=h0DABlibHB7v95H3LhOc4lIx2a+JuJCaG5dCjxY69vhbTwo2OewB2jqrcfxfSAWImf 0rilrwD74EdgNZkNctrYhdK0BKQa1IFxA96Sn77Ss9MbjCIxt55LT+Db94EGESOvWC61 FNhFsNV1l+s2LYwjRiVeyI/gY07VtoOl0G4eY13mJqePxG7L0c4mXQ3OowvJ26BmA67c 26EMpkQ2n7OL6XdtoU4I2iAZTKdgLhn27yeHPdjeTgGW4u+Pr5ofUSUfQP/ixCP+f2or 3yp/zGKOxnf1szBrwX417xIk13JJ29F0GqtqSoNssPh6hTcAf0X+yRRllGTo8pXmlpeV KA4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=k1T9dYB7DJoZ+u+nVe3kaxMkFtqFlEoHZfLN0p/pvEE=; b=RrDU/ywQLfXociLmclU8jNVHd27Z0esYTTzMC2Vz0P6QBkEzwHOTjc2fRc3PTWbPLF Iq2FVlOXsQqhDD5Hwiq5kRd50eE17teGTAxFllQPj4TDeyb0iX13zdK2E9eRI8q5mmJQ fQT0FR15uW6QuyZDWE2/vGoketnsCliteYvVIL1SM7GujCGF7SoK4C95h1c2nDvR4NIX Cg89udd+x3oibdr3OK5SKvszAyEYZLfnH2+kUQZ0XSQP1jifFKwEVxGIflWquQhRKI6e 8/l11OOvL3f9zcC09jRiR/sjiXASs59sw/4dsuW6rpJc6HC/5Oj9npT3YWV3ldM+QX5w TxeA== X-Gm-Message-State: AOAM533GknHnst95O2g4LjoJcRDWwZvn0X8azmE7SSz/tgWTM3vkK1sJ aVVTSdwcFTWibIiW60yaswWDbE9shw== X-Google-Smtp-Source: ABdhPJxI5BBppzUwl+FURSlYJ/XsuSII2/6RzrI0Ei9BEoIUMUq9N7cECIXnXgK6ZUjbLhwm9DwnPw5xLg== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:f693:9fff:fef4:2449]) (user=elver job=sendgmr) by 2002:ad4:4af4:: with SMTP id cp20mr30110353qvb.40.1600694811561; Mon, 21 Sep 2020 06:26:51 -0700 (PDT) Date: Mon, 21 Sep 2020 15:26:07 +0200 In-Reply-To: <20200921132611.1700350-1-elver@google.com> Message-Id: <20200921132611.1700350-7-elver@google.com> Mime-Version: 1.0 References: <20200921132611.1700350-1-elver@google.com> X-Mailer: git-send-email 2.28.0.681.g6f77f65b4e-goog Subject: [PATCH v3 06/10] kfence, kasan: make KFENCE compatible with KASAN From: Marco Elver To: elver@google.com, akpm@linux-foundation.org, glider@google.com Cc: hpa@zytor.com, paulmck@kernel.org, andreyknvl@google.com, aryabinin@virtuozzo.com, luto@kernel.org, bp@alien8.de, catalin.marinas@arm.com, cl@linux.com, dave.hansen@linux.intel.com, rientjes@google.com, dvyukov@google.com, edumazet@google.com, gregkh@linuxfoundation.org, hdanton@sina.com, mingo@redhat.com, jannh@google.com, Jonathan.Cameron@huawei.com, corbet@lwn.net, iamjoonsoo.kim@lge.com, keescook@chromium.org, mark.rutland@arm.com, penberg@kernel.org, peterz@infradead.org, sjpark@amazon.com, tglx@linutronix.de, vbabka@suse.cz, will@kernel.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org 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: From: Alexander Potapenko We make KFENCE compatible with KASAN for testing KFENCE itself. In particular, KASAN helps to catch any potential corruptions to KFENCE state, or other corruptions that may be a result of freepointer corruptions in the main allocators. To indicate that the combination of the two is generally discouraged, CONFIG_EXPERT=y should be set. It also gives us the nice property that KFENCE will be build-tested by allyesconfig builds. Reviewed-by: Dmitry Vyukov Co-developed-by: Marco Elver Signed-off-by: Marco Elver Signed-off-by: Alexander Potapenko --- lib/Kconfig.kfence | 2 +- mm/kasan/common.c | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Kconfig.kfence b/lib/Kconfig.kfence index 4c2ea1c722de..6825c1c07a10 100644 --- a/lib/Kconfig.kfence +++ b/lib/Kconfig.kfence @@ -10,7 +10,7 @@ config HAVE_ARCH_KFENCE_STATIC_POOL menuconfig KFENCE bool "KFENCE: low-overhead sampling-based memory safety error detector" - depends on HAVE_ARCH_KFENCE && !KASAN && (SLAB || SLUB) + depends on HAVE_ARCH_KFENCE && (!KASAN || EXPERT) && (SLAB || SLUB) depends on JUMP_LABEL # To ensure performance, require jump labels select STACKTRACE help diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 950fd372a07e..f5c49f0fdeff 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -396,6 +397,9 @@ static bool __kasan_slab_free(struct kmem_cache *cache, void *object, tagged_object = object; object = reset_tag(object); + if (is_kfence_address(object)) + return false; + if (unlikely(nearest_obj(cache, virt_to_head_page(object), object) != object)) { kasan_report_invalid_free(tagged_object, ip); @@ -444,6 +448,9 @@ static void *__kasan_kmalloc(struct kmem_cache *cache, const void *object, if (unlikely(object == NULL)) return NULL; + if (is_kfence_address(object)) + return (void *)object; + redzone_start = round_up((unsigned long)(object + size), KASAN_SHADOW_SCALE_SIZE); redzone_end = round_up((unsigned long)object + cache->object_size,