From patchwork Tue Sep 29 13:38:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Elver X-Patchwork-Id: 11805855 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 4564F1668 for ; Tue, 29 Sep 2020 13:39:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E4F802158C for ; Tue, 29 Sep 2020 13:39:03 +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="er322a8g" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E4F802158C 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 3708A900006; Tue, 29 Sep 2020 09:38:59 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2FAD06B0073; Tue, 29 Sep 2020 09:38:59 -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 1280A900006; Tue, 29 Sep 2020 09:38:59 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0119.hostedemail.com [216.40.44.119]) by kanga.kvack.org (Postfix) with ESMTP id EBE9F6B0071 for ; Tue, 29 Sep 2020 09:38:58 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id B7F4B180AD801 for ; Tue, 29 Sep 2020 13:38:58 +0000 (UTC) X-FDA: 77316204756.22.pet89_230fc9f2718a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 93F4118038E67 for ; Tue, 29 Sep 2020 13:38:58 +0000 (UTC) X-Spam-Summary: 1,0,0,b607c3ded7b0ca4f,d41d8cd98f00b204,38thzxwukcdiszjsfuccuzs.qcazwbil-aayjoqy.cfu@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.160.202:@flex--elver.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04ygafeok8jfeshf1cktgrs37mbosopydqxnwiehwy5oidq4nfdtuhubnoo4xiq.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,M SBL:0,DN X-HE-Tag: pet89_230fc9f2718a X-Filterd-Recvd-Size: 5911 Received: from mail-qt1-f202.google.com (mail-qt1-f202.google.com [209.85.160.202]) by imf18.hostedemail.com (Postfix) with ESMTP for ; Tue, 29 Sep 2020 13:38:58 +0000 (UTC) Received: by mail-qt1-f202.google.com with SMTP id 60so2968931qtf.21 for ; Tue, 29 Sep 2020 06:38:58 -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=3PLfj7Le+IfBX8a0VvW3RStHbDZmDhyxflksdHuR0eA=; b=er322a8geG68qcfF8M1guZNd7UF3m56ZBe9jI1gKY2Ai9rDqkC+XsPfeQe+Gxco71+ st8n9YtVCR4QANduoS54PpgWIz6J6ookqFiPylQPXIYD80aa0kVkBrI0GQMqzxcB+L3d aK7WiVxjzJ7vvUxnxIXhu0PvEQrzs4dw2UMzTlKskDDz8x0rnH18gN/SfzheEov2h57l oFMlpwpiR91ep+fcSlbc+dDINYyQ4dbf4MDNW6tu4aGiRvHBQ4H9axwpHrbwzJ6MXPWd 5BkMRw14eXNd/hu+SzMv1DIKxLS/ayUiiOLZSf5jQ1MonoUT6ctvp7gvSgeTZSRC51OM Yeaw== 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=3PLfj7Le+IfBX8a0VvW3RStHbDZmDhyxflksdHuR0eA=; b=AoWfTEzIX3AoPjm/OY8LhxS+s4mzWYqx2wZCztCIs55yRUEfVi7QJiExN+5hXtRMfP EK1LNktzvvRY+MkRXBwyNrsiji4aT2sPctFjjPH7yh6F7v++PqSQS48M8ibXfrz6/LzZ oqv+bew48phaXIIS7QXd5tTnV7b45dLldxBTd4ilslG4sT33oNbobwZjGM/4B9vJuVbG 0Cs+baXKrApcqDakf4W1tmufg5Mw4Jg/kgNtg2/uyj8QQ0xe3pVhLpGTCsL++MB7aoIR CvzvzdDkRjdV6vR07k2ezddbLe0y//Cv3pK6Nv5Cgx9z+UzCVygKMjvL32LuFAAOkz35 Xdzg== X-Gm-Message-State: AOAM531z9NvBxaCZGZZEz12PykXqvQKeD2I0rVwcKwrqj+MxzQN8T68+ Yf1LfclC+T8S8edHmpQHz05h45TPdw== X-Google-Smtp-Source: ABdhPJxJbcDYckRS0wVuzRySp2nuYSOJOG2pvGym1ZUIs47gMLvaU61ksR2fPMifrMOlNYqiUa3bx3KdoA== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:f693:9fff:fef4:2449]) (user=elver job=sendgmr) by 2002:a05:6214:b0d:: with SMTP id u13mr4600352qvj.17.1601386737145; Tue, 29 Sep 2020 06:38:57 -0700 (PDT) Date: Tue, 29 Sep 2020 15:38:09 +0200 In-Reply-To: <20200929133814.2834621-1-elver@google.com> Message-Id: <20200929133814.2834621-7-elver@google.com> Mime-Version: 1.0 References: <20200929133814.2834621-1-elver@google.com> X-Mailer: git-send-email 2.28.0.709.gb0816b6eb0-goog Subject: [PATCH v4 06/11] 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,