From patchwork Mon Sep 7 13:40:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Elver X-Patchwork-Id: 11761065 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 37A4A746 for ; Mon, 7 Sep 2020 13:43:33 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DAEBB21481 for ; Mon, 7 Sep 2020 13:43:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="cY70jzXZ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="sn+Q90cv"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="W3a/pmyA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DAEBB21481 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=gdjYs6hA3k+qClzQ6IP7sKDdfuXiDhmkI92eeiv1/OU=; b=cY70jzXZZgWluJw7W2Ezsh3NH KS5W13en8JQ6XsEeGFtkhKjrHZkQhQZ3KRLJqDPO6t4W4zL/sr3zap4BpUuwLrbUHIJVSv662jWLL 5LbGlf9RiwrU1WrARUSjkdmzMNl3ux6St78Jv/s7jkBhgqnDM9PCeFi0ikMPjjRNnsTtj5flSKL8t +QhBFM1LjRGtEPN6CGiNBR7QA8w6Kuoy9Jym56hUZJxQlp0pcHOXS/oiH1JcPddDO1aFD15FX3fCf xXcBu4e3k0xMpw3AtU1rbK+mAiAWdN131va+k+PYwmy2gQiZSaR6AL9u9BiNi7nDDY77YOGSN7Tyn ZI8q4URZA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kFHP4-0003ky-0Q; Mon, 07 Sep 2020 13:41:50 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kFHOn-0003el-Dq for linux-arm-kernel@merlin.infradead.org; Mon, 07 Sep 2020 13:41:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=sBEgph2pOr6CyODJ1uv8I0m4yR8SDTujVHr8yLlCuyo=; b=sn+Q90cv2eLQuIqv25Vb5RvkrM NlGxvurz0ZNglemq/0HCJ1IHoTmwCHbAHwDkle5VIz211ABsuEM0l5jR0GsHqhQfIEvI/k6vty1OR E0t1cjtDtI/iCByYziF9YlU8/poXZueodgjDI/ZhV0plW7EvopzMo++BaRIwHDU1/NINi67PXpYLh eW1auE7911Aonjx7Von+APYYKwJYreDAGgVLeSGzbzp9QfuGuyCK7339xYahgs/zEsVhVrW2UyTFI UaWhAqbhvuYjNnYgaFkTZhaDKyoFcWxxlbefOcVuqW+zYn9bpJdqipk3nyTP6b8qVzCXAlBeGZYmD 4UDQ1Giw==; Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kFHOh-00069d-Cb for linux-arm-kernel@lists.infradead.org; Mon, 07 Sep 2020 13:41:30 +0000 Received: by mail-wm1-x349.google.com with SMTP id d5so2868294wmb.2 for ; Mon, 07 Sep 2020 06:41:25 -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=sBEgph2pOr6CyODJ1uv8I0m4yR8SDTujVHr8yLlCuyo=; b=W3a/pmyA4RP9Ik4+QJ2hBf7+DdC59fjkdllmpsJW+SIiBQPN3kXyd9Kl+hHv33LAO8 0Rl7721pKfQjoHvZg5qD3ApYcG4ud82WNSxk7OFQ5p/DRxsI/wc1hgGYCDwxpDPlrMau 1vD8JshMZ5eXQ4eGdi+NX6QBfAAU1zXfaEEcd+/iPcOipwfLCv04EDrJPjCN2JfNQS2n hWtjfI6XY4eAGv7F9YdcWmMVOGPddTqLNehEiIxh84gokds7aOpJU/34ej4ZdtXwGqGd r7/F6AXB3t228e8XH01xJURnu3n83x2f94oZoI5f1Dg+cwUdzI69z9A1ttcD+jnYVWPP 2ryQ== 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=sBEgph2pOr6CyODJ1uv8I0m4yR8SDTujVHr8yLlCuyo=; b=qH3GKCf+adGl6FxcwNWJidhTrEbC8HR7OkUWFfnWT0fZyHUHseS7/pu6iPMASVIxUn 1U7y+tlKSqf6z+eDXUSuBEPUAxkAFM6k0Km6ZbTk+CzNnMj+SB5M+hPuyf7KSrD10Mml mO2lGFsakfFZwExoagB2+TqaPjSp2SiJzMfP2Uj1hYcdj1E7c2rqkmj7/TLZCUEnP8iu tOVQD702as60NlTSPSK+nVpUtrwAzqe5Xs7xXBneEVih32R+i5a4hqev+M21URCCPHL6 Xrom6d0Pz/VAkAT9Ajee/OF/Gj0vGrfkYtNPOEpAxxq4aubCUjg/FDPy8gTvpG399h13 Dt5g== X-Gm-Message-State: AOAM533wvD1d57PQM6ggErS8dF9vetPMxbsw5O7SjvqP3O/OdDEBJFsQ YnGmP0/EUcEEqGLpgYp2tTMc6qkmMQ== X-Google-Smtp-Source: ABdhPJxeJUaJi1Li1DPHii5Sj4LSLAplbFw0CU8QzsUMSMD+wpw59PJfS96CMu44VRwFFVbpHpJk5iEgwg== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:f693:9fff:fef4:2449]) (user=elver job=sendgmr) by 2002:a7b:c019:: with SMTP id c25mr9339wmb.0.1599486083942; Mon, 07 Sep 2020 06:41:23 -0700 (PDT) Date: Mon, 7 Sep 2020 15:40:51 +0200 In-Reply-To: <20200907134055.2878499-1-elver@google.com> Message-Id: <20200907134055.2878499-7-elver@google.com> Mime-Version: 1.0 References: <20200907134055.2878499-1-elver@google.com> X-Mailer: git-send-email 2.28.0.526.ge36021eeef-goog Subject: [PATCH RFC 06/10] kfence, kasan: make KFENCE compatible with KASAN From: Marco Elver To: elver@google.com, glider@google.com, akpm@linux-foundation.org, catalin.marinas@arm.com, cl@linux.com, rientjes@google.com, iamjoonsoo.kim@lge.com, mark.rutland@arm.com, penberg@kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200907_144127_520963_D9833042 X-CRM114-Status: GOOD ( 14.64 ) X-Spam-Score: -9.6 (---------) X-Spam-Report: SpamAssassin version 3.4.4 on casper.infradead.org summary: Content analysis details: (-9.6 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:349 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -7.5 USER_IN_DEF_DKIM_WL From: address is in the default DKIM white-list -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.0 DKIMWL_WL_MED DKIMwl.org - Medium sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-doc@vger.kernel.org, peterz@infradead.org, dave.hansen@linux.intel.com, linux-mm@kvack.org, edumazet@google.com, hpa@zytor.com, will@kernel.org, corbet@lwn.net, x86@kernel.org, kasan-dev@googlegroups.com, mingo@redhat.com, linux-arm-kernel@lists.infradead.org, aryabinin@virtuozzo.com, keescook@chromium.org, paulmck@kernel.org, jannh@google.com, andreyknvl@google.com, cai@lca.pw, luto@kernel.org, tglx@linutronix.de, dvyukov@google.com, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, bp@alien8.de Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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. 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 7ac91162edb0..b080e49e15d4 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,