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: 11789907 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 A5B036CB for ; Mon, 21 Sep 2020 13:46:03 +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 725A6207C3 for ; Mon, 21 Sep 2020 13:46:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="lxp7RO3S"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="vbtjZioe"; 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 725A6207C3 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=ftzaQDlgKD67xYvQp6f/5XzwOcRvk/ePX/odaCsdm9o=; b=lxp7RO3SRiSEt8bzBnyBMCQLV fkQ/RIEEqNOlw5fKSjTcwEmD/RsU5n7ATYwymy83GbN34RFVueKOhdzqOB9gSL/Wg5W6yqNFy0s+6 I9IfTP8n7vqpsRqmmnna7b6cVeopZdBXZPiBtJxcuZGwFKEntBsuXxzP+F3A1dV34whX5Rc9ANkhE 1TO9gW75/vEKiKAV8RrdBZAUcaK0/nLLeKxUm0pXztW8a20+rTMTYPXrKMkQJC8GA3kDl91cD4DQ0 WK21zf9qBMGFvH0NODu51/KnOZp15ZniCUF146dW2lV/mnhgD7xQGgTw63XbIkBAZ+Ucz8uyG/dcB WxorEz17Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kKM6w-0002nn-Pr; Mon, 21 Sep 2020 13:44:06 +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 1kKM6g-0002gy-Ci for linux-arm-kernel@merlin.infradead.org; Mon, 21 Sep 2020 13:43:50 +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=k1T9dYB7DJoZ+u+nVe3kaxMkFtqFlEoHZfLN0p/pvEE=; b=vbtjZioexQKFwJ7bQRbUHwU02z 7UpQllTaexqRqTdh95tNXF7sP53LLIxv53ZIAT78gyFDM+XczHErqejQpgGePq8PQFKVzlG9ANYZy joHmnrK7klEOlhV2ad1imfkfp5gvLdjGmyAXpEj+93XWVYvTXpvoaSfxIjjzUgqkh/wLeubMX544R fkyR9vqtaUDnoUcOGzREACKt1dJja0Bx7xedOqJc1bri9cDVmQTr6dtIsvrU3Q8vb90p8/dDNPtta EORSKyOHeYMZmlwmmaNSwpq0ptF+UHixGAKrYAZJZgSXNniwJ9jiz0QRHym4J3euY6AdP9j80B3Wi k4gm7RZw==; Received: from mail-qv1-xf4a.google.com ([2607:f8b0:4864:20::f4a]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kKLqK-0003eC-An for linux-arm-kernel@lists.infradead.org; Mon, 21 Sep 2020 13:26:59 +0000 Received: by mail-qv1-xf4a.google.com with SMTP id a13so8933105qvl.6 for ; Mon, 21 Sep 2020 06:26:53 -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=R35MyZJ0G8WBrVpW3ejaQVS9TTxqKRoEFTJhfGYgJFm/kmCivb4HwhY4IrVhnKINK7 oHOtx5cG3vYEdWQNek0V1K4q9VcDfX/aJy9r58D0kjZ7UTb6kA3VVYJYiOmpV87J3klp XcT1VmckwwmjkKOvoVDf6xJiI49d13IyYQUVGtcMsWdK/HsUcQ5Czw4JfjH/lCzL/zEf 3i14ySdUgkHxnWABP3l9WZgwzazTXeM7Jc08MDTiFsH0wDjwP+y9RGAlDDoZ/ouTE2GK qGs0KcZHpEpcxysp7iFRXFrRyzSU7mS73ybirQxyMF/0FpuJXVbeWgMF37sz3rVHuKf5 uoaQ== X-Gm-Message-State: AOAM531Ev4uapIEgIj7QgprcEHq8nrxvJSK7RQGUdFEJfOhDzfiF4Ayt K5kdUXISAOEADboqf/FHkpQQeJGpzg== 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200921_142656_460629_B91F9488 X-CRM114-Status: GOOD ( 14.44 ) 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 [2607:f8b0:4864:20:0:0:0:f4a listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -7.5 USER_IN_DEF_DKIM_WL From: address is in the default DKIM white-list 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -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_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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: mark.rutland@arm.com, hdanton@sina.com, linux-doc@vger.kernel.org, peterz@infradead.org, catalin.marinas@arm.com, dave.hansen@linux.intel.com, linux-mm@kvack.org, edumazet@google.com, hpa@zytor.com, cl@linux.com, will@kernel.org, sjpark@amazon.com, corbet@lwn.net, x86@kernel.org, kasan-dev@googlegroups.com, mingo@redhat.com, vbabka@suse.cz, rientjes@google.com, aryabinin@virtuozzo.com, keescook@chromium.org, paulmck@kernel.org, jannh@google.com, andreyknvl@google.com, bp@alien8.de, luto@kernel.org, Jonathan.Cameron@huawei.com, tglx@linutronix.de, dvyukov@google.com, linux-arm-kernel@lists.infradead.org, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, penberg@kernel.org, iamjoonsoo.kim@lge.com 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. 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,