From patchwork Mon Nov 23 20:14:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11926661 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A09A3C388F9 for ; Mon, 23 Nov 2020 20:31:59 +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 EBEE920715 for ; Mon, 23 Nov 2020 20:31:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="GIpl12R5"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="vE2RlTTz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EBEE920715 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+linux-arm-kernel=archiver.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=VEg4mwdvjJCoytY0BsjiWSQW9b8ZNFKcnxb4ClozOYs=; b=GIpl12R56No7RzvfeanGRY9sl A/Cj+JWZ8rOeYOQPZ1QZtmGJNRBMrLVigiILnh92f2Z+TbfIFTI5Fw9va2NyvI7MYc0UHyxBXHrx3 r9IO6V55EWki1kYqMVd4TwUeGn2UZjDbqPH4I/GGk4xmLPyg5XdVdkPTltK/mMxF0lZdfyrHUJLGc sK3Hkx+bozACLtPylIt2vjoEZNFgjYyXcQd7L9Gs1VB1Fm8grhLImZpDrf6liEcSx0ICo/9pKhPvq Luyr2WMDwj8yIZbIsDLf0MqNaeZYBcNXCUQrYt1rwV4m7p4XdCkw4QyB7Ob41TpuVBB/yKQoifoPq jfAkaR8yA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khITX-0000WS-ON; Mon, 23 Nov 2020 20:30:15 +0000 Received: from mail-qk1-x749.google.com ([2607:f8b0:4864:20::749]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIEm-00026f-As for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2020 20:15:02 +0000 Received: by mail-qk1-x749.google.com with SMTP id c18so15559587qkl.15 for ; Mon, 23 Nov 2020 12:14:57 -0800 (PST) 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=X8He+i5DTpgfYKqVr7f46nksdkLo8KZ5P0WRCUmFYW8=; b=vE2RlTTzBzO5Gu2A4Wlttso8aG+Md8VyWf3JRDOc1Rk1bLUV819+D3mRFk8KL3kdCG eXUGqYHjERGJSQYpOySgTRgSxDqdgGaOMismdtSjBIQFp7VMipUQnz3fsflxJBsTgjmH NTkvIqSK2uP2oEw57s2L/OQz6kWSVTj1zYVffNLK8eHvX8vuv0hOk/6SCps9Wj1XwINP adkHqjEHjQsc17VN0LO03Evgdty940In8beiJqeKz0sawcA/v6PNFAx/exm7EBcnbW+R oqSoQUga4Kh5eizfSuq5arMaMeewWgBhiYoyf2DJQl0xvTuFK0f+3u+3d79cZRKSlWGJ CCnA== 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=X8He+i5DTpgfYKqVr7f46nksdkLo8KZ5P0WRCUmFYW8=; b=dbmBgS1CACTGK+2DXwUqaehnZES0hD/+eNGwQzQXwgFcq3csmat/bFBa1fbwcGvmtv YN9VZyqoHRcWzgEZEaWzWTkwzc7NgUGcj4wShoqM2klRtJ2zMVSBdbfeZ3kNKFuSdkfv BFyC9r84mtVbhjvC4EPseKiO7tAnoR+izsiFslbkVw3ZCd8ch/Kd1jSwi+mkfKxZ4N+J 4EAFF+AyEApXY1pxPYlbwHc6lQWK8hMbJneKyt+v96fex+s1PT5GtYzXjYo1P/SJBAm7 C9Q7NZQDmuSBnTa4X2+RVgcVk9Z3UqH3VUR8wZBVmVVjmMR/vZUv01lBgivfMgYQFqx9 VAfw== X-Gm-Message-State: AOAM532Hu8RLupjHpaF8CPcHhklL2q6T07SiVDmjqNuE9IbFwccBwKH/ KzJR7scgwYAc0nSkBeVUb4pM1CE4GpXD7rzs X-Google-Smtp-Source: ABdhPJwdwL1lWnof+uE3ypolP2P0M2AIXFB3wOTJiySzgHkkoCi1sbMWbkPHW5t6+b/xqQEPSNiAl3jFR3LB4TT+ X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a0c:eac4:: with SMTP id y4mr1134178qvp.19.1606162496039; Mon, 23 Nov 2020 12:14:56 -0800 (PST) Date: Mon, 23 Nov 2020 21:14:31 +0100 In-Reply-To: Message-Id: <312d0a3ef92cc6dc4fa5452cbc1714f9393ca239.1606162397.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH mm v4 01/19] kasan: simplify quarantine_put call site From: Andrey Konovalov To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201123_151500_461896_295A1C5A X-CRM114-Status: GOOD ( 14.59 ) 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-arm-kernel@lists.infradead.org, Marco Elver , Catalin Marinas , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Konovalov , Andrey Ryabinin , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Move get_free_info() call into quarantine_put() to simplify the call site. No functional changes. Signed-off-by: Andrey Konovalov Reviewed-by: Dmitry Vyukov Reviewed-by: Marco Elver Link: https://linux-review.googlesource.com/id/Iab0f04e7ebf8d83247024b7190c67c3c34c7940f --- mm/kasan/common.c | 2 +- mm/kasan/kasan.h | 5 ++--- mm/kasan/quarantine.c | 3 ++- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 998aede4d172..e11fac2ee30c 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -317,7 +317,7 @@ static bool __kasan_slab_free(struct kmem_cache *cache, void *object, kasan_set_free_info(cache, object, tag); - quarantine_put(get_free_info(cache, object), cache); + quarantine_put(cache, object); return IS_ENABLED(CONFIG_KASAN_GENERIC); } diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 64560cc71191..13c511e85d5f 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -216,12 +216,11 @@ struct kasan_track *kasan_get_free_track(struct kmem_cache *cache, #if defined(CONFIG_KASAN_GENERIC) && \ (defined(CONFIG_SLAB) || defined(CONFIG_SLUB)) -void quarantine_put(struct kasan_free_meta *info, struct kmem_cache *cache); +void quarantine_put(struct kmem_cache *cache, void *object); void quarantine_reduce(void); void quarantine_remove_cache(struct kmem_cache *cache); #else -static inline void quarantine_put(struct kasan_free_meta *info, - struct kmem_cache *cache) { } +static inline void quarantine_put(struct kmem_cache *cache, void *object) { } static inline void quarantine_reduce(void) { } static inline void quarantine_remove_cache(struct kmem_cache *cache) { } #endif diff --git a/mm/kasan/quarantine.c b/mm/kasan/quarantine.c index 580ff5610fc1..a0792f0d6d0f 100644 --- a/mm/kasan/quarantine.c +++ b/mm/kasan/quarantine.c @@ -161,11 +161,12 @@ static void qlist_free_all(struct qlist_head *q, struct kmem_cache *cache) qlist_init(q); } -void quarantine_put(struct kasan_free_meta *info, struct kmem_cache *cache) +void quarantine_put(struct kmem_cache *cache, void *object) { unsigned long flags; struct qlist_head *q; struct qlist_head temp = QLIST_INIT; + struct kasan_free_meta *info = get_free_info(cache, object); /* * Note: irq must be disabled until after we move the batch to the From patchwork Mon Nov 23 20:14:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11926667 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5048C2D0E4 for ; Mon, 23 Nov 2020 20:33:50 +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 4309420715 for ; Mon, 23 Nov 2020 20:33:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="L6m1V1KC"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="fk9aLtCh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4309420715 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+linux-arm-kernel=archiver.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=FSojqPivgGUNs3Zd/6C8DgTONz6yBYdCpkX6H6aTpvE=; b=L6m1V1KCW5RTzXc96OKELyw9D Z7IWmEQiGNCZxRwSZ9rnLFw175EHlMkFQmApW6rvQb8FhrpZrjLQG6misCOQIxDLj4p+jykgDz9xw 50g79ro21YGfKWi/EP50/badg+eWuTMofukZKYRKUTjAkg/sxznddsYjmzoyKcUvaXvaIPu2BdUJ4 j33bWmkHXYLgNbpzTogRr13sq4w6tZVRF4zUXky+GSd5b4wqia5eSV8176hPPHP5O3H1UrdPzGfwJ 0UpGnadR+ad/kAqGjAINO+D0lVjSwd4/I+CpyScebeoWFyb6N4Oukos+rD8xs8B5fTBUHYUOS/kPh GfFVT+v5Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIUr-00016V-RN; Mon, 23 Nov 2020 20:31:38 +0000 Received: from mail-qk1-x74a.google.com ([2607:f8b0:4864:20::74a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIEt-00028D-41 for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2020 20:15:15 +0000 Received: by mail-qk1-x74a.google.com with SMTP id z129so2833951qkb.13 for ; Mon, 23 Nov 2020 12:14:59 -0800 (PST) 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=Q1jnDs8w1xeJeKoumjoM2fj7KFzVMx2xpTSCdfWMzaI=; b=fk9aLtChmZLGIQyf1PGVZC+ap8+7GNwfffNMv2tS8vb/gOtKMdeGo5YqeOWsEpyOSm Neb++K0kvvdN0iT1Py3tI94wV+P3UByw2Pkdq+j5rHnQagsY5EDC9sQ+wypnvD57TCiO V7usRRTD4uEJnPui7yUKbb7BSpb/EwiZhBdN9RAxmF4I0UqcqcEOhq9RXW3YV93gBqzX VYjTAEoBIlhzRs2KS1nXiHA4WZzs7Mpwqz4cds/ERGbcQKZK7COwjCA/0zy4SN+njdRk vlNs+svG+PoA2nvCvfKr5h18bdeWjwVwm2GcargM2+/rW6mpvSzzwUT9e3OTWx3ksAAW RnbA== 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=Q1jnDs8w1xeJeKoumjoM2fj7KFzVMx2xpTSCdfWMzaI=; b=fTTOFut646suM6skU8DF2OcFjzvItF70Tsq8K3AF1JtRl4losZinjPXHCDl3jm8G2d UXCcz2J6bQtpzb8lDADXuTpAWJsjjUI43YFMFek8r4iZ3kVV1+Y+tFODs0HSeTZes+Uf jPgaZYf2rR2iVxxGUjJT5wukQjY1B1COCdSsjxSoEsDGcCpYRZA0iD0GK6/88081//Oo Z7I51oJ3IC3HVtTVGyp8CfpltRK4N2csMY479/OgWI7rKigjG52KKDAZM99kYgsh4Vom fa9CPfT8UQOO43rjlbc+LJuzVqVNmdxJAFwXsecE+7k4nHc/vV/x1LQnPvsFnpcY06WO q4sw== X-Gm-Message-State: AOAM531gi4tmr4b61G+hOLEF7BQwkdSCgg1NGOO+CL4eNvzWzQC+AMqm PkaS4B8r1IyI4NAn3Ialg24pyTGGMcqBnkCU X-Google-Smtp-Source: ABdhPJxjiFxKuAWSU1YsZDwHLjMfXbzEG5ZQcQMsjj1BidAS/Q15I+apkubUzqdOI3UP5PWbwtrwjfV5MgEM+dRc X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a0c:f981:: with SMTP id t1mr1155145qvn.60.1606162498261; Mon, 23 Nov 2020 12:14:58 -0800 (PST) Date: Mon, 23 Nov 2020 21:14:32 +0100 In-Reply-To: Message-Id: <27b7c036b754af15a2839e945f6d8bfce32b4c2f.1606162397.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH mm v4 02/19] kasan: rename get_alloc/free_info From: Andrey Konovalov To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201123_151507_983489_B83B62B5 X-CRM114-Status: GOOD ( 19.23 ) 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-arm-kernel@lists.infradead.org, Marco Elver , Catalin Marinas , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Konovalov , Andrey Ryabinin , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Rename get_alloc_info() and get_free_info() to kasan_get_alloc_meta() and kasan_get_free_meta() to better reflect what those do and avoid confusion with kasan_set_free_info(). No functional changes. Signed-off-by: Andrey Konovalov Reviewed-by: Dmitry Vyukov Reviewed-by: Marco Elver Link: https://linux-review.googlesource.com/id/Ib6e4ba61c8b12112b403d3479a9799ac8fff8de1 --- mm/kasan/common.c | 16 ++++++++-------- mm/kasan/generic.c | 12 ++++++------ mm/kasan/hw_tags.c | 4 ++-- mm/kasan/kasan.h | 8 ++++---- mm/kasan/quarantine.c | 4 ++-- mm/kasan/report.c | 12 ++++++------ mm/kasan/report_sw_tags.c | 2 +- mm/kasan/sw_tags.c | 4 ++-- 8 files changed, 31 insertions(+), 31 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index e11fac2ee30c..8197399b0a1f 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -181,14 +181,14 @@ size_t kasan_metadata_size(struct kmem_cache *cache) sizeof(struct kasan_free_meta) : 0); } -struct kasan_alloc_meta *get_alloc_info(struct kmem_cache *cache, - const void *object) +struct kasan_alloc_meta *kasan_get_alloc_meta(struct kmem_cache *cache, + const void *object) { return (void *)reset_tag(object) + cache->kasan_info.alloc_meta_offset; } -struct kasan_free_meta *get_free_info(struct kmem_cache *cache, - const void *object) +struct kasan_free_meta *kasan_get_free_meta(struct kmem_cache *cache, + const void *object) { BUILD_BUG_ON(sizeof(struct kasan_free_meta) > 32); return (void *)reset_tag(object) + cache->kasan_info.free_meta_offset; @@ -265,13 +265,13 @@ static u8 assign_tag(struct kmem_cache *cache, const void *object, void * __must_check kasan_init_slab_obj(struct kmem_cache *cache, const void *object) { - struct kasan_alloc_meta *alloc_info; + struct kasan_alloc_meta *alloc_meta; if (!(cache->flags & SLAB_KASAN)) return (void *)object; - alloc_info = get_alloc_info(cache, object); - __memset(alloc_info, 0, sizeof(*alloc_info)); + alloc_meta = kasan_get_alloc_meta(cache, object); + __memset(alloc_meta, 0, sizeof(*alloc_meta)); if (IS_ENABLED(CONFIG_KASAN_SW_TAGS) || IS_ENABLED(CONFIG_KASAN_HW_TAGS)) object = set_tag(object, assign_tag(cache, object, true, false)); @@ -357,7 +357,7 @@ static void *__kasan_kmalloc(struct kmem_cache *cache, const void *object, KASAN_KMALLOC_REDZONE); if (cache->flags & SLAB_KASAN) - kasan_set_track(&get_alloc_info(cache, object)->alloc_track, flags); + kasan_set_track(&kasan_get_alloc_meta(cache, object)->alloc_track, flags); return set_tag(object, tag); } diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index da3608187c25..9c6b77f8c4a4 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -329,7 +329,7 @@ void kasan_record_aux_stack(void *addr) { struct page *page = kasan_addr_to_page(addr); struct kmem_cache *cache; - struct kasan_alloc_meta *alloc_info; + struct kasan_alloc_meta *alloc_meta; void *object; if (is_kfence_address(addr) || !(page && PageSlab(page))) @@ -337,13 +337,13 @@ void kasan_record_aux_stack(void *addr) cache = page->slab_cache; object = nearest_obj(cache, page, addr); - alloc_info = get_alloc_info(cache, object); + alloc_meta = kasan_get_alloc_meta(cache, object); /* * record the last two call_rcu() call stacks. */ - alloc_info->aux_stack[1] = alloc_info->aux_stack[0]; - alloc_info->aux_stack[0] = kasan_save_stack(GFP_NOWAIT); + alloc_meta->aux_stack[1] = alloc_meta->aux_stack[0]; + alloc_meta->aux_stack[0] = kasan_save_stack(GFP_NOWAIT); } void kasan_set_free_info(struct kmem_cache *cache, @@ -351,7 +351,7 @@ void kasan_set_free_info(struct kmem_cache *cache, { struct kasan_free_meta *free_meta; - free_meta = get_free_info(cache, object); + free_meta = kasan_get_free_meta(cache, object); kasan_set_track(&free_meta->free_track, GFP_NOWAIT); /* @@ -365,5 +365,5 @@ struct kasan_track *kasan_get_free_track(struct kmem_cache *cache, { if (*(u8 *)kasan_mem_to_shadow(object) != KASAN_KMALLOC_FREETRACK) return NULL; - return &get_free_info(cache, object)->free_track; + return &kasan_get_free_meta(cache, object)->free_track; } diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c index 3f9232464ed4..68e77363e58b 100644 --- a/mm/kasan/hw_tags.c +++ b/mm/kasan/hw_tags.c @@ -75,7 +75,7 @@ void kasan_set_free_info(struct kmem_cache *cache, { struct kasan_alloc_meta *alloc_meta; - alloc_meta = get_alloc_info(cache, object); + alloc_meta = kasan_get_alloc_meta(cache, object); kasan_set_track(&alloc_meta->free_track[0], GFP_NOWAIT); } @@ -84,6 +84,6 @@ struct kasan_track *kasan_get_free_track(struct kmem_cache *cache, { struct kasan_alloc_meta *alloc_meta; - alloc_meta = get_alloc_info(cache, object); + alloc_meta = kasan_get_alloc_meta(cache, object); return &alloc_meta->free_track[0]; } diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 13c511e85d5f..0eab7e4cecb8 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -149,10 +149,10 @@ struct kasan_free_meta { #endif }; -struct kasan_alloc_meta *get_alloc_info(struct kmem_cache *cache, - const void *object); -struct kasan_free_meta *get_free_info(struct kmem_cache *cache, - const void *object); +struct kasan_alloc_meta *kasan_get_alloc_meta(struct kmem_cache *cache, + const void *object); +struct kasan_free_meta *kasan_get_free_meta(struct kmem_cache *cache, + const void *object); void poison_range(const void *address, size_t size, u8 value); void unpoison_range(const void *address, size_t size); diff --git a/mm/kasan/quarantine.c b/mm/kasan/quarantine.c index a0792f0d6d0f..0da3d37e1589 100644 --- a/mm/kasan/quarantine.c +++ b/mm/kasan/quarantine.c @@ -166,7 +166,7 @@ void quarantine_put(struct kmem_cache *cache, void *object) unsigned long flags; struct qlist_head *q; struct qlist_head temp = QLIST_INIT; - struct kasan_free_meta *info = get_free_info(cache, object); + struct kasan_free_meta *meta = kasan_get_free_meta(cache, object); /* * Note: irq must be disabled until after we move the batch to the @@ -179,7 +179,7 @@ void quarantine_put(struct kmem_cache *cache, void *object) local_irq_save(flags); q = this_cpu_ptr(&cpu_quarantine); - qlist_put(q, &info->quarantine_link, cache->size); + qlist_put(q, &meta->quarantine_link, cache->size); if (unlikely(q->bytes > QUARANTINE_PERCPU_SIZE)) { qlist_move_all(q, &temp); diff --git a/mm/kasan/report.c b/mm/kasan/report.c index a69c2827a125..df16bef0d810 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -164,12 +164,12 @@ static void describe_object_addr(struct kmem_cache *cache, void *object, static void describe_object(struct kmem_cache *cache, void *object, const void *addr, u8 tag) { - struct kasan_alloc_meta *alloc_info = get_alloc_info(cache, object); + struct kasan_alloc_meta *alloc_meta = kasan_get_alloc_meta(cache, object); if (cache->flags & SLAB_KASAN) { struct kasan_track *free_track; - print_track(&alloc_info->alloc_track, "Allocated"); + print_track(&alloc_meta->alloc_track, "Allocated"); pr_err("\n"); free_track = kasan_get_free_track(cache, object, tag); if (free_track) { @@ -178,14 +178,14 @@ static void describe_object(struct kmem_cache *cache, void *object, } #ifdef CONFIG_KASAN_GENERIC - if (alloc_info->aux_stack[0]) { + if (alloc_meta->aux_stack[0]) { pr_err("Last call_rcu():\n"); - print_stack(alloc_info->aux_stack[0]); + print_stack(alloc_meta->aux_stack[0]); pr_err("\n"); } - if (alloc_info->aux_stack[1]) { + if (alloc_meta->aux_stack[1]) { pr_err("Second to last call_rcu():\n"); - print_stack(alloc_info->aux_stack[1]); + print_stack(alloc_meta->aux_stack[1]); pr_err("\n"); } #endif diff --git a/mm/kasan/report_sw_tags.c b/mm/kasan/report_sw_tags.c index aebc44a29e83..317100fd95b9 100644 --- a/mm/kasan/report_sw_tags.c +++ b/mm/kasan/report_sw_tags.c @@ -46,7 +46,7 @@ const char *get_bug_type(struct kasan_access_info *info) if (page && PageSlab(page)) { cache = page->slab_cache; object = nearest_obj(cache, page, (void *)addr); - alloc_meta = get_alloc_info(cache, object); + alloc_meta = kasan_get_alloc_meta(cache, object); for (i = 0; i < KASAN_NR_FREE_STACKS; i++) if (alloc_meta->free_pointer_tag[i] == tag) diff --git a/mm/kasan/sw_tags.c b/mm/kasan/sw_tags.c index a518483f3965..6d7648cc3b98 100644 --- a/mm/kasan/sw_tags.c +++ b/mm/kasan/sw_tags.c @@ -174,7 +174,7 @@ void kasan_set_free_info(struct kmem_cache *cache, struct kasan_alloc_meta *alloc_meta; u8 idx = 0; - alloc_meta = get_alloc_info(cache, object); + alloc_meta = kasan_get_alloc_meta(cache, object); #ifdef CONFIG_KASAN_SW_TAGS_IDENTIFY idx = alloc_meta->free_track_idx; @@ -191,7 +191,7 @@ struct kasan_track *kasan_get_free_track(struct kmem_cache *cache, struct kasan_alloc_meta *alloc_meta; int i = 0; - alloc_meta = get_alloc_info(cache, object); + alloc_meta = kasan_get_alloc_meta(cache, object); #ifdef CONFIG_KASAN_SW_TAGS_IDENTIFY for (i = 0; i < KASAN_NR_FREE_STACKS; i++) { From patchwork Mon Nov 23 20:14:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11926659 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0AB3C388F9 for ; Mon, 23 Nov 2020 20:31:51 +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 64BF320715 for ; Mon, 23 Nov 2020 20:31:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="iN9gHgaH"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="X8wfvSUP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 64BF320715 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+linux-arm-kernel=archiver.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=TKwPaMpEq4JoWcMB4pNa+HrLapdrIHx4v2Eo/zQA3LM=; b=iN9gHgaH+F0bltBkXiee7e0aC p8ETdnW7zQbuM6Vqh4tzRe/kXkrddHAkfTuO8fb0mN0J+a/Hl3o0lQwzP4Cbip8V15rjaNA6QrBUs eyHUR9mk0vg/Kg3xKFZPt09HnuppNybixEwcyzmMw2pYqZlWAJi7k1EQjTYTxKDiyT9u9FFag15mV yjxjrZjcHyyd+nXKgBL0FDp4HsHQCRJlIHSl9QsohRFjYJYZPHSNmxMXraIyIqnyeuF+wvv/JWTt9 mcrL4bEaBX7rC0SJ4/wD6ucaB3tSjUhxPhnQY56PwUeSE0V4mX/x78SY6NGiAmOyuZrw9xciPmxe2 gS4C+aiyw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIUT-0000vG-1C; Mon, 23 Nov 2020 20:31:13 +0000 Received: from mail-qt1-x84a.google.com ([2607:f8b0:4864:20::84a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIEt-00029P-6Q for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2020 20:15:12 +0000 Received: by mail-qt1-x84a.google.com with SMTP id i39so14498639qtb.1 for ; Mon, 23 Nov 2020 12:15:03 -0800 (PST) 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=X0qNbr9WproLcGX2R7jejC4I91Gg1JCilClxf4uOdQ4=; b=X8wfvSUPWDOeubA5laS0MiS+5zHTHlfDCeXD7x++Y29NOmeLLnfbzlFHR4Hb5I2RLu 9wd7W4DbL8t9WKn3i3FFJCexrLUKyqTUwXXHQ430kj8PdXDFnUpSI4xrd3GsfIU/ptme K5x/3lGScHV8LUNjww9qOHEJXgtGUueWlDXazSz1ByCXleTVf1o8CzId6vU/sQOvsLIK qdHzXbL8ZjXUmWsfu1sm/1iqAf842e3xeAL6FiYUl8MBbvK82iAc5qTIJtyBLOIjQMpZ rODbG8A5iOgyQ40ayjPhbqHoBebQeju5HciYk8AeFACmdvRUt57vrv0DQ7E+Gd4Gj2ZU TM7Q== 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=X0qNbr9WproLcGX2R7jejC4I91Gg1JCilClxf4uOdQ4=; b=IzIEUex/B0C8Mo9qDsaNUUL34c/s3FXmqSQGNZIpgGk9pBq3h4P1AC5QMhiIbT/Tsa mkA1h9kcEhQ647bY0UCQh3DVxpXyvO2PUxOsB9MYUdzrA7tQR76Apwx6yiUpsJDBqntI YBRY+z8YSKeZOwyj9lwziB0bLMuJdg3dA3NBFaS7mEC+1lGaVBEZDeGW+AeCT+F++ikv sihY/giHozGHBbPuXMdZXizRo1ZOGSrfSqNwLU5SCURto2jGW1qP5OW20/OzFVy1olpG EEjvstaXM/siR+xuvXwFKHiJ91Q73Ds0eyQ7dzKJJpW7otoqu3sOzq7Hzs4c74aTbxgw pPQg== X-Gm-Message-State: AOAM5323bw4IxpJxJ+US1/RUzLdo1/MAYflP8FEfz6VqvKai8//btpFO hfjM4CNoDxXXtT8jIceFNaZaWN9Vr0I898Dy X-Google-Smtp-Source: ABdhPJzImvXjbgZa+dqZyuNCYbUOjmgmMgki62vl+7qg8STo88r/i4TsRQg7xr1TST9CH00poNibD1gCn0B4pbPv X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a05:6214:9a9:: with SMTP id du9mr1102774qvb.47.1606162500502; Mon, 23 Nov 2020 12:15:00 -0800 (PST) Date: Mon, 23 Nov 2020 21:14:33 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH mm v4 03/19] kasan: introduce set_alloc_info From: Andrey Konovalov To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201123_151507_882879_83F77A5E X-CRM114-Status: GOOD ( 12.74 ) 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-arm-kernel@lists.infradead.org, Marco Elver , Catalin Marinas , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Konovalov , Andrey Ryabinin , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add set_alloc_info() helper and move kasan_set_track() into it. This will simplify the code for one of the upcoming changes. No functional changes. Signed-off-by: Andrey Konovalov Reviewed-by: Dmitry Vyukov Reviewed-by: Marco Elver Link: https://linux-review.googlesource.com/id/I0316193cbb4ecc9b87b7c2eee0dd79f8ec908c1a --- mm/kasan/common.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 8197399b0a1f..0a420f1dbc54 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -327,6 +327,11 @@ bool kasan_slab_free(struct kmem_cache *cache, void *object, unsigned long ip) return __kasan_slab_free(cache, object, ip, true); } +static void set_alloc_info(struct kmem_cache *cache, void *object, gfp_t flags) +{ + kasan_set_track(&kasan_get_alloc_meta(cache, object)->alloc_track, flags); +} + static void *__kasan_kmalloc(struct kmem_cache *cache, const void *object, size_t size, gfp_t flags, bool keep_tag) { @@ -357,7 +362,7 @@ static void *__kasan_kmalloc(struct kmem_cache *cache, const void *object, KASAN_KMALLOC_REDZONE); if (cache->flags & SLAB_KASAN) - kasan_set_track(&kasan_get_alloc_meta(cache, object)->alloc_track, flags); + set_alloc_info(cache, (void *)object, flags); return set_tag(object, tag); } From patchwork Mon Nov 23 20:14:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11926665 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66EFAC2D0E4 for ; Mon, 23 Nov 2020 20:33:06 +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 031E720715 for ; Mon, 23 Nov 2020 20:33:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="0Pvwpyac"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="SgzwKhZ3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 031E720715 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+linux-arm-kernel=archiver.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=NNhAsJPNKAIQKCgnZ5GxJc80zLIzQm8QrTlLdqqTQNA=; b=0PvwpyacKNQPjMz+Y2cmLTYdc idM5ADv/iRI4QqUuVCRJtJWzxCDkg9+QMFE4xh3WpHt1n7KneLdaNGOCnxKpNDKas75p63f49+fg1 sjZZ+duf9Ppfg6cdAGB7lqaKtSdvzt5c5qQr4dyGhLC0hebrdzxmfE+UC4F6ILokCi6IL0MHR3ivW wFaOHrFb3seUZQ+kO1rxGe8bHAGgc3gtzY/4P0kpOD9WL9J3PTWj13CJhuEp5DBtEQ+kjLnB3ins+ ned4gjdjo0m+O33r5X/sgBJzihDrUpfPIrMa5rtfG73pmItRSW/ixH/H9WQNCCWZk+17wjQGKK89G 1aghfXW0Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIUA-0000nc-JY; Mon, 23 Nov 2020 20:30:54 +0000 Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIEz-0002Ai-I8 for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2020 20:15:22 +0000 Received: by mail-wm1-x34a.google.com with SMTP id c131so167905wma.0 for ; Mon, 23 Nov 2020 12:15:04 -0800 (PST) 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=+fKBF8tk63anOpwt8A+LLR3Qf9R2P9gh2kXJ7NwYZig=; b=SgzwKhZ3R7W8sEp5bQojT95yPgII8yrnXK5PJm+8HBvCo7ZvvLUdSItbJK1GypiV78 xMXJN2ddUn+Rv5nTs1g2AGrivz1eSBhSPLPPA0QfNA5m8rvl5htFaDg+0OiuZ7J/Z4dS pBPZAOVwDwTyJETT3lYeHe/k41kbPwac0mKH7x+6K9Awsno7hCRm9BB3ODF4CwyYxbBb G/yNMKKAjoXIdmarVhQ6zhe2BlfpgbEKX1VJckdMF2Vp3Qmqjp1x2TA8rHeXavGGXT3o pguxCy6HrmCIuVEzT6REGnEXnVZH6DRhHApxMhlMXIOz6uRXZ/7IANmJlnuv3lgicWs2 YVrA== 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=+fKBF8tk63anOpwt8A+LLR3Qf9R2P9gh2kXJ7NwYZig=; b=fcFYMCcFZPn6PMQDe4e810wtIoxMTsxUsiKgLBHS8tlzWEfu4WJNvysToJNmQC5IEW qt/NFrMUaxRAUYru3C+dQS7ve9R2NPKKUN8zTySIyKFy7Izlb1NQdp06xyULJIhEiEey 9UCfs1Xj9lCr1ffvUWnR2alryU64cO6jc7OIyeyVd8sdC4bvHmhKzI8yilUiBuQckQ1C mrnxUS/4JaL0vjzqtqs1fRoCW+0TblJfrYKVHRmeVTnCy4E2kOgOvKUzrDpPHHhwagpt 4zU6mYb3qqelD3/wlJK5DGgChpyGp4vQ6z0bMIvTHcjOtwa5poroWiL1sTJk+glvVuoQ uYKw== X-Gm-Message-State: AOAM533wYyQYJmv5cRUzIE+DtA5+ujEJk9TCB5nXzo5VZ7FyLGjoY8ZN qKTduByLLkjkj/RlLAQouiS1RKAgUCVdOkA5 X-Google-Smtp-Source: ABdhPJy/rTCKa1eqa4mc4yEePlJFS2fAIHVEaaW/JgmCKkRtM+WiCe9SRu9w0wLP/xG8lUZlsreU6FcBRJ22hAo7 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a05:600c:ce:: with SMTP id u14mr639471wmm.150.1606162503128; Mon, 23 Nov 2020 12:15:03 -0800 (PST) Date: Mon, 23 Nov 2020 21:14:34 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH mm v4 04/19] kasan, arm64: unpoison stack only with CONFIG_KASAN_STACK From: Andrey Konovalov To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201123_151514_625545_EE9EE652 X-CRM114-Status: GOOD ( 17.01 ) 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-arm-kernel@lists.infradead.org, Marco Elver , Catalin Marinas , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Konovalov , Andrey Ryabinin , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org There's a config option CONFIG_KASAN_STACK that has to be enabled for KASAN to use stack instrumentation and perform validity checks for stack variables. There's no need to unpoison stack when CONFIG_KASAN_STACK is not enabled. Only call kasan_unpoison_task_stack[_below]() when CONFIG_KASAN_STACK is enabled. Note, that CONFIG_KASAN_STACK is an option that is currently always defined when CONFIG_KASAN is enabled, and therefore has to be tested with #if instead of #ifdef. Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver Acked-by: Catalin Marinas Reviewed-by: Dmitry Vyukov Link: https://linux-review.googlesource.com/id/If8a891e9fe01ea543e00b576852685afec0887e3 --- arch/arm64/kernel/sleep.S | 2 +- arch/x86/kernel/acpi/wakeup_64.S | 2 +- include/linux/kasan.h | 10 ++++++---- mm/kasan/common.c | 2 ++ 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kernel/sleep.S b/arch/arm64/kernel/sleep.S index ba40d57757d6..bdadfa56b40e 100644 --- a/arch/arm64/kernel/sleep.S +++ b/arch/arm64/kernel/sleep.S @@ -133,7 +133,7 @@ SYM_FUNC_START(_cpu_resume) */ bl cpu_do_resume -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN) && CONFIG_KASAN_STACK mov x0, sp bl kasan_unpoison_task_stack_below #endif diff --git a/arch/x86/kernel/acpi/wakeup_64.S b/arch/x86/kernel/acpi/wakeup_64.S index c8daa92f38dc..5d3a0b8fd379 100644 --- a/arch/x86/kernel/acpi/wakeup_64.S +++ b/arch/x86/kernel/acpi/wakeup_64.S @@ -112,7 +112,7 @@ SYM_FUNC_START(do_suspend_lowlevel) movq pt_regs_r14(%rax), %r14 movq pt_regs_r15(%rax), %r15 -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN) && CONFIG_KASAN_STACK /* * The suspend path may have poisoned some areas deeper in the stack, * which we now need to unpoison. diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 0c89e6fdd29e..f2109bf0c5f9 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -76,8 +76,6 @@ static inline void kasan_disable_current(void) {} void kasan_unpoison_range(const void *address, size_t size); -void kasan_unpoison_task_stack(struct task_struct *task); - void kasan_alloc_pages(struct page *page, unsigned int order); void kasan_free_pages(struct page *page, unsigned int order); @@ -122,8 +120,6 @@ void kasan_restore_multi_shot(bool enabled); static inline void kasan_unpoison_range(const void *address, size_t size) {} -static inline void kasan_unpoison_task_stack(struct task_struct *task) {} - static inline void kasan_alloc_pages(struct page *page, unsigned int order) {} static inline void kasan_free_pages(struct page *page, unsigned int order) {} @@ -175,6 +171,12 @@ static inline size_t kasan_metadata_size(struct kmem_cache *cache) { return 0; } #endif /* CONFIG_KASAN */ +#if defined(CONFIG_KASAN) && CONFIG_KASAN_STACK +void kasan_unpoison_task_stack(struct task_struct *task); +#else +static inline void kasan_unpoison_task_stack(struct task_struct *task) {} +#endif + #ifdef CONFIG_KASAN_GENERIC void kasan_cache_shrink(struct kmem_cache *cache); diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 0a420f1dbc54..7648a2452a01 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -64,6 +64,7 @@ void kasan_unpoison_range(const void *address, size_t size) unpoison_range(address, size); } +#if CONFIG_KASAN_STACK static void __kasan_unpoison_stack(struct task_struct *task, const void *sp) { void *base = task_stack_page(task); @@ -90,6 +91,7 @@ asmlinkage void kasan_unpoison_task_stack_below(const void *watermark) unpoison_range(base, watermark - base); } +#endif /* CONFIG_KASAN_STACK */ void kasan_alloc_pages(struct page *page, unsigned int order) { From patchwork Mon Nov 23 20:14:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11926663 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0BEF0C2D0E4 for ; Mon, 23 Nov 2020 20:33:02 +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 8BBC820715 for ; Mon, 23 Nov 2020 20:33:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="2u1NWgU3"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="ftOluYgs" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8BBC820715 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+linux-arm-kernel=archiver.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=FAWtBIcZQe1EpqgVX0g0xfsA3Xas40URASIiaiJNWsQ=; b=2u1NWgU3bCR4c+qkZGrbo+PvZ tNBFFRx9AiXubzgZU7widaOxJuk8CFeOFTo3LITtMRLdyTjoKas3yID2Y5D9wgJnbqp9jo/IjfPOx ExU7W1fkef3nekdaCtg//pueZFrIa0XKptrezUWwM1ra5ZiPNzWIFEOx6GvRPI1cCsu57Rsy2nRxz LqKvTI4byVaDh/Y7e/DT8TTw9otGmqhHKtYevezzxdJc/8a2XLO5Ql/2KRK7H4gFDTSG/dzsZ4tWX tuFSQjTDz5qJodpQIbkDyJ7PvUxoV5td3FMSrdS/jkef+SpX4zCG/SJ+2sXwEu4WCNGdifQLC1mtL OBt9PLTNQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIVP-0001L0-3w; Mon, 23 Nov 2020 20:32:11 +0000 Received: from mail-qk1-x74a.google.com ([2607:f8b0:4864:20::74a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIEz-0002B1-0Q for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2020 20:15:17 +0000 Received: by mail-qk1-x74a.google.com with SMTP id v134so15527081qka.19 for ; Mon, 23 Nov 2020 12:15:06 -0800 (PST) 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=01BW1GkidBPog12oysmILVzISd/+h9nT3tAZwCe3eCQ=; b=ftOluYgsoGAOE5Ye/to9lLng+2ouMijOYaYtwma2Ox9E53wFC3jC7Nqa0GnHSc266v 7venxL4adfRnnuzv07o06M9sPHJt+dDW40FZqv8UC20VDOUHQgD11io/dJVACWzd5Crp NyCk5K3h5KXsbQg+rRlQ0KFgtBFOS94A1KVMBNcjTIUeRCkb113dfiZjpB1xcq3rtsuB zkGdOifa55a0nfyRYqdixyGXB6OXKvBSZu5bw11Vg4HhJQoZ7veWEiiF3/bcJyIsl+06 NXpZUiOOOis3fhzxBKjaSCZNXCdhA3reqMwAszBN4vudp7UH4LMtCP4gOnylYl/ep3ys oIDg== 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=01BW1GkidBPog12oysmILVzISd/+h9nT3tAZwCe3eCQ=; b=r0tJN6Mqp+J75sO15KR1IpkYbotDnWQcYi1bHlarCoCl3hKPEzyhkx+eU41NhSgLZw JJQ9bFW4rHf7EmlnwdFXh9yzISeM2OweV06iBMKaA8aYFhQTG6yOImVmpnBkDmFD2mrX FeqrxCqrHQgChT08Gohvlav5BIPokgGTsX74ArEuGrk5YLGtdU/ccGIEACWNlA8LD9vf 5RFD638n511+32wLRwbt3YjrIGhLaIR2hU54QF3kSCrl1TMNkJNAKR3fEx+SvB6mTBoR UQLJRCj0Tkw3HlH92fLyfzwjcZZ/3+VOIQHGCQvHlOEVPCOn4h61qwfdUgevQLSJH8Zm 7L6A== X-Gm-Message-State: AOAM531iSXPGv8eRPO0U0FCOntXmqM9K7rjtKGoMq3rxwfYmuaULJwlL GZdtiIf/kD/G+SxgPoeUkmDq4uQASi5QCUiz X-Google-Smtp-Source: ABdhPJxJLu3lTiGvBa9uPDvK6XDnw+JLdTht9mXTq7OHyNsPd/2Yeymonl71MNmRULVBzyGWvGUs9Gqp+tGli6N/ X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a0c:804a:: with SMTP id 68mr1169751qva.1.1606162505149; Mon, 23 Nov 2020 12:15:05 -0800 (PST) Date: Mon, 23 Nov 2020 21:14:35 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH mm v4 05/19] kasan: allow VMAP_STACK for HW_TAGS mode From: Andrey Konovalov To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201123_151513_792340_1C18DAA0 X-CRM114-Status: GOOD ( 12.88 ) 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-arm-kernel@lists.infradead.org, Marco Elver , Catalin Marinas , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Konovalov , Andrey Ryabinin , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Even though hardware tag-based mode currently doesn't support checking vmalloc allocations, it doesn't use shadow memory and works with VMAP_STACK as is. Change VMAP_STACK definition accordingly. Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver Acked-by: Catalin Marinas Reviewed-by: Dmitry Vyukov Link: https://linux-review.googlesource.com/id/I3552cbc12321dec82cd7372676e9372a2eb452ac --- arch/Kconfig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index 762096e4ec16..6092102b29e9 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -955,16 +955,16 @@ config VMAP_STACK default y bool "Use a virtually-mapped stack" depends on HAVE_ARCH_VMAP_STACK - depends on !KASAN || KASAN_VMALLOC + depends on !KASAN || KASAN_HW_TAGS || KASAN_VMALLOC help Enable this if you want the use virtually-mapped kernel stacks with guard pages. This causes kernel stack overflows to be caught immediately rather than causing difficult-to-diagnose corruption. - To use this with KASAN, the architecture must support backing - virtual mappings with real shadow memory, and KASAN_VMALLOC must - be enabled. + To use this with software KASAN modes, the architecture must support + backing virtual mappings with real shadow memory, and KASAN_VMALLOC + must be enabled. config ARCH_OPTIONAL_KERNEL_RWX def_bool n From patchwork Mon Nov 23 20:14:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11926669 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93523C388F9 for ; Mon, 23 Nov 2020 20:34:35 +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 24F2120715 for ; Mon, 23 Nov 2020 20:34:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="2D7UxuZG"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="mg4G1Did" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 24F2120715 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+linux-arm-kernel=archiver.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=T+kV42lKjdR38tXXZhfLR+d6xhOLZrNV2VYfxCoZl6A=; b=2D7UxuZGJWVh3JfQRzIs6rbEs pM2xTxcRxt9X3x79mfThU6dx0HwVciVGaxGbpXdKzt70D9WVMJHfDNn/KeaLfOEoGrzKRvs2qdWhX DFo1WA7wk3bkmCXasdGEbGc58puTrW5eRaBULzp1HT4vYzmxLiDD/0cNnBuHXHEyLSohJDWrY985L EXfYySDxi3plTeoQW9XRoGczlNPslDjVOD5zhKhnma4Hf7kliFjibm54rJscvjpa+BI9SrWUGsSR9 9gOq9sHTKy73K+5w/6FS1LaSQBTwboFBxc1ic2uWhpVCiUCd9cI2wBqGgJS2X2vCfqs59xlywci9+ dYJ3Ag0Wg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIVs-0001Sa-UQ; Mon, 23 Nov 2020 20:32:41 +0000 Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIF5-0002CX-0Z for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2020 20:15:31 +0000 Received: by mail-wm1-x349.google.com with SMTP id c131so167984wma.0 for ; Mon, 23 Nov 2020 12:15:10 -0800 (PST) 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=p36dbwqSBkDo+5S2cwk7w2vFpTiM3nymWvjDRmhBFUI=; b=mg4G1DidJDofLGHNEBS3YNNpngVUCVymP5RWXDDdw2uRs9rVTEIaudcIuGM5F2q3L6 9Z/syptAsR65gevgGC7vb22jdpSpm8g2/OW2ZOv1TZ8ZvhRbz+eCh8+IZlSsYvvoSEaY KmtODUBNRhwsiEkBrfxHvAbyW7zWsjL/jwTAXPHFYAnzD1KOcF2q0gADTK7rF9nFZ+jO eOckU8kstaGbsmTJEnIYdXYtBuw6W4CSugEN2FyQtnaWvOQo7rNh2FHuR2TdgNawAkcz Xd/a751+eSOv37jt6hmeRkX2yJmLePmHNofrgvw4sRG3ClS9Zjoqb5Og50/dgojj1XOP Mbtw== 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=p36dbwqSBkDo+5S2cwk7w2vFpTiM3nymWvjDRmhBFUI=; b=i2+KcBjON1HnSAbOlBKUheOBrddpBqVEkBUoneOcnCXvfuJ/OsoQl8e0pTN6NVwxDQ +R1E3274/aNoWQA+0sJXKsXKgzzmyfuHSmUk+1c1JG2ctQgxif9wnwXPEVrCQmceKP2i VR89UyALWGQV3oQb9f3Dns9Z1v0cFYA6hGRBHKuOH3Wjgaif7sNE1BtL25NJrj4kSppH ktK/jz/JKanzaDlNca5+QP90PPM6bUh59rvQNywJh3KRp2dJyNd0ggfBPVKy3L7kX3Be LmAMxL9ThSFVELpyc5bJy7BgQYpjlhjJMpdynO1NZ5+7VlPK5KHnbWY981xaBHmUCQrL dQZA== X-Gm-Message-State: AOAM532ym6n5Kdweeba5ukrqdmc7YKIMpNk35jVgmjbeCoQJywWmsqYe 8xCSjr59mKp9ngu3PPAO/mpDqUE70vmvBkcA X-Google-Smtp-Source: ABdhPJx/wpDE4yzZ0h+S0RGgypb3BniYNtoFo8y6Vex4DrXhWizpWxJCeQcvoYWSbeyWzTWTt6szgogxteJ0R7Gh X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:9d4c:: with SMTP id g73mr17209wme.127.1606162507547; Mon, 23 Nov 2020 12:15:07 -0800 (PST) Date: Mon, 23 Nov 2020 21:14:36 +0100 In-Reply-To: Message-Id: <93e78948704a42ea92f6248ff8a725613d721161.1606162397.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH mm v4 06/19] kasan: remove __kasan_unpoison_stack From: Andrey Konovalov To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201123_151519_188387_94566BF0 X-CRM114-Status: GOOD ( 12.67 ) 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-arm-kernel@lists.infradead.org, Marco Elver , Catalin Marinas , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Konovalov , Andrey Ryabinin , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org There's no need for __kasan_unpoison_stack() helper, as it's only currently used in a single place. Removing it also removes unneeded arithmetic. No functional changes. Signed-off-by: Andrey Konovalov Reviewed-by: Dmitry Vyukov Reviewed-by: Marco Elver Link: https://linux-review.googlesource.com/id/Ie5ba549d445292fe629b4a96735e4034957bcc50 --- mm/kasan/common.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 7648a2452a01..fabd843eff3d 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -65,18 +65,12 @@ void kasan_unpoison_range(const void *address, size_t size) } #if CONFIG_KASAN_STACK -static void __kasan_unpoison_stack(struct task_struct *task, const void *sp) -{ - void *base = task_stack_page(task); - size_t size = sp - base; - - unpoison_range(base, size); -} - /* Unpoison the entire stack for a task. */ void kasan_unpoison_task_stack(struct task_struct *task) { - __kasan_unpoison_stack(task, task_stack_page(task) + THREAD_SIZE); + void *base = task_stack_page(task); + + unpoison_range(base, THREAD_SIZE); } /* Unpoison the stack for the current task beyond a watermark sp value. */ From patchwork Mon Nov 23 20:14:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11926673 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73ECFC63697 for ; Mon, 23 Nov 2020 20:35:15 +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 E31CA20721 for ; Mon, 23 Nov 2020 20:35:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="0xtu6BIf"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="ToUXDya0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E31CA20721 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+linux-arm-kernel=archiver.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=vhA/+f5SjuerR5PLzvqKL0iSdGU2bZ2yUPiKwyLO+Rc=; b=0xtu6BIfJWopX5hFolKHRjamX qCNi3WANDWiRpon2qx5g8sqdfHy94OfxwWXOm9++KCeC32zcJs0NNzlwGmZf6UBn2PpxjaDfAgV8d /+1jeyffexheflLk0b8BMQD6T785vwhkzssg7ROPSkPF7kDlvganATC/MNF+8Dc5lsoUFFkZIMYtJ dKVwg/ZJ4zm6tPeeQ4y6w0J80gaafyM8XWjkurHAhhFGErR/GDeANtgcyYoXlm8KFqBSXvoH1ccP+ 3Nx78ycIeHFPasiqgzw3LhgzI1ESb3IxaGyxYC3DsidJDeFOkF5lIk4gqHeAVziHQG13R5l7GYSt9 ReP5b4Wug==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIWg-0001nh-56; Mon, 23 Nov 2020 20:33:30 +0000 Received: from mail-qt1-x84a.google.com ([2607:f8b0:4864:20::84a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIF5-0002E7-26 for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2020 20:15:37 +0000 Received: by mail-qt1-x84a.google.com with SMTP id g12so14477180qtc.15 for ; Mon, 23 Nov 2020 12:15:11 -0800 (PST) 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=DkuzKfuS0My7aCtgOtfSEaKr7eC5T05KZFHiwPwDzrY=; b=ToUXDya0nLU8gLVsaoWMwWeuVDV42s0URz32+cStwWamBn3nVABOwknLOKc0eY/8zg 6GlTKnsFMa6kiCZKIOwsvo8+KfSsygd2LT04u2V/ze9fXFttvmlJJVd9MARC1LKLBDP8 8TodHuqYC9Ws5w8jQSN0i2U/vvz5mRpRve1wrH7FUpcf4EO8pOOSGl2zpb75QZEubBp5 NIN0Emgd5TuUTPKsUqNYZGAaXQGqeF9MiGA4rHstnCf+gPE4L2pZDXcXvi2Wjpy9UOPe WutM60Bo+S3dwHLHAU2ZGZuptnXh5fkOUbcH3TnrHdJtyY1YqWBHrKmdFV9MO3OZYUv8 7dng== 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=DkuzKfuS0My7aCtgOtfSEaKr7eC5T05KZFHiwPwDzrY=; b=jUi45TpcuyCNqwrYLimsOw+RJFo6jKIn/Y6/ppFbXYuQ1rr3bi1ZymfpQnAvHLLb0p sXhfFVCzmUOqaAMvMMfQHs9VCJa5iSpXdT+jI96ljy0GX3iFqLctitTNfGyyyBLvOEVR vyBv7IkeqaiQ4uarKspNnEPpTIj8qSkSzlhP8kOEP3n6AwSBfzI2ZaGiy3OihKAwC9HW hz3dsv0tcMqWXoAQv45bltZGCvgkhStUg3FRutmwxH1YIQhsGtu+/5XV0eRD+ZX0m0tk T+v1vZNtHVA60kYxEL2ZmafkfxSjqncnwP1F2ZDNOLHhikU0pzbpxuWNhk/Z9cybUFSc 7drg== X-Gm-Message-State: AOAM533cc7EUN3JZxsA2dzGUYZE1+dNwTlEV36YlzMPJ7RN1Les9wbsb QMpkg4j/j+kwivEHzGFs8u08x5b3VOr6T2lv X-Google-Smtp-Source: ABdhPJxjsvWA44pgvaeumd/Qxz2hCP9QwurD7nG6uOSBniAlYdv0kDnDg9wpMuPuLSGr28gkQ6eWemi0uBu0w96F X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:450e:: with SMTP id k14mr1203920qvu.28.1606162510024; Mon, 23 Nov 2020 12:15:10 -0800 (PST) Date: Mon, 23 Nov 2020 21:14:37 +0100 In-Reply-To: Message-Id: <6940383a3a9dfb416134d338d8fac97a9ebb8686.1606162397.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH mm v4 07/19] kasan: inline kasan_reset_tag for tag-based modes From: Andrey Konovalov To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201123_151519_456956_8B96440D X-CRM114-Status: GOOD ( 17.94 ) 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-arm-kernel@lists.infradead.org, Marco Elver , Catalin Marinas , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Konovalov , Andrey Ryabinin , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Using kasan_reset_tag() currently results in a function call. As it's called quite often from the allocator code, this leads to a noticeable slowdown. Move it to include/linux/kasan.h and turn it into a static inline function. Also remove the now unneeded reset_tag() internal KASAN macro and use kasan_reset_tag() instead. Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver Reviewed-by: Dmitry Vyukov Link: https://linux-review.googlesource.com/id/I4d2061acfe91d480a75df00b07c22d8494ef14b5 --- include/linux/kasan.h | 5 ++++- mm/kasan/common.c | 6 +++--- mm/kasan/hw_tags.c | 9 ++------- mm/kasan/kasan.h | 4 ---- mm/kasan/report.c | 4 ++-- mm/kasan/report_hw_tags.c | 2 +- mm/kasan/report_sw_tags.c | 4 ++-- mm/kasan/shadow.c | 4 ++-- mm/kasan/sw_tags.c | 9 ++------- 9 files changed, 18 insertions(+), 29 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index f2109bf0c5f9..1594177f86bb 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -193,7 +193,10 @@ static inline void kasan_record_aux_stack(void *ptr) {} #if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS) -void *kasan_reset_tag(const void *addr); +static inline void *kasan_reset_tag(const void *addr) +{ + return (void *)arch_kasan_reset_tag(addr); +} bool kasan_report(unsigned long addr, size_t size, bool is_write, unsigned long ip); diff --git a/mm/kasan/common.c b/mm/kasan/common.c index fabd843eff3d..1ac4f435c679 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -180,14 +180,14 @@ size_t kasan_metadata_size(struct kmem_cache *cache) struct kasan_alloc_meta *kasan_get_alloc_meta(struct kmem_cache *cache, const void *object) { - return (void *)reset_tag(object) + cache->kasan_info.alloc_meta_offset; + return kasan_reset_tag(object) + cache->kasan_info.alloc_meta_offset; } struct kasan_free_meta *kasan_get_free_meta(struct kmem_cache *cache, const void *object) { BUILD_BUG_ON(sizeof(struct kasan_free_meta) > 32); - return (void *)reset_tag(object) + cache->kasan_info.free_meta_offset; + return kasan_reset_tag(object) + cache->kasan_info.free_meta_offset; } void kasan_poison_slab(struct page *page) @@ -284,7 +284,7 @@ static bool __kasan_slab_free(struct kmem_cache *cache, void *object, tag = get_tag(object); tagged_object = object; - object = reset_tag(object); + object = kasan_reset_tag(object); if (is_kfence_address(object)) return false; diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c index 68e77363e58b..a34476764f1d 100644 --- a/mm/kasan/hw_tags.c +++ b/mm/kasan/hw_tags.c @@ -31,18 +31,13 @@ void __init kasan_init_hw_tags(void) pr_info("KernelAddressSanitizer initialized\n"); } -void *kasan_reset_tag(const void *addr) -{ - return reset_tag(addr); -} - void poison_range(const void *address, size_t size, u8 value) { /* Skip KFENCE memory if called explicitly outside of sl*b. */ if (is_kfence_address(address)) return; - hw_set_mem_tag_range(reset_tag(address), + hw_set_mem_tag_range(kasan_reset_tag(address), round_up(size, KASAN_GRANULE_SIZE), value); } @@ -52,7 +47,7 @@ void unpoison_range(const void *address, size_t size) if (is_kfence_address(address)) return; - hw_set_mem_tag_range(reset_tag(address), + hw_set_mem_tag_range(kasan_reset_tag(address), round_up(size, KASAN_GRANULE_SIZE), get_tag(address)); } diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 0eab7e4cecb8..5e8cd2080369 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -248,15 +248,11 @@ static inline const void *arch_kasan_set_tag(const void *addr, u8 tag) return addr; } #endif -#ifndef arch_kasan_reset_tag -#define arch_kasan_reset_tag(addr) ((void *)(addr)) -#endif #ifndef arch_kasan_get_tag #define arch_kasan_get_tag(addr) 0 #endif #define set_tag(addr, tag) ((void *)arch_kasan_set_tag((addr), (tag))) -#define reset_tag(addr) ((void *)arch_kasan_reset_tag(addr)) #define get_tag(addr) arch_kasan_get_tag(addr) #ifdef CONFIG_KASAN_HW_TAGS diff --git a/mm/kasan/report.c b/mm/kasan/report.c index df16bef0d810..76a0e3ae2049 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -328,7 +328,7 @@ void kasan_report_invalid_free(void *object, unsigned long ip) unsigned long flags; u8 tag = get_tag(object); - object = reset_tag(object); + object = kasan_reset_tag(object); #if IS_ENABLED(CONFIG_KUNIT) if (current->kunit_test) @@ -361,7 +361,7 @@ static void __kasan_report(unsigned long addr, size_t size, bool is_write, disable_trace_on_warning(); tagged_addr = (void *)addr; - untagged_addr = reset_tag(tagged_addr); + untagged_addr = kasan_reset_tag(tagged_addr); info.access_addr = tagged_addr; if (addr_has_metadata(untagged_addr)) diff --git a/mm/kasan/report_hw_tags.c b/mm/kasan/report_hw_tags.c index da543eb832cd..57114f0e14d1 100644 --- a/mm/kasan/report_hw_tags.c +++ b/mm/kasan/report_hw_tags.c @@ -22,7 +22,7 @@ const char *get_bug_type(struct kasan_access_info *info) void *find_first_bad_addr(void *addr, size_t size) { - return reset_tag(addr); + return kasan_reset_tag(addr); } void metadata_fetch_row(char *buffer, void *row) diff --git a/mm/kasan/report_sw_tags.c b/mm/kasan/report_sw_tags.c index 317100fd95b9..7604b46239d4 100644 --- a/mm/kasan/report_sw_tags.c +++ b/mm/kasan/report_sw_tags.c @@ -41,7 +41,7 @@ const char *get_bug_type(struct kasan_access_info *info) int i; tag = get_tag(info->access_addr); - addr = reset_tag(info->access_addr); + addr = kasan_reset_tag(info->access_addr); page = kasan_addr_to_page(addr); if (page && PageSlab(page)) { cache = page->slab_cache; @@ -72,7 +72,7 @@ const char *get_bug_type(struct kasan_access_info *info) void *find_first_bad_addr(void *addr, size_t size) { u8 tag = get_tag(addr); - void *p = reset_tag(addr); + void *p = kasan_reset_tag(addr); void *end = p + size; while (p < end && tag == *(u8 *)kasan_mem_to_shadow(p)) diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c index d8a122f887a0..37153bd1c126 100644 --- a/mm/kasan/shadow.c +++ b/mm/kasan/shadow.c @@ -82,7 +82,7 @@ void poison_range(const void *address, size_t size, u8 value) * some of the callers (e.g. kasan_poison_object_data) pass tagged * addresses to this function. */ - address = reset_tag(address); + address = kasan_reset_tag(address); /* Skip KFENCE memory if called explicitly outside of sl*b. */ if (is_kfence_address(address)) @@ -103,7 +103,7 @@ void unpoison_range(const void *address, size_t size) * some of the callers (e.g. kasan_unpoison_object_data) pass tagged * addresses to this function. */ - address = reset_tag(address); + address = kasan_reset_tag(address); /* * Skip KFENCE memory if called explicitly outside of sl*b. Also note diff --git a/mm/kasan/sw_tags.c b/mm/kasan/sw_tags.c index 6d7648cc3b98..e17de2619bbf 100644 --- a/mm/kasan/sw_tags.c +++ b/mm/kasan/sw_tags.c @@ -67,11 +67,6 @@ u8 random_tag(void) return (u8)(state % (KASAN_TAG_MAX + 1)); } -void *kasan_reset_tag(const void *addr) -{ - return reset_tag(addr); -} - bool check_memory_region(unsigned long addr, size_t size, bool write, unsigned long ret_ip) { @@ -107,7 +102,7 @@ bool check_memory_region(unsigned long addr, size_t size, bool write, if (tag == KASAN_TAG_KERNEL) return true; - untagged_addr = reset_tag((const void *)addr); + untagged_addr = kasan_reset_tag((const void *)addr); if (unlikely(untagged_addr < kasan_shadow_to_mem((void *)KASAN_SHADOW_START))) { return !kasan_report(addr, size, write, ret_ip); @@ -126,7 +121,7 @@ bool check_memory_region(unsigned long addr, size_t size, bool write, bool check_invalid_free(void *addr) { u8 tag = get_tag(addr); - u8 shadow_byte = READ_ONCE(*(u8 *)kasan_mem_to_shadow(reset_tag(addr))); + u8 shadow_byte = READ_ONCE(*(u8 *)kasan_mem_to_shadow(kasan_reset_tag(addr))); return (shadow_byte == KASAN_TAG_INVALID) || (tag != KASAN_TAG_KERNEL && tag != shadow_byte); From patchwork Mon Nov 23 20:14:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11926671 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0EBD8C63697 for ; Mon, 23 Nov 2020 20:35:08 +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 9C79120721 for ; Mon, 23 Nov 2020 20:35:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="DAku0S+P"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="nMsy4P1z" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9C79120721 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+linux-arm-kernel=archiver.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=oexkPbuFzxroGwCarqT+EaMvrjTTA9p5EJSWFjGoGLk=; b=DAku0S+P2ltZ1N4a6kqF3DdNg k7yqqNhAAJwASz+iSA8fNf2XYdh7K5/LXfkgUzznQ1f7EBjtG0Lh0pQ02t9dhfaJVLvU3sbxmA/t2 3oq2uTvYdiqUDJVLj0JtVnioM4FLOk/19iSGfUlTrrb2RpDAyEr0rUZ2nmi59XefHdx7QfeL0qxhH d/o/sWikmkd61upX3CFr3wOsJ/WJ1WCC7cnMXPCW4FlH83Ba5VOlcTmgAehcuzMLjV1VPdVTjWveO 4yNpiGgIWxJjlIDSwYhPbm4Zof9N91NIls3OZM9AVmVM+4ha9IftyXWmxkE2YOpGkL3BLuAxVoU8H L9JQZFuGA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIXf-0002Ic-Mo; Mon, 23 Nov 2020 20:34:31 +0000 Received: from mail-qv1-f73.google.com ([209.85.219.73]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIF7-0002EP-Mg for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2020 20:15:36 +0000 Received: by mail-qv1-f73.google.com with SMTP id v8so13698258qvq.12 for ; Mon, 23 Nov 2020 12:15:15 -0800 (PST) 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=+ebVro8WhZiLU99JJsnZ41QIjsbf3l1QeUgTEZT5fwM=; b=nMsy4P1zBhnUlJ7LXW5vgMe9VAoz/CbtlFUKrJKF1+LyFx3nO8IGDWAzkq6sCI3cyX 37cZ0AyhoIpiVPMTMdyIP8+n8+BQA57PTXiQxaqv1coMlGKSDmL5G0Bzu1IswwgHYRIF WL3uJIRxFuTlY8/s2i4hCvE/6Vy8uBi6lCrsVkIn8eAz6q3j1YzY9iX/JW8uCtCQyoOv 2fgfUu3tA1ooA7GWCT/E5nVFskmr0ABKzjIcPB/jQauVJM9VZ8rbHjYRd8eAchmaVMRZ kRtz9MnoLJ+37V9QrBxh8/aA/B7kZ8Cwx1WSfgMSxOgxMX4E7RLZx4vULPLNgYjMi0p6 nheA== 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=+ebVro8WhZiLU99JJsnZ41QIjsbf3l1QeUgTEZT5fwM=; b=YNSNFs0vJIoC1xAhfL6bst+dSh5hLfS6LJZxcrXE21/5WssT/IR8rGpmnRHrCfKKod e+SEl4hOC4zgVWokCAyeDJJHcnubraCFTGZX/xh1V/NYeMigxWp+V3KH2bdTnvcP0kf2 NnUFo23fxWg5LADGRqFXRaX97h+DbgGMAeFDho8vEngA3ypiq4fRtzlhDgqdz5kNjIqv m+/Gi3ouMrR9wuk9rKf1ZGxikQjRDavOMYYZBg650Mj2HmOemR8PijpvBSp60kExGzeq RhK+tg5aw7zgSVObS+YLj5dx8ORoYoCsbja/P5l1T3MXA8EK0qm1GDXS4CZc0v7Bg0n/ QJLg== X-Gm-Message-State: AOAM530oBdULHCU6ijQdNtDVVlMMfysJ9VDVP4+NekfPbQYZqYlPyN2P MpS89IAbaKnN9evQ4pZM1Afrip+Yw243wrep X-Google-Smtp-Source: ABdhPJz/EIT+p1GLjg2l1/jdNIDDxtLmLPSNqnUlEbXUIzj7/CSWJSG0+2TpsAC2+guYEI2P9bEmzgTPMtEAhQTQ X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a05:6214:aab:: with SMTP id ew11mr1176833qvb.4.1606162512301; Mon, 23 Nov 2020 12:15:12 -0800 (PST) Date: Mon, 23 Nov 2020 21:14:38 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH mm v4 08/19] kasan: inline random_tag for HW_TAGS From: Andrey Konovalov To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201123_151522_310746_313B832A X-CRM114-Status: GOOD ( 14.58 ) 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-arm-kernel@lists.infradead.org, Marco Elver , Catalin Marinas , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Konovalov , Andrey Ryabinin , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Using random_tag() currently results in a function call. Move its definition to mm/kasan/kasan.h and turn it into a static inline function for hardware tag-based mode to avoid uneeded function calls. Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver Reviewed-by: Dmitry Vyukov Link: https://linux-review.googlesource.com/id/Iac5b2faf9a912900e16cca6834d621f5d4abf427 --- mm/kasan/hw_tags.c | 5 ----- mm/kasan/kasan.h | 31 ++++++++++++++----------------- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c index a34476764f1d..3cdd87d189f6 100644 --- a/mm/kasan/hw_tags.c +++ b/mm/kasan/hw_tags.c @@ -51,11 +51,6 @@ void unpoison_range(const void *address, size_t size) round_up(size, KASAN_GRANULE_SIZE), get_tag(address)); } -u8 random_tag(void) -{ - return hw_get_random_tag(); -} - bool check_invalid_free(void *addr) { u8 ptr_tag = get_tag(addr); diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 5e8cd2080369..7876a2547b7d 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -190,6 +190,12 @@ static inline bool addr_has_metadata(const void *addr) #endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ +#if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS) +void print_tags(u8 addr_tag, const void *addr); +#else +static inline void print_tags(u8 addr_tag, const void *addr) { } +#endif + bool check_invalid_free(void *addr); void *find_first_bad_addr(void *addr, size_t size); @@ -225,23 +231,6 @@ static inline void quarantine_reduce(void) { } static inline void quarantine_remove_cache(struct kmem_cache *cache) { } #endif -#if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS) - -void print_tags(u8 addr_tag, const void *addr); - -u8 random_tag(void); - -#else - -static inline void print_tags(u8 addr_tag, const void *addr) { } - -static inline u8 random_tag(void) -{ - return 0; -} - -#endif - #ifndef arch_kasan_set_tag static inline const void *arch_kasan_set_tag(const void *addr, u8 tag) { @@ -281,6 +270,14 @@ static inline const void *arch_kasan_set_tag(const void *addr, u8 tag) #endif /* CONFIG_KASAN_HW_TAGS */ +#ifdef CONFIG_KASAN_SW_TAGS +u8 random_tag(void); +#elif defined(CONFIG_KASAN_HW_TAGS) +static inline u8 random_tag(void) { return hw_get_random_tag(); } +#else +static inline u8 random_tag(void) { return 0; } +#endif + /* * Exported functions for interfaces called from assembly or from generated * code. Declarations here to avoid warning about missing declarations. From patchwork Mon Nov 23 20:14:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11926693 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 353BBC388F9 for ; Mon, 23 Nov 2020 20:37:07 +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 85EE420715 for ; Mon, 23 Nov 2020 20:37:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="q2PAKfot"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="sEEd+SR5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 85EE420715 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+linux-arm-kernel=archiver.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=lfIKoMFdfjaQB8qvSmonxrnOkbGbM0rbEYhjZ7IMq/Y=; b=q2PAKfotw8lY5kjdXrutMaxZB dFVkkdveQqrfkUKDfpohqbl3EpbGYXevizC0W+Q6oGeQB7//dnLq9nQYeclKdwy24BCdailcZf7+p Fe1WmJueKQI7ksQESu4lyOK2MOHa8LaOvXN/X8B1XlfCsmBGuHUWFaBBzL4l4LgB5X4XFh+xDUlg9 53u9R9442YGYaPkf20ufeHLhzoiijZenRMX14Er2wnXDdH9Z9L+HJ1fbXo7ZDC6Bd98Xgn3DiQbcC z1rowrsruPmDq0LleoGLylTwpjK7O/esp0Xp56stChrekGTtP1PPsTrNQFSlhLlG4y6ICl27mIIGf X5vj8Fskw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIYO-0002d0-57; Mon, 23 Nov 2020 20:35:16 +0000 Received: from mail-qt1-x84a.google.com ([2607:f8b0:4864:20::84a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIFF-0002G3-Bk for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2020 20:15:43 +0000 Received: by mail-qt1-x84a.google.com with SMTP id t22so9792263qtq.2 for ; Mon, 23 Nov 2020 12:15:17 -0800 (PST) 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=NLiVUxn9nGZzjemtf3cQRZI6tHXp7YKQ8dqUNAbFdqU=; b=sEEd+SR5E0QujIT6LdTNMkP8lvByK/biZ74au0Czx9ejMJ7eteUUr04ivXsXnZo0g+ ATjcA39S/TY8d8NJxKDXQ1milDVgJmFjdelMKmd3E+kadIQWJxzBS/HP4OQn/3jV53EX zbtTSa1kT/UkktYPQ1CYBza1aMMLQSg3uRWLqRuPvi8Iq0z26TFAB3ZXNeF1Mu+LBYeo iAHQizMKbfGB75rv0K24dDQV7pzlIuD8FAttvqmJn27tLVdR7ewFAbw6w0P0VPS6I0vX dyjKhQWaiOUXrKBzq1gX3WWhDNtOnk2CyVHfR21g9XT+kNzCmuYSC4AQuXtmhHH+46yn Gylw== 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=NLiVUxn9nGZzjemtf3cQRZI6tHXp7YKQ8dqUNAbFdqU=; b=FvCF9P8kfsFVCr2LwQW/mcMWZyPVT6zUbu18YLOGu50JqdZuf8ENHDHHU/QYzJz6HJ 0TTxMgEZrgIFSrdvzizLKRNccloBFVjvroGiSfu5uUuRKbgskFl9rmOm+8hf84UcSN+Z eulha4MqONz6UePmxs2CCAxo+OUbleF/5aekW8T8u/EsYXIW0p65ICf8+JP9yKbq3dJZ XAuntdf12ksV6FjIzn8p40ShhX1Ss6TDuFlCUxrQpv5klkE6GCnSyJXmsc1PCL+a1OXj nG7uXr9J6HpiUvitEcpj5sQCmRqJ+dUZAw0ro9Q2/4/6lx6Sr+RJoSjCK2DRnvbOpsE8 dliQ== X-Gm-Message-State: AOAM5306ilSKTEEXX+G2YIQG7+zLYhuH/SGs1id8C+hvopvB0ah9moEW LE2z89/81Wj9TtfA/X67/GJQub5dd5alpAEW X-Google-Smtp-Source: ABdhPJxOc7uK81qXmguJVdi7tYU8ToxOxicUm1j1rL9VWGPliVVPXjfCwHBWb4jXxW7bR846SidQKgv2RVKPCxk+ X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:4a8a:: with SMTP id h10mr1086459qvx.55.1606162514671; Mon, 23 Nov 2020 12:15:14 -0800 (PST) Date: Mon, 23 Nov 2020 21:14:39 +0100 In-Reply-To: Message-Id: <131a6694a978a9a8b150187e539eecc8bcbf759b.1606162397.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH mm v4 09/19] kasan: open-code kasan_unpoison_slab From: Andrey Konovalov To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201123_151530_145189_FDEDEB52 X-CRM114-Status: GOOD ( 14.55 ) 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-arm-kernel@lists.infradead.org, Marco Elver , Catalin Marinas , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Konovalov , Andrey Ryabinin , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org There's the external annotation kasan_unpoison_slab() that is currently defined as static inline and uses kasan_unpoison_range(). Open-code this function in mempool.c. Otherwise with an upcoming change this function will result in an unnecessary function call. Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver Link: https://linux-review.googlesource.com/id/Ia7c8b659f79209935cbaab3913bf7f082cc43a0e --- include/linux/kasan.h | 6 ------ mm/mempool.c | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 1594177f86bb..872bf145ddde 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -106,11 +106,6 @@ struct kasan_cache { int free_meta_offset; }; -size_t __ksize(const void *); -static inline void kasan_unpoison_slab(const void *ptr) -{ - kasan_unpoison_range(ptr, __ksize(ptr)); -} size_t kasan_metadata_size(struct kmem_cache *cache); bool kasan_save_enable_multi_shot(void); @@ -166,7 +161,6 @@ static inline bool kasan_slab_free(struct kmem_cache *s, void *object, return false; } -static inline void kasan_unpoison_slab(const void *ptr) { } static inline size_t kasan_metadata_size(struct kmem_cache *cache) { return 0; } #endif /* CONFIG_KASAN */ diff --git a/mm/mempool.c b/mm/mempool.c index f473cdddaff0..583a9865b181 100644 --- a/mm/mempool.c +++ b/mm/mempool.c @@ -112,7 +112,7 @@ static __always_inline void kasan_poison_element(mempool_t *pool, void *element) static void kasan_unpoison_element(mempool_t *pool, void *element) { if (pool->alloc == mempool_alloc_slab || pool->alloc == mempool_kmalloc) - kasan_unpoison_slab(element); + kasan_unpoison_range(element, __ksize(element)); else if (pool->alloc == mempool_alloc_pages) kasan_alloc_pages(element, (unsigned long)pool->pool_data); } From patchwork Mon Nov 23 20:14:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11926677 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70EB1C2D0E4 for ; Mon, 23 Nov 2020 20:35:37 +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 EEA2320715 for ; Mon, 23 Nov 2020 20:35:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Om28kFj3"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="Xdpxb1Vf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EEA2320715 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+linux-arm-kernel=archiver.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=lCq6GnRY3F53jm8I1QbX9RBjhYJWpAkeeDOxsJ1IhuY=; b=Om28kFj3LZJAbtw0Zj9je8sT+ 4pO80qbztcQDTVbi6NPQ7mr/MoWtSP8pJTw4EOZlf9RrSFgcN0m4O8g58CAWxjEQo4WRDVe/k3eGi XBJ60gu5ORQVPa4AkzTH9xgxD/4vnPcLCNuMcEFU1Urs62d7PA7EbTmtWr7dwEMw6PMnz1GqBCXtm YDO6Ulnqc4tM9b/Q71gDh+MvdeFEEOmYqetOYw4gA7dfzRjgGn3nH0hsMYn8rzw7VYMQ9At4pQnA5 7MiWVCkV5d6KfnUK0o3BrYxLJZWOWlfXMRMN3lD2nt/FN/uC5FsS3XXkPlwGzGp7Z/oDT4BEJ3+Br knPCGNkzw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIXE-00025s-7g; Mon, 23 Nov 2020 20:34:04 +0000 Received: from mail-qv1-xf4a.google.com ([2607:f8b0:4864:20::f4a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIFB-0002Gi-VD for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2020 20:15:40 +0000 Received: by mail-qv1-xf4a.google.com with SMTP id cu18so13683699qvb.17 for ; Mon, 23 Nov 2020 12:15:19 -0800 (PST) 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=S3Qrn/dExjiymjsgYUNfOEnR/LmRZMAIXzYoVslXjjw=; b=Xdpxb1Vf3s/kPw2pHNSS9JiFvoC2ZXTVqLGV29CN101YnRfcUJj54e13O+4shFzNRR UxJOJrDwgBms68V+NwgrrY57TQLSJEvHK/P93J5NSj47DQVWAHehli8I2fKm+zJJPseI DL5ssg+ltuq7C1TTwAD2z1DpU/DJvdCdIOygSieLe91+DwvRmebsYMl4yr/oD38kVwwr 9rUFFMTvdMatQepRl0EqTXJ5CGN9B2lWsJ/P/3Hu1bfQydR3x3KE0ir05X90+OrKNFaU 9lVY0TxUO2ZPp+UK87A2vvY6Cj4xos035dsYERhzZ0F3VH109GzKqChJQihY3dhXwauS r94A== 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=S3Qrn/dExjiymjsgYUNfOEnR/LmRZMAIXzYoVslXjjw=; b=iwxNrBloPD1T4rx93U1Z9/cGnaNSDQpNSai6Tl96UR8j4++w7ixeZVGnlv1q4Dm/HJ EfGODQclLXbTvUfPTQrhHzkTfZOKQU0wNyHbaAXk699nSCtRHWuZ4pC1gHWaVI6yaykq rjqohfOTAIzqMEBGa2+WJX6WEhR50ucxNK43tfi54elQGmBhRrgDVwvfODzfSqQtoHR9 t7MGnO0e2il26eQB8L0c9KRUagJsuhXxECi0Akn7KPIONBMiR22jwcB2tIvjWl83CV4i gsjdgYbD04bnOsB7NwwuVPWjfMhnabcn51zW7v9tTYyRbqxuS8D8/af2BZM8xINXdo3v IEYQ== X-Gm-Message-State: AOAM533o30DkylggygzbPKKIMptC+tCzqLXsxhQesQWfjfCsVMZZxT1M hJQaz8l2XoUXT1t4PTxtvFcEcB4BLip6Z5tI X-Google-Smtp-Source: ABdhPJzP0MC5E8U031n1ajvN8bRvma1gdRfUKfjzvSoZePlaiwYB+rq0QqGVBK+BNceQRzCZ0IBw7rLdYKvu+Rd/ X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:470d:: with SMTP id k13mr1306441qvz.40.1606162517097; Mon, 23 Nov 2020 12:15:17 -0800 (PST) Date: Mon, 23 Nov 2020 21:14:40 +0100 In-Reply-To: Message-Id: <7007955b69eb31b5376a7dc1e0f4ac49138504f2.1606162397.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH mm v4 10/19] kasan: inline (un)poison_range and check_invalid_free From: Andrey Konovalov To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201123_151526_672856_1E46088E X-CRM114-Status: GOOD ( 17.18 ) 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-arm-kernel@lists.infradead.org, Marco Elver , Catalin Marinas , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Konovalov , Andrey Ryabinin , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Using (un)poison_range() or check_invalid_free() currently results in function calls. Move their definitions to mm/kasan/kasan.h and turn them into static inline functions for hardware tag-based mode to avoid unneeded function calls. Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver Link: https://linux-review.googlesource.com/id/Ia9d8191024a12d1374675b3d27197f10193f50bb --- mm/kasan/hw_tags.c | 30 ------------------------------ mm/kasan/kasan.h | 45 ++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 35 deletions(-) diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c index 3cdd87d189f6..863fed4edd3f 100644 --- a/mm/kasan/hw_tags.c +++ b/mm/kasan/hw_tags.c @@ -10,7 +10,6 @@ #include #include -#include #include #include #include @@ -31,35 +30,6 @@ void __init kasan_init_hw_tags(void) pr_info("KernelAddressSanitizer initialized\n"); } -void poison_range(const void *address, size_t size, u8 value) -{ - /* Skip KFENCE memory if called explicitly outside of sl*b. */ - if (is_kfence_address(address)) - return; - - hw_set_mem_tag_range(kasan_reset_tag(address), - round_up(size, KASAN_GRANULE_SIZE), value); -} - -void unpoison_range(const void *address, size_t size) -{ - /* Skip KFENCE memory if called explicitly outside of sl*b. */ - if (is_kfence_address(address)) - return; - - hw_set_mem_tag_range(kasan_reset_tag(address), - round_up(size, KASAN_GRANULE_SIZE), get_tag(address)); -} - -bool check_invalid_free(void *addr) -{ - u8 ptr_tag = get_tag(addr); - u8 mem_tag = hw_get_mem_tag(addr); - - return (mem_tag == KASAN_TAG_INVALID) || - (ptr_tag != KASAN_TAG_KERNEL && ptr_tag != mem_tag); -} - void kasan_set_free_info(struct kmem_cache *cache, void *object, u8 tag) { diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 7876a2547b7d..8aa83b7ad79e 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -3,6 +3,7 @@ #define __MM_KASAN_KASAN_H #include +#include #include #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) @@ -154,9 +155,6 @@ struct kasan_alloc_meta *kasan_get_alloc_meta(struct kmem_cache *cache, struct kasan_free_meta *kasan_get_free_meta(struct kmem_cache *cache, const void *object); -void poison_range(const void *address, size_t size, u8 value); -void unpoison_range(const void *address, size_t size); - #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) static inline const void *kasan_shadow_to_mem(const void *shadow_addr) @@ -196,8 +194,6 @@ void print_tags(u8 addr_tag, const void *addr); static inline void print_tags(u8 addr_tag, const void *addr) { } #endif -bool check_invalid_free(void *addr); - void *find_first_bad_addr(void *addr, size_t size); const char *get_bug_type(struct kasan_access_info *info); void metadata_fetch_row(char *buffer, void *row); @@ -278,6 +274,45 @@ static inline u8 random_tag(void) { return hw_get_random_tag(); } static inline u8 random_tag(void) { return 0; } #endif +#ifdef CONFIG_KASAN_HW_TAGS + +static inline void poison_range(const void *address, size_t size, u8 value) +{ + /* Skip KFENCE memory if called explicitly outside of sl*b. */ + if (is_kfence_address(address)) + return; + + hw_set_mem_tag_range(kasan_reset_tag(address), + round_up(size, KASAN_GRANULE_SIZE), value); +} + +static inline void unpoison_range(const void *address, size_t size) +{ + /* Skip KFENCE memory if called explicitly outside of sl*b. */ + if (is_kfence_address(address)) + return; + + hw_set_mem_tag_range(kasan_reset_tag(address), + round_up(size, KASAN_GRANULE_SIZE), get_tag(address)); +} + +static inline bool check_invalid_free(void *addr) +{ + u8 ptr_tag = get_tag(addr); + u8 mem_tag = hw_get_mem_tag(addr); + + return (mem_tag == KASAN_TAG_INVALID) || + (ptr_tag != KASAN_TAG_KERNEL && ptr_tag != mem_tag); +} + +#else /* CONFIG_KASAN_HW_TAGS */ + +void poison_range(const void *address, size_t size, u8 value); +void unpoison_range(const void *address, size_t size); +bool check_invalid_free(void *addr); + +#endif /* CONFIG_KASAN_HW_TAGS */ + /* * Exported functions for interfaces called from assembly or from generated * code. Declarations here to avoid warning about missing declarations. From patchwork Mon Nov 23 20:14:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11926675 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4792EC388F9 for ; Mon, 23 Nov 2020 20:35:29 +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 B3BB720715 for ; Mon, 23 Nov 2020 20:35:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="oa2qLJXI"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="GvA/EBeX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B3BB720715 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+linux-arm-kernel=archiver.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=5HmGlbvROrlYoZg4+8lvu3tx5Kk0spz9+XtZweLXsy0=; b=oa2qLJXIZgGGDwE/xMBLFjVIF b9/BQw3GhFFE/bIxnWyNqt52C1e67UocMWEW52Gzz9y5kReu13ejjSTtQV3eJ+DbIsnCAPpKMSwv4 yo6meHUJatLfpillMmQzyfzhm6VdfXMAIphjuRsmb9RyAc41+m921RvEt4dF4pCKnBxeyCOBCK4ON XnN30XaQKx3nD5xnp3VO8w41JOfUxH0DBqnbw8nhxWK7Tjzwz5IuWlydGDsbkVakQRRNPQdvmT29N fDCm0eW+HTP1VieAm/Bk1iz+wzDGhPsLZhHeY4MRv3t0EvbIobtOhBnVY9As6XIFfoPmUMaUZN98B vU9bnNkTw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIY0-0002St-6p; Mon, 23 Nov 2020 20:34:52 +0000 Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIFC-0002I8-Bw for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2020 20:15:42 +0000 Received: by mail-wm1-x34a.google.com with SMTP id o19so163414wme.2 for ; Mon, 23 Nov 2020 12:15:21 -0800 (PST) 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=jfEhV0tAQhE/zbKKPTCT6UIAQVQtbAcePK8Pzf7KaDc=; b=GvA/EBeXpISUQQVhjYHlsUjv/JDak79nQfzfvbc+M5c9T/dsf4680a8APmqsMLGafj p7nuxeZ28QFdTpZGfLpAOsVoCubT1PFYsepbLUwR6LXDW235BzSeXNYsNl2OfNgyBt08 lev0wm/2pftJkxcYrcsXjAz156X/g3OSLHNeXmOzcMUZrrQXUcQYzcmbtVmiqILtIu0N agbb+oKPO4oTBDSw3ahq8+CQ0Qega7w8eTLqVD1qjuQisczO27qgAZrvsB1kMY+OF73V gQhWCnU8XiIn2nvEXzeboLJn0ieHqEUgjFyLPRl1Gj8w085sVQdIB4ppdOLxzj0LheP0 FKow== 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=jfEhV0tAQhE/zbKKPTCT6UIAQVQtbAcePK8Pzf7KaDc=; b=ty3x07bIsSEAsCENDZQ+wKEGk0/TKeueEDgQDZrJ8azVSFGc0BN6Wym52mSD4eYiCR N+tdQE1thJVkt8NLp0Xz5stuiwJH1FIljSqbWJrMoe9t/9TUFvKMlx7Kvpmv5reUD2Gn fm7nmDD6l/JvyFsUMew7gcWdJ/HGkrBT7uq3iSnXv/OAop/rAm+xRAaHNj5lVJOwgz1G RKr9VMmIG3CkUm82IKOhM/oM1va0XOppWLeNwAjIOOnmr8UWBRenihQnUDXFoi50dmn9 j5io+0G53ebKWEsMJRfzCfuNo7cvVkXqRhsxZSSsysA4QB8Qc88rWl/tZ7OCgb8JsXVv 04kA== X-Gm-Message-State: AOAM530fWRL7uIEMb0QYL3D+TFhYtBiEiNpxMGotXrPEWcAnBM82oD4K Q1pZn88HGkIAiCU7lB8qa/JEGs+mq8Fj9rsz X-Google-Smtp-Source: ABdhPJygrgUVSwSuWEunXxfKsfeVNdRKIawcizZLcA4jf0vayzOsf1jr5u1nzP7zQ2/7fPEfLE+olHQfI+mhIamu X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:9901:: with SMTP id b1mr648770wme.18.1606162519408; Mon, 23 Nov 2020 12:15:19 -0800 (PST) Date: Mon, 23 Nov 2020 21:14:41 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH mm v4 11/19] kasan: add and integrate kasan boot parameters From: Andrey Konovalov To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201123_151526_989829_848F0179 X-CRM114-Status: GOOD ( 25.63 ) 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-arm-kernel@lists.infradead.org, Marco Elver , Catalin Marinas , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Konovalov , Andrey Ryabinin , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hardware tag-based KASAN mode is intended to eventually be used in production as a security mitigation. Therefore there's a need for finer control over KASAN features and for an existence of a kill switch. This change adds a few boot parameters for hardware tag-based KASAN that allow to disable or otherwise control particular KASAN features. The features that can be controlled are: 1. Whether KASAN is enabled at all. 2. Whether KASAN collects and saves alloc/free stacks. 3. Whether KASAN panics on a detected bug or not. With this change a new boot parameter kasan.mode allows to choose one of three main modes: - kasan.mode=off - KASAN is disabled, no tag checks are performed - kasan.mode=prod - only essential production features are enabled - kasan.mode=full - all KASAN features are enabled The chosen mode provides default control values for the features mentioned above. However it's also possible to override the default values by providing: - kasan.stacktrace=off/on - enable alloc/free stack collection (default: on for mode=full, otherwise off) - kasan.fault=report/panic - only report tag fault or also panic (default: report) If kasan.mode parameter is not provided, it defaults to full when CONFIG_DEBUG_KERNEL is enabled, and to prod otherwise. It is essential that switching between these modes doesn't require rebuilding the kernel with different configs, as this is required by the Android GKI (Generic Kernel Image) initiative [1]. [1] https://source.android.com/devices/architecture/kernel/generic-kernel-image Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver Reviewed-by: Dmitry Vyukov Link: https://linux-review.googlesource.com/id/If7d37003875b2ed3e0935702c8015c223d6416a4 --- mm/kasan/common.c | 22 +++++-- mm/kasan/hw_tags.c | 151 +++++++++++++++++++++++++++++++++++++++++++++ mm/kasan/kasan.h | 16 +++++ mm/kasan/report.c | 14 ++++- 4 files changed, 196 insertions(+), 7 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 1ac4f435c679..a11e3e75eb08 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -135,6 +135,11 @@ void kasan_cache_create(struct kmem_cache *cache, unsigned int *size, unsigned int redzone_size; int redzone_adjust; + if (!kasan_stack_collection_enabled()) { + *flags |= SLAB_KASAN; + return; + } + /* Add alloc meta. */ cache->kasan_info.alloc_meta_offset = *size; *size += sizeof(struct kasan_alloc_meta); @@ -171,6 +176,8 @@ void kasan_cache_create(struct kmem_cache *cache, unsigned int *size, size_t kasan_metadata_size(struct kmem_cache *cache) { + if (!kasan_stack_collection_enabled()) + return 0; return (cache->kasan_info.alloc_meta_offset ? sizeof(struct kasan_alloc_meta) : 0) + (cache->kasan_info.free_meta_offset ? @@ -263,11 +270,13 @@ void * __must_check kasan_init_slab_obj(struct kmem_cache *cache, { struct kasan_alloc_meta *alloc_meta; - if (!(cache->flags & SLAB_KASAN)) - return (void *)object; + if (kasan_stack_collection_enabled()) { + if (!(cache->flags & SLAB_KASAN)) + return (void *)object; - alloc_meta = kasan_get_alloc_meta(cache, object); - __memset(alloc_meta, 0, sizeof(*alloc_meta)); + alloc_meta = kasan_get_alloc_meta(cache, object); + __memset(alloc_meta, 0, sizeof(*alloc_meta)); + } if (IS_ENABLED(CONFIG_KASAN_SW_TAGS) || IS_ENABLED(CONFIG_KASAN_HW_TAGS)) object = set_tag(object, assign_tag(cache, object, true, false)); @@ -307,6 +316,9 @@ static bool __kasan_slab_free(struct kmem_cache *cache, void *object, rounded_up_size = round_up(cache->object_size, KASAN_GRANULE_SIZE); poison_range(object, rounded_up_size, KASAN_KMALLOC_FREE); + if (!kasan_stack_collection_enabled()) + return false; + if ((IS_ENABLED(CONFIG_KASAN_GENERIC) && !quarantine) || unlikely(!(cache->flags & SLAB_KASAN))) return false; @@ -357,7 +369,7 @@ static void *__kasan_kmalloc(struct kmem_cache *cache, const void *object, poison_range((void *)redzone_start, redzone_end - redzone_start, KASAN_KMALLOC_REDZONE); - if (cache->flags & SLAB_KASAN) + if (kasan_stack_collection_enabled() && (cache->flags & SLAB_KASAN)) set_alloc_info(cache, (void *)object, flags); return set_tag(object, tag); diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c index 863fed4edd3f..30ce88935e9d 100644 --- a/mm/kasan/hw_tags.c +++ b/mm/kasan/hw_tags.c @@ -8,18 +8,115 @@ #define pr_fmt(fmt) "kasan: " fmt +#include #include #include #include #include +#include #include #include #include "kasan.h" +enum kasan_arg_mode { + KASAN_ARG_MODE_DEFAULT, + KASAN_ARG_MODE_OFF, + KASAN_ARG_MODE_PROD, + KASAN_ARG_MODE_FULL, +}; + +enum kasan_arg_stacktrace { + KASAN_ARG_STACKTRACE_DEFAULT, + KASAN_ARG_STACKTRACE_OFF, + KASAN_ARG_STACKTRACE_ON, +}; + +enum kasan_arg_fault { + KASAN_ARG_FAULT_DEFAULT, + KASAN_ARG_FAULT_REPORT, + KASAN_ARG_FAULT_PANIC, +}; + +static enum kasan_arg_mode kasan_arg_mode __ro_after_init; +static enum kasan_arg_stacktrace kasan_arg_stacktrace __ro_after_init; +static enum kasan_arg_fault kasan_arg_fault __ro_after_init; + +/* Whether KASAN is enabled at all. */ +DEFINE_STATIC_KEY_FALSE_RO(kasan_flag_enabled); +EXPORT_SYMBOL(kasan_flag_enabled); + +/* Whether to collect alloc/free stack traces. */ +DEFINE_STATIC_KEY_FALSE_RO(kasan_flag_stacktrace); + +/* Whether panic or disable tag checking on fault. */ +bool kasan_flag_panic __ro_after_init; + +/* kasan.mode=off/prod/full */ +static int __init early_kasan_mode(char *arg) +{ + if (!arg) + return -EINVAL; + + if (!strcmp(arg, "off")) + kasan_arg_mode = KASAN_ARG_MODE_OFF; + else if (!strcmp(arg, "prod")) + kasan_arg_mode = KASAN_ARG_MODE_PROD; + else if (!strcmp(arg, "full")) + kasan_arg_mode = KASAN_ARG_MODE_FULL; + else + return -EINVAL; + + return 0; +} +early_param("kasan.mode", early_kasan_mode); + +/* kasan.stack=off/on */ +static int __init early_kasan_flag_stacktrace(char *arg) +{ + if (!arg) + return -EINVAL; + + if (!strcmp(arg, "off")) + kasan_arg_stacktrace = KASAN_ARG_STACKTRACE_OFF; + else if (!strcmp(arg, "on")) + kasan_arg_stacktrace = KASAN_ARG_STACKTRACE_ON; + else + return -EINVAL; + + return 0; +} +early_param("kasan.stacktrace", early_kasan_flag_stacktrace); + +/* kasan.fault=report/panic */ +static int __init early_kasan_fault(char *arg) +{ + if (!arg) + return -EINVAL; + + if (!strcmp(arg, "report")) + kasan_arg_fault = KASAN_ARG_FAULT_REPORT; + else if (!strcmp(arg, "panic")) + kasan_arg_fault = KASAN_ARG_FAULT_PANIC; + else + return -EINVAL; + + return 0; +} +early_param("kasan.fault", early_kasan_fault); + /* kasan_init_hw_tags_cpu() is called for each CPU. */ void kasan_init_hw_tags_cpu(void) { + /* + * There's no need to check that the hardware is MTE-capable here, + * as this function is only called for MTE-capable hardware. + */ + + /* If KASAN is disabled, do nothing. */ + if (kasan_arg_mode == KASAN_ARG_MODE_OFF) + return; + hw_init_tags(KASAN_TAG_MAX); hw_enable_tagging(); } @@ -27,6 +124,60 @@ void kasan_init_hw_tags_cpu(void) /* kasan_init_hw_tags() is called once on boot CPU. */ void __init kasan_init_hw_tags(void) { + /* If hardware doesn't support MTE, do nothing. */ + if (!system_supports_mte()) + return; + + /* Choose KASAN mode if kasan boot parameter is not provided. */ + if (kasan_arg_mode == KASAN_ARG_MODE_DEFAULT) { + if (IS_ENABLED(CONFIG_DEBUG_KERNEL)) + kasan_arg_mode = KASAN_ARG_MODE_FULL; + else + kasan_arg_mode = KASAN_ARG_MODE_PROD; + } + + /* Preset parameter values based on the mode. */ + switch (kasan_arg_mode) { + case KASAN_ARG_MODE_DEFAULT: + /* Shouldn't happen as per the check above. */ + WARN_ON(1); + return; + case KASAN_ARG_MODE_OFF: + /* If KASAN is disabled, do nothing. */ + return; + case KASAN_ARG_MODE_PROD: + static_branch_enable(&kasan_flag_enabled); + break; + case KASAN_ARG_MODE_FULL: + static_branch_enable(&kasan_flag_enabled); + static_branch_enable(&kasan_flag_stacktrace); + break; + } + + /* Now, optionally override the presets. */ + + switch (kasan_arg_stacktrace) { + case KASAN_ARG_STACKTRACE_DEFAULT: + break; + case KASAN_ARG_STACKTRACE_OFF: + static_branch_disable(&kasan_flag_stacktrace); + break; + case KASAN_ARG_STACKTRACE_ON: + static_branch_enable(&kasan_flag_stacktrace); + break; + } + + switch (kasan_arg_fault) { + case KASAN_ARG_FAULT_DEFAULT: + break; + case KASAN_ARG_FAULT_REPORT: + kasan_flag_panic = false; + break; + case KASAN_ARG_FAULT_PANIC: + kasan_flag_panic = true; + break; + } + pr_info("KernelAddressSanitizer initialized\n"); } diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 8aa83b7ad79e..d01a5ac34f70 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -6,6 +6,22 @@ #include #include +#ifdef CONFIG_KASAN_HW_TAGS +#include +DECLARE_STATIC_KEY_FALSE(kasan_flag_stacktrace); +static inline bool kasan_stack_collection_enabled(void) +{ + return static_branch_unlikely(&kasan_flag_stacktrace); +} +#else +static inline bool kasan_stack_collection_enabled(void) +{ + return true; +} +#endif + +extern bool kasan_flag_panic __ro_after_init; + #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) #define KASAN_GRANULE_SIZE (1UL << KASAN_SHADOW_SCALE_SHIFT) #else diff --git a/mm/kasan/report.c b/mm/kasan/report.c index 76a0e3ae2049..ffa6076b1710 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -99,6 +99,10 @@ static void end_report(unsigned long *flags) panic_on_warn = 0; panic("panic_on_warn set ...\n"); } +#ifdef CONFIG_KASAN_HW_TAGS + if (kasan_flag_panic) + panic("kasan.fault=panic set ...\n"); +#endif kasan_enable_current(); } @@ -161,8 +165,8 @@ static void describe_object_addr(struct kmem_cache *cache, void *object, (void *)(object_addr + cache->object_size)); } -static void describe_object(struct kmem_cache *cache, void *object, - const void *addr, u8 tag) +static void describe_object_stacks(struct kmem_cache *cache, void *object, + const void *addr, u8 tag) { struct kasan_alloc_meta *alloc_meta = kasan_get_alloc_meta(cache, object); @@ -190,7 +194,13 @@ static void describe_object(struct kmem_cache *cache, void *object, } #endif } +} +static void describe_object(struct kmem_cache *cache, void *object, + const void *addr, u8 tag) +{ + if (kasan_stack_collection_enabled()) + describe_object_stacks(cache, object, addr, tag); describe_object_addr(cache, object, addr); } From patchwork Mon Nov 23 20:14:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11926695 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3ED8DC2D0E4 for ; Mon, 23 Nov 2020 20:37:16 +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 B614120715 for ; Mon, 23 Nov 2020 20:37:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="arUJ7Xt/"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="RnHQK3gT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B614120715 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+linux-arm-kernel=archiver.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=k23+ADP2zqwVLSvIegziRnRMT90vCq3o3JWYrGkBQZs=; b=arUJ7Xt/rFtAf8pGBDx37Mm9t Srx3KL77ap7TGjrzfVfy6UB+btakN5iaze6kxQpr6FJHGq6XXtoufE0UVBwonpa8E0EbtGJYvMxWX lR0Bo7WThd0DN+3MdeQyFLj2o5uih2bdtUy6roQxEQXd95BMAsQL/c6qsyCfgUr8rWIEpT2bTW+46 M4ynrjFQQsq21nMLQnAtJBo4Er0XFMjWFKAAcpQkEzN5GQZ3KsctLBtb9fpj8slB8FOPZLzHe+Zwh ioTUcdFuZl19iFEp8lVyop2G32FHzYpFA93T0xin2XsDzNb/sQ/30h5NxG/V3ZS9ujJXhWyA+B3tC xXhvaAwgA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIYS-0002h8-KB; Mon, 23 Nov 2020 20:35:20 +0000 Received: from mail-qv1-xf49.google.com ([2607:f8b0:4864:20::f49]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIFD-0002JN-5J for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2020 20:15:44 +0000 Received: by mail-qv1-xf49.google.com with SMTP id d41so13673366qvc.23 for ; Mon, 23 Nov 2020 12:15:24 -0800 (PST) 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=nlC0gdqYkTMGAEqxvmFcC299FPQJg14RB1uP6sPoMPA=; b=RnHQK3gTCXiYpPGmP3h1g96yT5JPN2+JeR4DUjGLGaoKelLmcSnHfnPu35mEcinQRe iCvSR01vkLFGejUJDCc7Kh4ACJMmCf5ow+0+bob+NA15Tt/knF/gH/I87wQ3nZwIBN+T ccpVZlCt1hdsO6ez8lgtl2rmSaJs+rdvLWEhrJJ+HYIBbpjGtNmvF286l5MbgRgoj+oJ qaWoli7HU9zHQADOSp6Oh23BqOp4v7XRBZsYfg6Sh7O6wxz000iaStfQKVUemxaYIZyk iRd5Psfkoh04c2uxEuSQG0pTukLWZRPzr2fpA+JztAtN0Z6gSZoORCeonNiDxDt8wYcy qMgw== 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=nlC0gdqYkTMGAEqxvmFcC299FPQJg14RB1uP6sPoMPA=; b=bH/0piYczK+ZWwIhdNXcB8+ZNL8LUFehOXlpKQowH5FVYBrzd0i6+fH+ctLJWM5KiD TdPeiYecGbu7GkU7JXKdgBEnjA69kILPiHZDmuQAwuzksCMUD0TKytI7zMMkymzw0P5G k8t8cpO/r7VWwYfhhnSbXS80v60suyEa4cx1y6JG4P5dnM4clpRSBfL+HbLfJA+gNRsv bRl6TNXgqTBe0aL/aNbgNlWGx0LmlU5dn4EfNuA0TCY1/NdLvynfpDQ9RlmJCrrwN1w+ PgYP/wRpJNvkNa4lEvMcKU5a2P2pJfw7Xf6ZlZgsHGy7X8JSSinvTxx5DkJG/DjwPJD2 dG2w== X-Gm-Message-State: AOAM531CPWnpxPl5gu7XdWqCJ3CP9o4gMJV2nTmSMMNSLlP95y3ABDkr QXaOxRknXUiJk4417fmod7eJ/qpv+AKDzpRZ X-Google-Smtp-Source: ABdhPJxCQ4MtTajGqDHJa1Kkz02gonMDqPUjMYoMA22YvP2PU7FW/RvQdDYCGHcur5SD6iBZVG4+ONkVaNM+face X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:4051:: with SMTP id r17mr1091487qvp.39.1606162521864; Mon, 23 Nov 2020 12:15:21 -0800 (PST) Date: Mon, 23 Nov 2020 21:14:42 +0100 In-Reply-To: Message-Id: <9f90e3c0aa840dbb4833367c2335193299f69023.1606162397.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH mm v4 12/19] kasan, mm: check kasan_enabled in annotations From: Andrey Konovalov To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201123_151528_717474_E3C94ABD X-CRM114-Status: GOOD ( 18.50 ) 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-arm-kernel@lists.infradead.org, Marco Elver , Catalin Marinas , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Konovalov , Andrey Ryabinin , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Declare the kasan_enabled static key in include/linux/kasan.h and in include/linux/mm.h and check it in all kasan annotations. This allows to avoid any slowdown caused by function calls when kasan_enabled is disabled. Co-developed-by: Vincenzo Frascino Signed-off-by: Vincenzo Frascino Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver Reviewed-by: Dmitry Vyukov Link: https://linux-review.googlesource.com/id/I2589451d3c96c97abbcbf714baabe6161c6f153e --- include/linux/kasan.h | 213 ++++++++++++++++++++++++++++++++---------- include/linux/mm.h | 22 +++-- mm/kasan/common.c | 56 +++++------ 3 files changed, 210 insertions(+), 81 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 872bf145ddde..f631f99aa4b4 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -2,6 +2,7 @@ #ifndef _LINUX_KASAN_H #define _LINUX_KASAN_H +#include #include struct kmem_cache; @@ -74,54 +75,176 @@ static inline void kasan_disable_current(void) {} #ifdef CONFIG_KASAN -void kasan_unpoison_range(const void *address, size_t size); +struct kasan_cache { + int alloc_meta_offset; + int free_meta_offset; +}; -void kasan_alloc_pages(struct page *page, unsigned int order); -void kasan_free_pages(struct page *page, unsigned int order); +#ifdef CONFIG_KASAN_HW_TAGS +DECLARE_STATIC_KEY_FALSE(kasan_flag_enabled); +static __always_inline bool kasan_enabled(void) +{ + return static_branch_likely(&kasan_flag_enabled); +} +#else +static inline bool kasan_enabled(void) +{ + return true; +} +#endif -void kasan_cache_create(struct kmem_cache *cache, unsigned int *size, - slab_flags_t *flags); +void __kasan_unpoison_range(const void *addr, size_t size); +static __always_inline void kasan_unpoison_range(const void *addr, size_t size) +{ + if (kasan_enabled()) + __kasan_unpoison_range(addr, size); +} -void kasan_poison_slab(struct page *page); -void kasan_unpoison_object_data(struct kmem_cache *cache, void *object); -void kasan_poison_object_data(struct kmem_cache *cache, void *object); -void * __must_check kasan_init_slab_obj(struct kmem_cache *cache, - const void *object); +void __kasan_alloc_pages(struct page *page, unsigned int order); +static __always_inline void kasan_alloc_pages(struct page *page, + unsigned int order) +{ + if (kasan_enabled()) + __kasan_alloc_pages(page, order); +} -void * __must_check kasan_kmalloc_large(const void *ptr, size_t size, - gfp_t flags); -void kasan_kfree_large(void *ptr, unsigned long ip); -void kasan_poison_kfree(void *ptr, unsigned long ip); -void * __must_check kasan_kmalloc(struct kmem_cache *s, const void *object, - size_t size, gfp_t flags); -void * __must_check kasan_krealloc(const void *object, size_t new_size, - gfp_t flags); +void __kasan_free_pages(struct page *page, unsigned int order); +static __always_inline void kasan_free_pages(struct page *page, + unsigned int order) +{ + if (kasan_enabled()) + __kasan_free_pages(page, order); +} -void * __must_check kasan_slab_alloc(struct kmem_cache *s, void *object, - gfp_t flags); -bool kasan_slab_free(struct kmem_cache *s, void *object, unsigned long ip); +void __kasan_cache_create(struct kmem_cache *cache, unsigned int *size, + slab_flags_t *flags); +static __always_inline void kasan_cache_create(struct kmem_cache *cache, + unsigned int *size, slab_flags_t *flags) +{ + if (kasan_enabled()) + __kasan_cache_create(cache, size, flags); +} -struct kasan_cache { - int alloc_meta_offset; - int free_meta_offset; -}; +size_t __kasan_metadata_size(struct kmem_cache *cache); +static __always_inline size_t kasan_metadata_size(struct kmem_cache *cache) +{ + if (kasan_enabled()) + return __kasan_metadata_size(cache); + return 0; +} + +void __kasan_poison_slab(struct page *page); +static __always_inline void kasan_poison_slab(struct page *page) +{ + if (kasan_enabled()) + __kasan_poison_slab(page); +} + +void __kasan_unpoison_object_data(struct kmem_cache *cache, void *object); +static __always_inline void kasan_unpoison_object_data(struct kmem_cache *cache, + void *object) +{ + if (kasan_enabled()) + __kasan_unpoison_object_data(cache, object); +} + +void __kasan_poison_object_data(struct kmem_cache *cache, void *object); +static __always_inline void kasan_poison_object_data(struct kmem_cache *cache, + void *object) +{ + if (kasan_enabled()) + __kasan_poison_object_data(cache, object); +} + +void * __must_check __kasan_init_slab_obj(struct kmem_cache *cache, + const void *object); +static __always_inline void * __must_check kasan_init_slab_obj( + struct kmem_cache *cache, const void *object) +{ + if (kasan_enabled()) + return __kasan_init_slab_obj(cache, object); + return (void *)object; +} + +bool __kasan_slab_free(struct kmem_cache *s, void *object, unsigned long ip); +static __always_inline bool kasan_slab_free(struct kmem_cache *s, void *object, + unsigned long ip) +{ + if (kasan_enabled()) + return __kasan_slab_free(s, object, ip); + return false; +} + +void * __must_check __kasan_slab_alloc(struct kmem_cache *s, + void *object, gfp_t flags); +static __always_inline void * __must_check kasan_slab_alloc( + struct kmem_cache *s, void *object, gfp_t flags) +{ + if (kasan_enabled()) + return __kasan_slab_alloc(s, object, flags); + return object; +} + +void * __must_check __kasan_kmalloc(struct kmem_cache *s, const void *object, + size_t size, gfp_t flags); +static __always_inline void * __must_check kasan_kmalloc(struct kmem_cache *s, + const void *object, size_t size, gfp_t flags) +{ + if (kasan_enabled()) + return __kasan_kmalloc(s, object, size, flags); + return (void *)object; +} -size_t kasan_metadata_size(struct kmem_cache *cache); +void * __must_check __kasan_kmalloc_large(const void *ptr, + size_t size, gfp_t flags); +static __always_inline void * __must_check kasan_kmalloc_large(const void *ptr, + size_t size, gfp_t flags) +{ + if (kasan_enabled()) + return __kasan_kmalloc_large(ptr, size, flags); + return (void *)ptr; +} + +void * __must_check __kasan_krealloc(const void *object, + size_t new_size, gfp_t flags); +static __always_inline void * __must_check kasan_krealloc(const void *object, + size_t new_size, gfp_t flags) +{ + if (kasan_enabled()) + return __kasan_krealloc(object, new_size, flags); + return (void *)object; +} + +void __kasan_poison_kfree(void *ptr, unsigned long ip); +static __always_inline void kasan_poison_kfree(void *ptr, unsigned long ip) +{ + if (kasan_enabled()) + __kasan_poison_kfree(ptr, ip); +} + +void __kasan_kfree_large(void *ptr, unsigned long ip); +static __always_inline void kasan_kfree_large(void *ptr, unsigned long ip) +{ + if (kasan_enabled()) + __kasan_kfree_large(ptr, ip); +} bool kasan_save_enable_multi_shot(void); void kasan_restore_multi_shot(bool enabled); #else /* CONFIG_KASAN */ +static inline bool kasan_enabled(void) +{ + return false; +} static inline void kasan_unpoison_range(const void *address, size_t size) {} - static inline void kasan_alloc_pages(struct page *page, unsigned int order) {} static inline void kasan_free_pages(struct page *page, unsigned int order) {} - static inline void kasan_cache_create(struct kmem_cache *cache, unsigned int *size, slab_flags_t *flags) {} - +static inline size_t kasan_metadata_size(struct kmem_cache *cache) { return 0; } static inline void kasan_poison_slab(struct page *page) {} static inline void kasan_unpoison_object_data(struct kmem_cache *cache, void *object) {} @@ -132,36 +255,32 @@ static inline void *kasan_init_slab_obj(struct kmem_cache *cache, { return (void *)object; } - -static inline void *kasan_kmalloc_large(void *ptr, size_t size, gfp_t flags) +static inline bool kasan_slab_free(struct kmem_cache *s, void *object, + unsigned long ip) { - return ptr; + return false; +} +static inline void *kasan_slab_alloc(struct kmem_cache *s, void *object, + gfp_t flags) +{ + return object; } -static inline void kasan_kfree_large(void *ptr, unsigned long ip) {} -static inline void kasan_poison_kfree(void *ptr, unsigned long ip) {} static inline void *kasan_kmalloc(struct kmem_cache *s, const void *object, size_t size, gfp_t flags) { return (void *)object; } +static inline void *kasan_kmalloc_large(const void *ptr, size_t size, gfp_t flags) +{ + return (void *)ptr; +} static inline void *kasan_krealloc(const void *object, size_t new_size, gfp_t flags) { return (void *)object; } - -static inline void *kasan_slab_alloc(struct kmem_cache *s, void *object, - gfp_t flags) -{ - return object; -} -static inline bool kasan_slab_free(struct kmem_cache *s, void *object, - unsigned long ip) -{ - return false; -} - -static inline size_t kasan_metadata_size(struct kmem_cache *cache) { return 0; } +static inline void kasan_poison_kfree(void *ptr, unsigned long ip) {} +static inline void kasan_kfree_large(void *ptr, unsigned long ip) {} #endif /* CONFIG_KASAN */ diff --git a/include/linux/mm.h b/include/linux/mm.h index 035957363055..82c57668748c 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -31,6 +31,7 @@ #include #include #include +#include struct mempolicy; struct anon_vma; @@ -1422,22 +1423,30 @@ static inline bool cpupid_match_pid(struct task_struct *task, int cpupid) #endif /* CONFIG_NUMA_BALANCING */ #if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS) + static inline u8 page_kasan_tag(const struct page *page) { - return (page->flags >> KASAN_TAG_PGSHIFT) & KASAN_TAG_MASK; + if (kasan_enabled()) + return (page->flags >> KASAN_TAG_PGSHIFT) & KASAN_TAG_MASK; + return 0xff; } static inline void page_kasan_tag_set(struct page *page, u8 tag) { - page->flags &= ~(KASAN_TAG_MASK << KASAN_TAG_PGSHIFT); - page->flags |= (tag & KASAN_TAG_MASK) << KASAN_TAG_PGSHIFT; + if (kasan_enabled()) { + page->flags &= ~(KASAN_TAG_MASK << KASAN_TAG_PGSHIFT); + page->flags |= (tag & KASAN_TAG_MASK) << KASAN_TAG_PGSHIFT; + } } static inline void page_kasan_tag_reset(struct page *page) { - page_kasan_tag_set(page, 0xff); + if (kasan_enabled()) + page_kasan_tag_set(page, 0xff); } -#else + +#else /* CONFIG_KASAN_SW_TAGS || CONFIG_KASAN_HW_TAGS */ + static inline u8 page_kasan_tag(const struct page *page) { return 0xff; @@ -1445,7 +1454,8 @@ static inline u8 page_kasan_tag(const struct page *page) static inline void page_kasan_tag_set(struct page *page, u8 tag) { } static inline void page_kasan_tag_reset(struct page *page) { } -#endif + +#endif /* CONFIG_KASAN_SW_TAGS || CONFIG_KASAN_HW_TAGS */ static inline struct zone *page_zone(const struct page *page) { diff --git a/mm/kasan/common.c b/mm/kasan/common.c index a11e3e75eb08..17918bd20ed9 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -59,7 +59,7 @@ void kasan_disable_current(void) } #endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ -void kasan_unpoison_range(const void *address, size_t size) +void __kasan_unpoison_range(const void *address, size_t size) { unpoison_range(address, size); } @@ -87,7 +87,7 @@ asmlinkage void kasan_unpoison_task_stack_below(const void *watermark) } #endif /* CONFIG_KASAN_STACK */ -void kasan_alloc_pages(struct page *page, unsigned int order) +void __kasan_alloc_pages(struct page *page, unsigned int order) { u8 tag; unsigned long i; @@ -101,7 +101,7 @@ void kasan_alloc_pages(struct page *page, unsigned int order) unpoison_range(page_address(page), PAGE_SIZE << order); } -void kasan_free_pages(struct page *page, unsigned int order) +void __kasan_free_pages(struct page *page, unsigned int order) { if (likely(!PageHighMem(page))) poison_range(page_address(page), @@ -128,8 +128,8 @@ static inline unsigned int optimal_redzone(unsigned int object_size) object_size <= (1 << 16) - 1024 ? 1024 : 2048; } -void kasan_cache_create(struct kmem_cache *cache, unsigned int *size, - slab_flags_t *flags) +void __kasan_cache_create(struct kmem_cache *cache, unsigned int *size, + slab_flags_t *flags) { unsigned int orig_size = *size; unsigned int redzone_size; @@ -174,7 +174,7 @@ void kasan_cache_create(struct kmem_cache *cache, unsigned int *size, *flags |= SLAB_KASAN; } -size_t kasan_metadata_size(struct kmem_cache *cache) +size_t __kasan_metadata_size(struct kmem_cache *cache) { if (!kasan_stack_collection_enabled()) return 0; @@ -197,7 +197,7 @@ struct kasan_free_meta *kasan_get_free_meta(struct kmem_cache *cache, return kasan_reset_tag(object) + cache->kasan_info.free_meta_offset; } -void kasan_poison_slab(struct page *page) +void __kasan_poison_slab(struct page *page) { unsigned long i; @@ -207,12 +207,12 @@ void kasan_poison_slab(struct page *page) KASAN_KMALLOC_REDZONE); } -void kasan_unpoison_object_data(struct kmem_cache *cache, void *object) +void __kasan_unpoison_object_data(struct kmem_cache *cache, void *object) { unpoison_range(object, cache->object_size); } -void kasan_poison_object_data(struct kmem_cache *cache, void *object) +void __kasan_poison_object_data(struct kmem_cache *cache, void *object) { poison_range(object, round_up(cache->object_size, KASAN_GRANULE_SIZE), @@ -265,7 +265,7 @@ static u8 assign_tag(struct kmem_cache *cache, const void *object, #endif } -void * __must_check kasan_init_slab_obj(struct kmem_cache *cache, +void * __must_check __kasan_init_slab_obj(struct kmem_cache *cache, const void *object) { struct kasan_alloc_meta *alloc_meta; @@ -284,7 +284,7 @@ void * __must_check kasan_init_slab_obj(struct kmem_cache *cache, return (void *)object; } -static bool __kasan_slab_free(struct kmem_cache *cache, void *object, +static bool ____kasan_slab_free(struct kmem_cache *cache, void *object, unsigned long ip, bool quarantine) { u8 tag; @@ -330,9 +330,9 @@ static bool __kasan_slab_free(struct kmem_cache *cache, void *object, return IS_ENABLED(CONFIG_KASAN_GENERIC); } -bool kasan_slab_free(struct kmem_cache *cache, void *object, unsigned long ip) +bool __kasan_slab_free(struct kmem_cache *cache, void *object, unsigned long ip) { - return __kasan_slab_free(cache, object, ip, true); + return ____kasan_slab_free(cache, object, ip, true); } static void set_alloc_info(struct kmem_cache *cache, void *object, gfp_t flags) @@ -340,7 +340,7 @@ static void set_alloc_info(struct kmem_cache *cache, void *object, gfp_t flags) kasan_set_track(&kasan_get_alloc_meta(cache, object)->alloc_track, flags); } -static void *__kasan_kmalloc(struct kmem_cache *cache, const void *object, +static void *____kasan_kmalloc(struct kmem_cache *cache, const void *object, size_t size, gfp_t flags, bool keep_tag) { unsigned long redzone_start; @@ -375,20 +375,20 @@ static void *__kasan_kmalloc(struct kmem_cache *cache, const void *object, return set_tag(object, tag); } -void * __must_check kasan_slab_alloc(struct kmem_cache *cache, void *object, - gfp_t flags) +void * __must_check __kasan_slab_alloc(struct kmem_cache *cache, + void *object, gfp_t flags) { - return __kasan_kmalloc(cache, object, cache->object_size, flags, false); + return ____kasan_kmalloc(cache, object, cache->object_size, flags, false); } -void * __must_check kasan_kmalloc(struct kmem_cache *cache, const void *object, - size_t size, gfp_t flags) +void * __must_check __kasan_kmalloc(struct kmem_cache *cache, const void *object, + size_t size, gfp_t flags) { - return __kasan_kmalloc(cache, object, size, flags, true); + return ____kasan_kmalloc(cache, object, size, flags, true); } -EXPORT_SYMBOL(kasan_kmalloc); +EXPORT_SYMBOL(__kasan_kmalloc); -void * __must_check kasan_kmalloc_large(const void *ptr, size_t size, +void * __must_check __kasan_kmalloc_large(const void *ptr, size_t size, gfp_t flags) { struct page *page; @@ -413,7 +413,7 @@ void * __must_check kasan_kmalloc_large(const void *ptr, size_t size, return (void *)ptr; } -void * __must_check kasan_krealloc(const void *object, size_t size, gfp_t flags) +void * __must_check __kasan_krealloc(const void *object, size_t size, gfp_t flags) { struct page *page; @@ -423,13 +423,13 @@ void * __must_check kasan_krealloc(const void *object, size_t size, gfp_t flags) page = virt_to_head_page(object); if (unlikely(!PageSlab(page))) - return kasan_kmalloc_large(object, size, flags); + return __kasan_kmalloc_large(object, size, flags); else - return __kasan_kmalloc(page->slab_cache, object, size, + return ____kasan_kmalloc(page->slab_cache, object, size, flags, true); } -void kasan_poison_kfree(void *ptr, unsigned long ip) +void __kasan_poison_kfree(void *ptr, unsigned long ip) { struct page *page; @@ -442,11 +442,11 @@ void kasan_poison_kfree(void *ptr, unsigned long ip) } poison_range(ptr, page_size(page), KASAN_FREE_PAGE); } else { - __kasan_slab_free(page->slab_cache, ptr, ip, false); + ____kasan_slab_free(page->slab_cache, ptr, ip, false); } } -void kasan_kfree_large(void *ptr, unsigned long ip) +void __kasan_kfree_large(void *ptr, unsigned long ip) { if (ptr != page_address(virt_to_head_page(ptr))) kasan_report_invalid_free(ptr, ip); From patchwork Mon Nov 23 20:14:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11929071 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DBD0C2D0E4 for ; Tue, 24 Nov 2020 13:50:39 +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 1A54120888 for ; Tue, 24 Nov 2020 13:50:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="YMIS76iH"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="iw9IgCY/"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="A+kpGAdD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1A54120888 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+linux-arm-kernel=archiver.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=Qxg4k3Uex81+y7F15RCoaRCope6PFeLXZ05asNkNe8I=; b=YMIS76iHSCout4hjfEst/vk/1 bXFlBrd3OW9upZ8FxR+YyDBVVE/D23YzwyAztyEsMjdVi7KGHCLO+rVHNabP0uge86O9zjb2TuvcO 5D6uAK6J5/D8kjO6SX47KyK1HSxqogPnzqAlQHY8HKq4NHyfJstmik/NLlWN7kCKsf45rAjnHSDHh gKScKD4ewrFuCLXWlMxyp+q1XuRKusdh9/JHYY6KljNw8wGj+KJtvwL62cOl1SQkw8sGp5LzwWu4q AdzgBqi3JeYmM2aerkzAs4D69ZNcloar5tDqU2uhL+DSugWXJV0j1ykHBNIqUZDc31m1WaK/urCEp qns4CjtWw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khYh9-0005dM-Ko; Tue, 24 Nov 2020 13:49:23 +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 1khIO9-0006KM-7A for linux-arm-kernel@merlin.infradead.org; Mon, 23 Nov 2020 20:24:41 +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=vCPSdYhuISEPMca4NzZzu0kqKTeEYaaZfMxe3jMvD/s=; b=iw9IgCY/sbFLc4cxpe3DV+DSkZ EIZ08ZvT84EFxQkOWQAXPdSmBrAnTiExQkecAQI6Wjs4ZbloLu35TbGklNv6XAUsJW3nBwPJjcEZG JQdQO6d729Rln5t0Uw/sP2DvCHect6rg3BkLdxKSdGws/e6iCyBUssIygeCU7gdS2vM2or/Ot6RXG 7/nhatchcu1SHQeNQvr4rulquRoZ5HQ6cFNfdwxEqGxsSUWoe7ZOvfeOQDFHNacIGIAkicBDD+VWr xph5H/emd+Hu+gbeiCFiZtYewKIk6eTvRsHkL1ZMk/kTv2nbnih/aSXqioiNGLBtnKPjmuET0cLQI E684oZPg==; Received: from mail-wr1-x44a.google.com ([2a00:1450:4864:20::44a]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIFC-0006Lz-Hh for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2020 20:15:30 +0000 Received: by mail-wr1-x44a.google.com with SMTP id x10so2158078wrs.2 for ; Mon, 23 Nov 2020 12:15:25 -0800 (PST) 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=vCPSdYhuISEPMca4NzZzu0kqKTeEYaaZfMxe3jMvD/s=; b=A+kpGAdDHR+xLc8BXfFeZuxuuUrerctxHRGgM41gvim7A7SXBS2BpSFAPSf5z+xzcE w6rQ703Pf9m4i65OsXJrLu449pBNv4pXNZeOvCOD8nzLXO3r5Zsa4nVbArsdgc4QZy/D ClV5Ear6f0SA4Jp/VjbffFIIf1cSZ6qO6dFN5ShhIVcvVxMoMbpLjthlfMNq75mF0WYA T7wypdNYQEmicmFseG6C87RZXk2XsHgsH8s1aqze4J+fIljx2mYVTU6+mkwSiOWQsfQD BnjTUyurg1MZW73nAmP1V+AeMyico/YJMF2zluj5MlPfXPwPp4qXLmUPA3Lavcv/PFIs URBQ== 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=vCPSdYhuISEPMca4NzZzu0kqKTeEYaaZfMxe3jMvD/s=; b=lVjvaMuEijpuXXnH86nD1OvU3N8slJivgy5vogYUo1LXImQbB/95f647DbjNzjYNJe Zrub0xP/zMoODB0Yf2HCCgvt7oUq8CmsO924EPHOiw7O0m3Bv0DJcf1AUho+v2DTpMxL 0bDcE7n7Ka6wX1YYNk2ERWfGdMDHSnGUsAbdefcpavhldGmix8PW1Uv9h65FzVHnofAb 9XwLWGl7qVwM3Ve/dfN+VNlIVpXDm7OjSG7PJsnvBcl/BpGt3MHa1Qh8VyqnHriUVEV/ GMH+x1qYCvFtmdMpWWJnhfKlG7V+enHkJhgrke5ffJ1Vg9cnvjfPwKMrbn4R7sclEMic E07w== X-Gm-Message-State: AOAM531Rv/xb3QDjjV1DwerPmC3plocEv8HsfYH5lx4CvEo7GLULqjmE mhNnOM15Eo5KrxWUtsCJg71w8V/xXESHrRQN X-Google-Smtp-Source: ABdhPJyImRIUxX0vdlPpQTNZOS8VnAdiwtBEG9ySXx3qFznfha0oetLY9Do8+WGjSwOiFt3ZSxe5XbJ3Qnga4at5 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:c343:: with SMTP id t64mr639600wmf.140.1606162524075; Mon, 23 Nov 2020 12:15:24 -0800 (PST) Date: Mon, 23 Nov 2020 21:14:43 +0100 In-Reply-To: Message-Id: <141675fb493555e984c5dca555e9d9f768c7bbaa.1606162397.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH mm v4 13/19] kasan, mm: rename kasan_poison_kfree From: Andrey Konovalov To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201123_201526_915223_A71363AD X-CRM114-Status: GOOD ( 16.40 ) 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-arm-kernel@lists.infradead.org, Marco Elver , Catalin Marinas , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Konovalov , Andrey Ryabinin , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Rename kasan_poison_kfree() to kasan_slab_free_mempool() as it better reflects what this annotation does. Also add a comment that explains the PageSlab() check. No functional changes. Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver Link: https://linux-review.googlesource.com/id/I5026f87364e556b506ef1baee725144bb04b8810 --- include/linux/kasan.h | 16 ++++++++-------- mm/kasan/common.c | 40 +++++++++++++++++++++++----------------- mm/mempool.c | 2 +- 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index f631f99aa4b4..2610438120ce 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -175,6 +175,13 @@ static __always_inline bool kasan_slab_free(struct kmem_cache *s, void *object, return false; } +void __kasan_slab_free_mempool(void *ptr, unsigned long ip); +static __always_inline void kasan_slab_free_mempool(void *ptr, unsigned long ip) +{ + if (kasan_enabled()) + __kasan_slab_free_mempool(ptr, ip); +} + void * __must_check __kasan_slab_alloc(struct kmem_cache *s, void *object, gfp_t flags); static __always_inline void * __must_check kasan_slab_alloc( @@ -215,13 +222,6 @@ static __always_inline void * __must_check kasan_krealloc(const void *object, return (void *)object; } -void __kasan_poison_kfree(void *ptr, unsigned long ip); -static __always_inline void kasan_poison_kfree(void *ptr, unsigned long ip) -{ - if (kasan_enabled()) - __kasan_poison_kfree(ptr, ip); -} - void __kasan_kfree_large(void *ptr, unsigned long ip); static __always_inline void kasan_kfree_large(void *ptr, unsigned long ip) { @@ -260,6 +260,7 @@ static inline bool kasan_slab_free(struct kmem_cache *s, void *object, { return false; } +static inline void kasan_slab_free_mempool(void *ptr, unsigned long ip) {} static inline void *kasan_slab_alloc(struct kmem_cache *s, void *object, gfp_t flags) { @@ -279,7 +280,6 @@ static inline void *kasan_krealloc(const void *object, size_t new_size, { return (void *)object; } -static inline void kasan_poison_kfree(void *ptr, unsigned long ip) {} static inline void kasan_kfree_large(void *ptr, unsigned long ip) {} #endif /* CONFIG_KASAN */ diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 17918bd20ed9..1205faac90bd 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -335,6 +335,29 @@ bool __kasan_slab_free(struct kmem_cache *cache, void *object, unsigned long ip) return ____kasan_slab_free(cache, object, ip, true); } +void __kasan_slab_free_mempool(void *ptr, unsigned long ip) +{ + struct page *page; + + page = virt_to_head_page(ptr); + + /* + * Even though this function is only called for kmem_cache_alloc and + * kmalloc backed mempool allocations, those allocations can still be + * !PageSlab() when the size provided to kmalloc is larger than + * KMALLOC_MAX_SIZE, and kmalloc falls back onto page_alloc. + */ + if (unlikely(!PageSlab(page))) { + if (ptr != page_address(page)) { + kasan_report_invalid_free(ptr, ip); + return; + } + poison_range(ptr, page_size(page), KASAN_FREE_PAGE); + } else { + ____kasan_slab_free(page->slab_cache, ptr, ip, false); + } +} + static void set_alloc_info(struct kmem_cache *cache, void *object, gfp_t flags) { kasan_set_track(&kasan_get_alloc_meta(cache, object)->alloc_track, flags); @@ -429,23 +452,6 @@ void * __must_check __kasan_krealloc(const void *object, size_t size, gfp_t flag flags, true); } -void __kasan_poison_kfree(void *ptr, unsigned long ip) -{ - struct page *page; - - page = virt_to_head_page(ptr); - - if (unlikely(!PageSlab(page))) { - if (ptr != page_address(page)) { - kasan_report_invalid_free(ptr, ip); - return; - } - poison_range(ptr, page_size(page), KASAN_FREE_PAGE); - } else { - ____kasan_slab_free(page->slab_cache, ptr, ip, false); - } -} - void __kasan_kfree_large(void *ptr, unsigned long ip) { if (ptr != page_address(virt_to_head_page(ptr))) diff --git a/mm/mempool.c b/mm/mempool.c index 583a9865b181..624ed51b060f 100644 --- a/mm/mempool.c +++ b/mm/mempool.c @@ -104,7 +104,7 @@ static inline void poison_element(mempool_t *pool, void *element) static __always_inline void kasan_poison_element(mempool_t *pool, void *element) { if (pool->alloc == mempool_alloc_slab || pool->alloc == mempool_kmalloc) - kasan_poison_kfree(element, _RET_IP_); + kasan_slab_free_mempool(element, _RET_IP_); else if (pool->alloc == mempool_alloc_pages) kasan_free_pages(element, (unsigned long)pool->pool_data); } From patchwork Mon Nov 23 20:14:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11926709 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 980FBC2D0E4 for ; Mon, 23 Nov 2020 20:41:09 +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 1B5A720721 for ; Mon, 23 Nov 2020 20:41:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="A2zPczTF"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="bCnebjZk"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="K9aATwYZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1B5A720721 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+linux-arm-kernel=archiver.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=lCiIwj8en42n3vC5tiXyFYKsudLI1wHVR9t1V0IHxQ4=; b=A2zPczTFa8NtzxHbYHPbDuhXG BfRYoqA85CxhuVlrUh+BGySUcJwICoQW2JGvo1DFiY6i2pYsO/zHGJFhJQNDFa6t5z8+CIY3IWul9 0eOAWC4iKPC4pR9kU9Co3QpXB0Zx/PPd3IteZtmcPvCTVddbpxFovuQ+LZEy3hdtakiaMVtx6FABP DRyetGwsrvmLSt6g/Y0xsQJwQyGEA/YCyF91rBDtBpaO4AZiWWvdg6RuXVjCRprHHAkNT4Pq4TYjE s7XyReSQYgv+GpHCpOcZm5vv1crD/pH1onbwYW1TG6JUuZD3EApw1vWDFT4J+N05l4Gruawd5WVfW GB9R4tAmw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIdM-00052g-Be; Mon, 23 Nov 2020 20:40:25 +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 1khIO6-0006KM-Fz for linux-arm-kernel@merlin.infradead.org; Mon, 23 Nov 2020 20:24:38 +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=FZtWTAUkAvRQTA+AtFREJR6Qo+0tQ7KPae8j2grwXDU=; b=bCnebjZk8TA+pKbb5a15uxdM4U 5hyuIHm6McJIn2bsKtTw/drfkLpHHC7SdrU2o5AqI/w02vBbQ7aj1aQeh9iqPxBd5Km7OggfpTadw oWtP0ZvQ9++hj/lATb56hxgpBTgaF6KykeUGeeEbb44oBZDz58V2ieGrbP/948Wa1HjrU+lcOzq7i Qz7vmEA4CyZi7qmdH4lGS67r9FhjOXArpmtr07lQHQ7/A+AepldGglLC+AniKN6GbbthD54O12wC2 OYmq2lGAGzM0xisH8tb1Xt1zcPrGoDdwwaITw6fBPKXqY/7+BWzd5SPIhX2uzjVRIelOKikQLbRAr pLBCMSfQ==; Received: from mail-wr1-x449.google.com ([2a00:1450:4864:20::449]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIFE-0006Mp-RL for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2020 20:15:37 +0000 Received: by mail-wr1-x449.google.com with SMTP id c8so6243016wrh.16 for ; Mon, 23 Nov 2020 12:15:28 -0800 (PST) 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=FZtWTAUkAvRQTA+AtFREJR6Qo+0tQ7KPae8j2grwXDU=; b=K9aATwYZ9UoO7zi/mRajdIf64nFoB/xPUhE6qD8yIYqaNAhTqY64x7uB+K9m3QJ40A ytw4vCig7iAtvBjCXfs40hqcTLm7Odl0kKeDucZE+W5LxAe8giB5ELA+GiXmWkoyVfTR 8VWXey3Y9t3qeFOVBmJkyXECHO8rV15eIPpddIiFLLU/qlDLV5HqtrwPJh0+UH2Ygph5 Z6/bnnanhSfmK5redsl/WVUEpIGIXuFJacmnkiW+gJbrNQFApiGz7xK8SCrztmwn+Cvh vx+a8m9boaO+qlJC/KyajQBs38ioorzXUmsspg2Z4ytFIwtAzknXZ1YxVcYgrBWWv60L fiZQ== 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=FZtWTAUkAvRQTA+AtFREJR6Qo+0tQ7KPae8j2grwXDU=; b=OmRt+FvjfUFweFwO+2ue27gbTVJYZj2bNBMTC6cDJFb/pKATnmegtMGI+qcfWzOHfc W7A1F8/ctC9n0NKbsaN4vaWw66otMkv4nrQCTGBNrlZV8k+x1kfzeC7tzHRpI8yR4CqA iw7+B7lo04D+eBhVhcjf1zbxa48ZGh0ABh+NKeriAcuuSrPsAeluDkEFn3oJQh16U7SR pJ/jJddFByxCf59OzomDm7t9ziNC/bgPMxqdtV20f/FjKQDWC411+OkUkKU0+AJaAY/j 0vzGeR7x/Us7V6HEnEV2FpRSKIztaDPmDJVDb6IMmK0znJ+T4pSMNvWAdrgW9IwXqnIS iQBg== X-Gm-Message-State: AOAM530AkOstiU0iD9tzot3nZ6G3iMof390+lvKpjMw79CxhsFMMhPDh P1SK233jnL/O6MzGtEzy0oAEJ9X1xxoFzM6N X-Google-Smtp-Source: ABdhPJx1M4yjerM84Av5uMxcUmZm/oWpySCuetBAnvpXA3hwdyiT7m0HNDW+S1RL2PjXZJhTMRp0/KP7cR2W8hs1 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:adf:ed02:: with SMTP id a2mr1480549wro.81.1606162526631; Mon, 23 Nov 2020 12:15:26 -0800 (PST) Date: Mon, 23 Nov 2020 21:14:44 +0100 In-Reply-To: Message-Id: <47b232474f1f89dc072aeda0fa58daa6efade377.1606162397.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH mm v4 14/19] kasan: don't round_up too much From: Andrey Konovalov To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201123_201529_594195_164E1499 X-CRM114-Status: GOOD ( 12.70 ) 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-arm-kernel@lists.infradead.org, Marco Elver , Catalin Marinas , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Konovalov , Andrey Ryabinin , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org For hardware tag-based mode kasan_poison_memory() already rounds up the size. Do the same for software modes and remove round_up() from the common code. Signed-off-by: Andrey Konovalov Reviewed-by: Dmitry Vyukov Reviewed-by: Marco Elver Link: https://linux-review.googlesource.com/id/Ib397128fac6eba874008662b4964d65352db4aa4 --- mm/kasan/common.c | 8 ++------ mm/kasan/shadow.c | 1 + 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 1205faac90bd..1a88e4005181 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -214,9 +214,7 @@ void __kasan_unpoison_object_data(struct kmem_cache *cache, void *object) void __kasan_poison_object_data(struct kmem_cache *cache, void *object) { - poison_range(object, - round_up(cache->object_size, KASAN_GRANULE_SIZE), - KASAN_KMALLOC_REDZONE); + poison_range(object, cache->object_size, KASAN_KMALLOC_REDZONE); } /* @@ -289,7 +287,6 @@ static bool ____kasan_slab_free(struct kmem_cache *cache, void *object, { u8 tag; void *tagged_object; - unsigned long rounded_up_size; tag = get_tag(object); tagged_object = object; @@ -313,8 +310,7 @@ static bool ____kasan_slab_free(struct kmem_cache *cache, void *object, return true; } - rounded_up_size = round_up(cache->object_size, KASAN_GRANULE_SIZE); - poison_range(object, rounded_up_size, KASAN_KMALLOC_FREE); + poison_range(object, cache->object_size, KASAN_KMALLOC_FREE); if (!kasan_stack_collection_enabled()) return false; diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c index 37153bd1c126..e9efe88f7679 100644 --- a/mm/kasan/shadow.c +++ b/mm/kasan/shadow.c @@ -83,6 +83,7 @@ void poison_range(const void *address, size_t size, u8 value) * addresses to this function. */ address = kasan_reset_tag(address); + size = round_up(size, KASAN_GRANULE_SIZE); /* Skip KFENCE memory if called explicitly outside of sl*b. */ if (is_kfence_address(address)) From patchwork Mon Nov 23 20:14:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11926719 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA5D1C2D0E4 for ; Mon, 23 Nov 2020 20:41:55 +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 339F2204FD for ; Mon, 23 Nov 2020 20:41:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="NbeCl/He"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="ZfNNRWdc"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="vHo5ItmT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 339F2204FD 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+linux-arm-kernel=archiver.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=Ddu/qncFyF8F3zpCp3SdWjH7KYmmkXcSEvznFqGMkrY=; b=NbeCl/HeE56eZm20araWvx8rx ogOq13UGIkGQMqd5YNgTDgzRcbMOjsD7631+R+gGrM3ZWU6dTqaqpsfmZLTqLN8MNU5r/vLdrPmbj yuvhfsQ6r+gbZAy1l6t3EkNMUh0KIg7dUuFr/pizaHG8TpXnxFoTip8frg/CA0ranim1N93B2suLP lwNIwD3nq8834oUa6tQYcfCPGml3h/jePvB4Kxk1ismxTS8xk14Sr1pS/YW0aOhCMvC1/cikgCHRt VuKuaeEZo60+bQvFgRvZOLzFWI0gvJGkgD0uMnyVm7vetEH7PAgae0VcC+oh1+yLLteTWnyENYOPQ BI9LPxr2g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIcw-0004rN-Jc; Mon, 23 Nov 2020 20:39:59 +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 1khIO5-0006KM-Bz for linux-arm-kernel@merlin.infradead.org; Mon, 23 Nov 2020 20:24:37 +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=wBmPP01T6X6nVOaGKZckDZFO93MqGK09sbRfPDSt1eI=; b=ZfNNRWdcWehnBGimotnWkCLcPN /UuBdNsJgeUYRoNl8RWIQDNx/mALyPmt7K99X//6xLt/UgF3Ryto1RSbDAV6HZLQV61KpiCYdIbpe EQ5naPbjY08ABuCvRm+bPjo/Olhywhs4rTawbxmWO/hdOkcW+A+CsnDFt9ebvrMn4/Xr2PzSal09M 9d0ReZaMTzdOS5l5LwlMapqBvsvNJPct0waJFsM7gLXZ5vSeka3igOdhcPdZpBEsF58rPxgP874bn MnIfJ+/qUUcEi2x/43Rms+LgMXj+JW99g5i51Z5Fhdm3hnKN0dGNs1N/FICXe+huA1m3Zq/4QPA4D donc9eWQ==; Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIFI-0006Nu-Cc for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2020 20:15:37 +0000 Received: by mail-wm1-x34a.google.com with SMTP id o17so148703wmd.9 for ; Mon, 23 Nov 2020 12:15:31 -0800 (PST) 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=wBmPP01T6X6nVOaGKZckDZFO93MqGK09sbRfPDSt1eI=; b=vHo5ItmTL3kbBhJu4MbDo8AfqRmB73n2TJFE0EqgqSt8qZmzJAeQdQC3sKEnalkGXn ktkjkHf9SVCy/+8sUzxYEdo0V1Yxbry2LrkenRFFOepM6GqptfBvA4C8IpThBl75KpHt WmRnIy0r+5UovGNDlKo4z+gvVIVR67Jp4iFay2QP1lhbg/zzFlL1xN2Ts1992NPJccMO yPvLvTrrP9WRIgX3u5V106kkWnv9b5I21z82z2a8Odxi1fZjp6KzOWRTuiHa4PYjNJv+ Qx8DTqkNyJ8snArdIUqRdgkNEsIT5BmKTanM6v/2K7vU+vIIBXO28XYu1M994wDmikAX UWlw== 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=wBmPP01T6X6nVOaGKZckDZFO93MqGK09sbRfPDSt1eI=; b=hXc4GMNNwit4Dh0MUDCOHBU8Q+fmcBmRs1/EKjtyEw/X3vBLEc3eWbKYdSKa17Ifn/ BGqrYD9Si97lCQbtEClenkuiz8l7VuaZPN6uvNdRhpPfpN98XpJnBVL3cjHLizrL15td 2WyeDWAG44JI9KyLiRwIcxVV5sSrDS6owNUspii99GINMk9s44lnzAIKmQbdGAAscyFT 0RsoIoKFsj5XpUiOBQF6GjfDgmn0yctOBY8wfST552R8WEArfxud5GAx8SMUh51pblhs ev0EZJ6T5Fjfk5c7e52oiD/m6Z87JVnxdNYL1mAlu1y4Kn5awmSeIL+nBMFxEcHWUgq7 CBsg== X-Gm-Message-State: AOAM531gBQLmxWgkAqoIBwZZhZvzIOv44H9nvDUnow1bdEzkAYrFrhaJ n4IA/rPOscZCV6oUzKqZ1jgggIhI7lyps0uB X-Google-Smtp-Source: ABdhPJyHaYhL2h/mGk2m6LiBmTS7pItR3APYX+HCQrNLLJYOQY2bd3/ofHLz5IVsdCsxUJXf29WoeTZZqqWHQsZj X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:810c:: with SMTP id c12mr609306wmd.96.1606162529119; Mon, 23 Nov 2020 12:15:29 -0800 (PST) Date: Mon, 23 Nov 2020 21:14:45 +0100 In-Reply-To: Message-Id: <121eeab245f98555862b289d2ba9269c868fbbcf.1606162397.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH mm v4 15/19] kasan: simplify assign_tag and set_tag calls From: Andrey Konovalov To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201123_201532_806236_F55C7C5C X-CRM114-Status: GOOD ( 14.19 ) 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-arm-kernel@lists.infradead.org, Marco Elver , Catalin Marinas , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Konovalov , Andrey Ryabinin , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org set_tag() already ignores the tag for the generic mode, so just call it as is. Add a check for the generic mode to assign_tag(), and simplify its call in ____kasan_kmalloc(). Signed-off-by: Andrey Konovalov Reviewed-by: Dmitry Vyukov Reviewed-by: Marco Elver Link: https://linux-review.googlesource.com/id/I18905ca78fb4a3d60e1a34a4ca00247272480438 --- mm/kasan/common.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 1a88e4005181..821678a58ac6 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -234,6 +234,9 @@ void __kasan_poison_object_data(struct kmem_cache *cache, void *object) static u8 assign_tag(struct kmem_cache *cache, const void *object, bool init, bool keep_tag) { + if (IS_ENABLED(CONFIG_KASAN_GENERIC)) + return 0xff; + /* * 1. When an object is kmalloc()'ed, two hooks are called: * kasan_slab_alloc() and kasan_kmalloc(). We assign the @@ -276,8 +279,8 @@ void * __must_check __kasan_init_slab_obj(struct kmem_cache *cache, __memset(alloc_meta, 0, sizeof(*alloc_meta)); } - if (IS_ENABLED(CONFIG_KASAN_SW_TAGS) || IS_ENABLED(CONFIG_KASAN_HW_TAGS)) - object = set_tag(object, assign_tag(cache, object, true, false)); + /* Tag is ignored in set_tag() without CONFIG_KASAN_SW/HW_TAGS */ + object = set_tag(object, assign_tag(cache, object, true, false)); return (void *)object; } @@ -364,7 +367,7 @@ static void *____kasan_kmalloc(struct kmem_cache *cache, const void *object, { unsigned long redzone_start; unsigned long redzone_end; - u8 tag = 0xff; + u8 tag; if (gfpflags_allow_blocking(flags)) quarantine_reduce(); @@ -379,9 +382,7 @@ static void *____kasan_kmalloc(struct kmem_cache *cache, const void *object, KASAN_GRANULE_SIZE); redzone_end = round_up((unsigned long)object + cache->object_size, KASAN_GRANULE_SIZE); - - if (IS_ENABLED(CONFIG_KASAN_SW_TAGS) || IS_ENABLED(CONFIG_KASAN_HW_TAGS)) - tag = assign_tag(cache, object, false, keep_tag); + tag = assign_tag(cache, object, false, keep_tag); /* Tag is ignored in set_tag without CONFIG_KASAN_SW/HW_TAGS */ unpoison_range(set_tag(object, tag), size); From patchwork Mon Nov 23 20:14:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11926679 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66687C2D0E4 for ; Mon, 23 Nov 2020 20:36:00 +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 E91B420715 for ; Mon, 23 Nov 2020 20:35:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="0lWzrBim"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="gPxuvkeW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E91B420715 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+linux-arm-kernel=archiver.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=wBpBG0k8DwuTI7dhRYVRQeXITh1QtGgfdBkVBQAdfPM=; b=0lWzrBimqUzLFdvvuEYyw0BlG IVaI3hqo1Wqp0sxoxHGJ5YmRT0O8RZzw2tG6MGmdouNFIfkZwpPCxogCN/+HuO32i4SrhGYzWHILo pvfY9FIwUv9Wbrt1G4JEu2EFN4pjwAoXbIiN37K8OOOdDENuaiB40wMHCPlJH5LWwbo7VVF4lRFuu TTlrEFhIcGy1l+lp/CmNf00HuCVZXruQGXlfUuPkRxxJ6/2SnPyA88QC2ci4Uw8Kb0NJrJkkV4J8F Y5yvBB+2D87mizM38jsi0iqhfnJ56iuFPHy/NaYKm9ZC4+Pxa509y10vn9OGX4bIQpJRnSY7Jdm9D pts5BilXQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIYW-0002jG-Go; Mon, 23 Nov 2020 20:35:24 +0000 Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIFP-0002N1-9p for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2020 20:15:53 +0000 Received: by mail-wm1-x34a.google.com with SMTP id a130so320601wmf.0 for ; Mon, 23 Nov 2020 12:15:34 -0800 (PST) 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=SLF2Qvc7gBcEHnpk1EaOz5XsuYMk/rWEwWdOy/HR3J8=; b=gPxuvkeWbzAL10okCvnV63J6yKq5+nJDEf3KTpJZbFspTv57Fe66PFPktm1spET60q yEGt0mvxByroPr8UW1XHzCutUzRXJsgufyPVovhwfXtPDiEbDJ3ESK6fiWenjl6VJ4Bn IirhAvXSxowHsx4WAf+eZlDnt97b+hVAgKp+zd0ZIl9HcAiBAo05ye8vRfvtk1GV3JGN b4QWlJnRe6K1ElxT1mvUrNUmLjvjl09A2f0Nbldpda1qdIfcjYvQA1j1TVKHIlXFrlyW ettj4xS8+Zhq139aDT9rcGaB1iY/WgEABjb9kPtV5u9O9nMMri6xNgVguCVhD+eax7uL xxIA== 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=SLF2Qvc7gBcEHnpk1EaOz5XsuYMk/rWEwWdOy/HR3J8=; b=eynKmpBFfItuR/nfoTqfcUbtYBnRcM7Yb3Alzh5t/nb+fZ2whOJQyMPFMZZ14ccBLH Rw+3Ll2caNkY1AHNr2nkgjEyPvpNxJVxUGXPtthh4Zx6fBysNDbTcx5SokXapv2lcC+F eKTx4YiGdpSJX+o45ZJS4TCHbGxfGCab+r1DE3lrx09Gl4uLMVQkVbvMFlApPwP9yFGT mlXy+2ASR7w75sQ/k1HdnUCVo8IHs3DaJfo9J8ux71hMd499VQHhdv8SZsMBYlMwJ5gb RRdBRNi6mgrNizUf+Rsgf3F6TUc1GF/2OkSSrv9IW51Lbc0C1T230arswrUtppOiV7bD gz/Q== X-Gm-Message-State: AOAM531lY/ce9vcX5omowmTAnWCcrugICQTsc9xsoNRv4hl1x3Z4Vz1D XlUH2XdxZQmdXrO52juNhGP9VTZkUZvnEXHl X-Google-Smtp-Source: ABdhPJzCMxIzE1RMShDMDCcSDUVJ4JkQIYpCzwGXhmF3084iS9J11LT0NWXFlyiI8uA5UJueQ+y3msS6pvgNj8vl X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a7b:c00b:: with SMTP id c11mr587868wmb.175.1606162531510; Mon, 23 Nov 2020 12:15:31 -0800 (PST) Date: Mon, 23 Nov 2020 21:14:46 +0100 In-Reply-To: Message-Id: <1c8380fe0332a3bcc720fe29f1e0bef2e2974416.1606162397.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH mm v4 16/19] kasan: clarify comment in __kasan_kfree_large From: Andrey Konovalov To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201123_151540_214459_45AECE52 X-CRM114-Status: GOOD ( 13.67 ) 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-arm-kernel@lists.infradead.org, Marco Elver , Catalin Marinas , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Konovalov , Andrey Ryabinin , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently it says that the memory gets poisoned by page_alloc code. Clarify this by mentioning the specific callback that poisons the memory. Signed-off-by: Andrey Konovalov Reviewed-by: Dmitry Vyukov Reviewed-by: Marco Elver Link: https://linux-review.googlesource.com/id/I1334dffb69b87d7986fab88a1a039cc3ea764725 --- mm/kasan/common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 821678a58ac6..42ba64fce8a3 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -453,5 +453,5 @@ void __kasan_kfree_large(void *ptr, unsigned long ip) { if (ptr != page_address(virt_to_head_page(ptr))) kasan_report_invalid_free(ptr, ip); - /* The object will be poisoned by page_alloc. */ + /* The object will be poisoned by kasan_free_pages(). */ } From patchwork Mon Nov 23 20:14:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11926697 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A19DC388F9 for ; Mon, 23 Nov 2020 20:37:31 +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 98E6120721 for ; Mon, 23 Nov 2020 20:37:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Mh+Onlj4"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="vb3tnn8k" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 98E6120721 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+linux-arm-kernel=archiver.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=jCs14sBWRCBoTXzsyh++cwNqEYaOIt8+j1OKht35HtU=; b=Mh+Onlj4vCCG3vcfwouSWcxlo MiBAQ2cDsG0qaw/yai8rE4kJsMesAp2Pyxm47oZYro3MOMDV5bYmx7SrKkGLVaBhHb3+cm/NdyJ6y qeRFG50gqUaXXBmK7wA73aGkYjZ79b7bSygejrriKwQqxxUHQrVKl8Kz02L/EtErFSuit8YxHcH3G GjLUDHJwUde1U/sxntfDek96Cj+v6CehygrDWRG4A+gNINqQgfsXLHqKWdh5VpfZcf8yYmo+cHQv2 qy5rjH+2M32hyp6KyVTf5UZOG9vIEyy5TFse/LyzuYMEUxAGGwm5HmW7+VITtMGDs5eoCxvUJ7q/g tpIIiaSTA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIYd-0002nT-Oi; Mon, 23 Nov 2020 20:35:31 +0000 Received: from mail-qk1-x74a.google.com ([2607:f8b0:4864:20::74a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIFQ-0002Nj-7g for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2020 20:16:00 +0000 Received: by mail-qk1-x74a.google.com with SMTP id p129so131127qkc.20 for ; Mon, 23 Nov 2020 12:15:36 -0800 (PST) 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=ynP119GCVFCNEeKVEPVj7pM+QyD/hOvaLJsj/XDDQFw=; b=vb3tnn8kMgXNs0Y1GKGinWycRFk3eYD9mqaTh1+rBK0yxZG9Ua4sRfT523rRAQMS+B vn1qqVfjTp15yGAj5s5CoWbAUq34yjwp5e4FktPNcrp+zSPo3Refqd2kZ7xQWzT54BVm 4mp6nA47cwN+Aa5/waSd8BeOvAnZiT39dcO7Us2JLrCLnUBaY9A05C6yEO7swK1iRAn0 Zyo7/cwTjO1k3pRyEj7H2r6mHNYg7C0jUtw7eexwKoJYJIXmDYE5kSIsNwaFxXZ+P6sE gBK28YiUv1EwQh+kvmYohYs88El1mtuXLCDj4zjitmbw0eLYE0j2105D8dtmXu9VO5Ni 3EXw== 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=ynP119GCVFCNEeKVEPVj7pM+QyD/hOvaLJsj/XDDQFw=; b=dwsLvrUR+WJSKsYat+oK3WcFovFFYBwt6yodazrzl0gJyOAGV3+PvpyXUDNrKZf/5a 4OC707g5DIB57Wgi31kdigNp0zpu3QJDQTahiMLissOvb6lcC+jVEYwecZsoSAis9bHO LpzPvOBmQouQxxnICrxjMQURwnqUZ34TsUa2fDo/LScTFkwlggMpEOrU+rOJVjHZfY4d xLqVH8sfUzepOemuXmeDfH4ANeAAXYQhBPH9Nezo8+lieN5hnl2JJ/DwnYNJJsTUeFGx JZN0LbLC/VBccXSZbOWY03Fezt4oIubUrOCdh7LggcY0EvxY8b+pnsHNvW5OCrJ/FDGa FH4A== X-Gm-Message-State: AOAM530S/ZNLS8Mry2qXXpUv6Xx2RZyDVHTsG1OGN3ZC38UBUC33GgHm 5Qa1UkKe0bctweC81gj+tghmfhxS8htPeidy X-Google-Smtp-Source: ABdhPJy1Ttccayj5bHL1Qkwd9GPXwXjN+B592JrI/RD9bRkUAe5l3XPvVktIawbd9OOrK8MaGRi9OAQO5giJsfwB X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a0c:ab07:: with SMTP id h7mr1353179qvb.34.1606162533975; Mon, 23 Nov 2020 12:15:33 -0800 (PST) Date: Mon, 23 Nov 2020 21:14:47 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH mm v4 17/19] kasan: sanitize objects when metadata doesn't fit From: Andrey Konovalov To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201123_151540_957109_3FE39318 X-CRM114-Status: GOOD ( 31.20 ) 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-arm-kernel@lists.infradead.org, Marco Elver , Catalin Marinas , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Konovalov , Andrey Ryabinin , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org KASAN marks caches that are sanitized with the SLAB_KASAN cache flag. Currently if the metadata that is appended after the object (stores e.g. stack trace ids) doesn't fit into KMALLOC_MAX_SIZE (can only happen with SLAB, see the comment in the patch), KASAN turns off sanitization completely. With this change sanitization of the object data is always enabled. However the metadata is only stored when it fits. Instead of checking for SLAB_KASAN flag accross the code to find out whether the metadata is there, use cache->kasan_info.alloc/free_meta_offset. As 0 can be a valid value for free_meta_offset, introduce KASAN_NO_FREE_META as an indicator that the free metadata is missing. Without this change all sanitized KASAN objects would be put into quarantine with generic KASAN. With this change, only the objects that have metadata (i.e. when it fits) are put into quarantine, the rest is freed right away. Along the way rework __kasan_cache_create() and add claryfying comments. Co-developed-by: Vincenzo Frascino Signed-off-by: Vincenzo Frascino Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver Link: https://linux-review.googlesource.com/id/Icd947e2bea054cb5cfbdc6cf6652227d97032dcb --- mm/kasan/common.c | 116 ++++++++++++++++++++++++-------------- mm/kasan/generic.c | 15 ++--- mm/kasan/hw_tags.c | 6 +- mm/kasan/kasan.h | 17 +++++- mm/kasan/quarantine.c | 16 +++++- mm/kasan/report.c | 43 +++++++------- mm/kasan/report_sw_tags.c | 9 ++- mm/kasan/sw_tags.c | 4 ++ 8 files changed, 149 insertions(+), 77 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 42ba64fce8a3..249ccba1ecf5 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -115,9 +115,6 @@ void __kasan_free_pages(struct page *page, unsigned int order) */ static inline unsigned int optimal_redzone(unsigned int object_size) { - if (!IS_ENABLED(CONFIG_KASAN_GENERIC)) - return 0; - return object_size <= 64 - 16 ? 16 : object_size <= 128 - 32 ? 32 : @@ -131,47 +128,77 @@ static inline unsigned int optimal_redzone(unsigned int object_size) void __kasan_cache_create(struct kmem_cache *cache, unsigned int *size, slab_flags_t *flags) { - unsigned int orig_size = *size; - unsigned int redzone_size; - int redzone_adjust; + unsigned int ok_size; + unsigned int optimal_size; + + /* + * SLAB_KASAN is used to mark caches as ones that are sanitized by + * KASAN. Currently this flag is used in two places: + * 1. In slab_ksize() when calculating the size of the accessible + * memory within the object. + * 2. In slab_common.c to prevent merging of sanitized caches. + */ + *flags |= SLAB_KASAN; - if (!kasan_stack_collection_enabled()) { - *flags |= SLAB_KASAN; + if (!kasan_stack_collection_enabled()) return; - } - /* Add alloc meta. */ + ok_size = *size; + + /* Add alloc meta into redzone. */ cache->kasan_info.alloc_meta_offset = *size; *size += sizeof(struct kasan_alloc_meta); - /* Add free meta. */ - if (IS_ENABLED(CONFIG_KASAN_GENERIC) && - (cache->flags & SLAB_TYPESAFE_BY_RCU || cache->ctor || - cache->object_size < sizeof(struct kasan_free_meta))) { - cache->kasan_info.free_meta_offset = *size; - *size += sizeof(struct kasan_free_meta); + /* + * If alloc meta doesn't fit, don't add it. + * This can only happen with SLAB, as it has KMALLOC_MAX_SIZE equal + * to KMALLOC_MAX_CACHE_SIZE and doesn't fall back to page_alloc for + * larger sizes. + */ + if (*size > KMALLOC_MAX_SIZE) { + cache->kasan_info.alloc_meta_offset = 0; + *size = ok_size; + /* Continue, since free meta might still fit. */ } - redzone_size = optimal_redzone(cache->object_size); - redzone_adjust = redzone_size - (*size - cache->object_size); - if (redzone_adjust > 0) - *size += redzone_adjust; - - *size = min_t(unsigned int, KMALLOC_MAX_SIZE, - max(*size, cache->object_size + redzone_size)); + /* Only the generic mode uses free meta or flexible redzones. */ + if (!IS_ENABLED(CONFIG_KASAN_GENERIC)) { + cache->kasan_info.free_meta_offset = KASAN_NO_FREE_META; + return; + } /* - * If the metadata doesn't fit, don't enable KASAN at all. + * Add free meta into redzone when it's not possible to store + * it in the object. This is the case when: + * 1. Object is SLAB_TYPESAFE_BY_RCU, which means that it can + * be touched after it was freed, or + * 2. Object has a constructor, which means it's expected to + * retain its content until the next allocation, or + * 3. Object is too small. + * Otherwise cache->kasan_info.free_meta_offset = 0 is implied. */ - if (*size <= cache->kasan_info.alloc_meta_offset || - *size <= cache->kasan_info.free_meta_offset) { - cache->kasan_info.alloc_meta_offset = 0; - cache->kasan_info.free_meta_offset = 0; - *size = orig_size; - return; + if ((cache->flags & SLAB_TYPESAFE_BY_RCU) || cache->ctor || + cache->object_size < sizeof(struct kasan_free_meta)) { + ok_size = *size; + + cache->kasan_info.free_meta_offset = *size; + *size += sizeof(struct kasan_free_meta); + + /* If free meta doesn't fit, don't add it. */ + if (*size > KMALLOC_MAX_SIZE) { + cache->kasan_info.free_meta_offset = KASAN_NO_FREE_META; + *size = ok_size; + } } - *flags |= SLAB_KASAN; + /* Calculate size with optimal redzone. */ + optimal_size = cache->object_size + optimal_redzone(cache->object_size); + /* Limit it with KMALLOC_MAX_SIZE (relevant for SLAB only). */ + if (optimal_size > KMALLOC_MAX_SIZE) + optimal_size = KMALLOC_MAX_SIZE; + /* Use optimal size if the size with added metas is not large enough. */ + if (*size < optimal_size) + *size = optimal_size; } size_t __kasan_metadata_size(struct kmem_cache *cache) @@ -187,15 +214,21 @@ size_t __kasan_metadata_size(struct kmem_cache *cache) struct kasan_alloc_meta *kasan_get_alloc_meta(struct kmem_cache *cache, const void *object) { + if (!cache->kasan_info.alloc_meta_offset) + return NULL; return kasan_reset_tag(object) + cache->kasan_info.alloc_meta_offset; } +#ifdef CONFIG_KASAN_GENERIC struct kasan_free_meta *kasan_get_free_meta(struct kmem_cache *cache, const void *object) { BUILD_BUG_ON(sizeof(struct kasan_free_meta) > 32); + if (cache->kasan_info.free_meta_offset == KASAN_NO_FREE_META) + return NULL; return kasan_reset_tag(object) + cache->kasan_info.free_meta_offset; } +#endif void __kasan_poison_slab(struct page *page) { @@ -272,11 +305,9 @@ void * __must_check __kasan_init_slab_obj(struct kmem_cache *cache, struct kasan_alloc_meta *alloc_meta; if (kasan_stack_collection_enabled()) { - if (!(cache->flags & SLAB_KASAN)) - return (void *)object; - alloc_meta = kasan_get_alloc_meta(cache, object); - __memset(alloc_meta, 0, sizeof(*alloc_meta)); + if (alloc_meta) + __memset(alloc_meta, 0, sizeof(*alloc_meta)); } /* Tag is ignored in set_tag() without CONFIG_KASAN_SW/HW_TAGS */ @@ -318,15 +349,12 @@ static bool ____kasan_slab_free(struct kmem_cache *cache, void *object, if (!kasan_stack_collection_enabled()) return false; - if ((IS_ENABLED(CONFIG_KASAN_GENERIC) && !quarantine) || - unlikely(!(cache->flags & SLAB_KASAN))) + if ((IS_ENABLED(CONFIG_KASAN_GENERIC) && !quarantine)) return false; kasan_set_free_info(cache, object, tag); - quarantine_put(cache, object); - - return IS_ENABLED(CONFIG_KASAN_GENERIC); + return quarantine_put(cache, object); } bool __kasan_slab_free(struct kmem_cache *cache, void *object, unsigned long ip) @@ -359,7 +387,11 @@ void __kasan_slab_free_mempool(void *ptr, unsigned long ip) static void set_alloc_info(struct kmem_cache *cache, void *object, gfp_t flags) { - kasan_set_track(&kasan_get_alloc_meta(cache, object)->alloc_track, flags); + struct kasan_alloc_meta *alloc_meta; + + alloc_meta = kasan_get_alloc_meta(cache, object); + if (alloc_meta) + kasan_set_track(&alloc_meta->alloc_track, flags); } static void *____kasan_kmalloc(struct kmem_cache *cache, const void *object, @@ -389,7 +421,7 @@ static void *____kasan_kmalloc(struct kmem_cache *cache, const void *object, poison_range((void *)redzone_start, redzone_end - redzone_start, KASAN_KMALLOC_REDZONE); - if (kasan_stack_collection_enabled() && (cache->flags & SLAB_KASAN)) + if (kasan_stack_collection_enabled()) set_alloc_info(cache, (void *)object, flags); return set_tag(object, tag); diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index 9c6b77f8c4a4..157df6c762a4 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -338,10 +338,10 @@ void kasan_record_aux_stack(void *addr) cache = page->slab_cache; object = nearest_obj(cache, page, addr); alloc_meta = kasan_get_alloc_meta(cache, object); + if (!alloc_meta) + return; - /* - * record the last two call_rcu() call stacks. - */ + /* Record the last two call_rcu() call stacks. */ alloc_meta->aux_stack[1] = alloc_meta->aux_stack[0]; alloc_meta->aux_stack[0] = kasan_save_stack(GFP_NOWAIT); } @@ -352,11 +352,11 @@ void kasan_set_free_info(struct kmem_cache *cache, struct kasan_free_meta *free_meta; free_meta = kasan_get_free_meta(cache, object); - kasan_set_track(&free_meta->free_track, GFP_NOWAIT); + if (!free_meta) + return; - /* - * the object was freed and has free track set - */ + kasan_set_track(&free_meta->free_track, GFP_NOWAIT); + /* The object was freed and has free track set. */ *(u8 *)kasan_mem_to_shadow(object) = KASAN_KMALLOC_FREETRACK; } @@ -365,5 +365,6 @@ struct kasan_track *kasan_get_free_track(struct kmem_cache *cache, { if (*(u8 *)kasan_mem_to_shadow(object) != KASAN_KMALLOC_FREETRACK) return NULL; + /* Free meta must be present with KASAN_KMALLOC_FREETRACK. */ return &kasan_get_free_meta(cache, object)->free_track; } diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c index 30ce88935e9d..c91f2c06ecb5 100644 --- a/mm/kasan/hw_tags.c +++ b/mm/kasan/hw_tags.c @@ -187,7 +187,8 @@ void kasan_set_free_info(struct kmem_cache *cache, struct kasan_alloc_meta *alloc_meta; alloc_meta = kasan_get_alloc_meta(cache, object); - kasan_set_track(&alloc_meta->free_track[0], GFP_NOWAIT); + if (alloc_meta) + kasan_set_track(&alloc_meta->free_track[0], GFP_NOWAIT); } struct kasan_track *kasan_get_free_track(struct kmem_cache *cache, @@ -196,5 +197,8 @@ struct kasan_track *kasan_get_free_track(struct kmem_cache *cache, struct kasan_alloc_meta *alloc_meta; alloc_meta = kasan_get_alloc_meta(cache, object); + if (!alloc_meta) + return NULL; + return &alloc_meta->free_track[0]; } diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index d01a5ac34f70..725a472e8ea7 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -156,20 +156,31 @@ struct kasan_alloc_meta { struct qlist_node { struct qlist_node *next; }; + +/* + * Generic mode either stores free meta in the object itself or in the redzone + * after the object. In the former case free meta offset is 0, in the latter + * case it has some sane value smaller than INT_MAX. Use INT_MAX as free meta + * offset when free meta isn't present. + */ +#define KASAN_NO_FREE_META INT_MAX + struct kasan_free_meta { +#ifdef CONFIG_KASAN_GENERIC /* This field is used while the object is in the quarantine. * Otherwise it might be used for the allocator freelist. */ struct qlist_node quarantine_link; -#ifdef CONFIG_KASAN_GENERIC struct kasan_track free_track; #endif }; struct kasan_alloc_meta *kasan_get_alloc_meta(struct kmem_cache *cache, const void *object); +#ifdef CONFIG_KASAN_GENERIC struct kasan_free_meta *kasan_get_free_meta(struct kmem_cache *cache, const void *object); +#endif #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) @@ -234,11 +245,11 @@ struct kasan_track *kasan_get_free_track(struct kmem_cache *cache, #if defined(CONFIG_KASAN_GENERIC) && \ (defined(CONFIG_SLAB) || defined(CONFIG_SLUB)) -void quarantine_put(struct kmem_cache *cache, void *object); +bool quarantine_put(struct kmem_cache *cache, void *object); void quarantine_reduce(void); void quarantine_remove_cache(struct kmem_cache *cache); #else -static inline void quarantine_put(struct kmem_cache *cache, void *object) { } +static inline bool quarantine_put(struct kmem_cache *cache, void *object) { return false; } static inline void quarantine_reduce(void) { } static inline void quarantine_remove_cache(struct kmem_cache *cache) { } #endif diff --git a/mm/kasan/quarantine.c b/mm/kasan/quarantine.c index 0da3d37e1589..a598c3514e1a 100644 --- a/mm/kasan/quarantine.c +++ b/mm/kasan/quarantine.c @@ -135,7 +135,12 @@ static void qlink_free(struct qlist_node *qlink, struct kmem_cache *cache) if (IS_ENABLED(CONFIG_SLAB)) local_irq_save(flags); + /* + * As the object now gets freed from the quaratine, assume that its + * free track is no longer valid. + */ *(u8 *)kasan_mem_to_shadow(object) = KASAN_KMALLOC_FREE; + ___cache_free(cache, object, _THIS_IP_); if (IS_ENABLED(CONFIG_SLAB)) @@ -161,13 +166,20 @@ static void qlist_free_all(struct qlist_head *q, struct kmem_cache *cache) qlist_init(q); } -void quarantine_put(struct kmem_cache *cache, void *object) +bool quarantine_put(struct kmem_cache *cache, void *object) { unsigned long flags; struct qlist_head *q; struct qlist_head temp = QLIST_INIT; struct kasan_free_meta *meta = kasan_get_free_meta(cache, object); + /* + * If there's no metadata for this object, don't put it into + * quarantine. + */ + if (!meta) + return false; + /* * Note: irq must be disabled until after we move the batch to the * global quarantine. Otherwise quarantine_remove_cache() can miss @@ -200,6 +212,8 @@ void quarantine_put(struct kmem_cache *cache, void *object) } local_irq_restore(flags); + + return true; } void quarantine_reduce(void) diff --git a/mm/kasan/report.c b/mm/kasan/report.c index ffa6076b1710..8b6656d47983 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -168,32 +168,35 @@ static void describe_object_addr(struct kmem_cache *cache, void *object, static void describe_object_stacks(struct kmem_cache *cache, void *object, const void *addr, u8 tag) { - struct kasan_alloc_meta *alloc_meta = kasan_get_alloc_meta(cache, object); - - if (cache->flags & SLAB_KASAN) { - struct kasan_track *free_track; + struct kasan_alloc_meta *alloc_meta; + struct kasan_track *free_track; + alloc_meta = kasan_get_alloc_meta(cache, object); + if (alloc_meta) { print_track(&alloc_meta->alloc_track, "Allocated"); pr_err("\n"); - free_track = kasan_get_free_track(cache, object, tag); - if (free_track) { - print_track(free_track, "Freed"); - pr_err("\n"); - } + } + + free_track = kasan_get_free_track(cache, object, tag); + if (free_track) { + print_track(free_track, "Freed"); + pr_err("\n"); + } #ifdef CONFIG_KASAN_GENERIC - if (alloc_meta->aux_stack[0]) { - pr_err("Last call_rcu():\n"); - print_stack(alloc_meta->aux_stack[0]); - pr_err("\n"); - } - if (alloc_meta->aux_stack[1]) { - pr_err("Second to last call_rcu():\n"); - print_stack(alloc_meta->aux_stack[1]); - pr_err("\n"); - } -#endif + if (!alloc_meta) + return; + if (alloc_meta->aux_stack[0]) { + pr_err("Last call_rcu():\n"); + print_stack(alloc_meta->aux_stack[0]); + pr_err("\n"); } + if (alloc_meta->aux_stack[1]) { + pr_err("Second to last call_rcu():\n"); + print_stack(alloc_meta->aux_stack[1]); + pr_err("\n"); + } +#endif } static void describe_object(struct kmem_cache *cache, void *object, diff --git a/mm/kasan/report_sw_tags.c b/mm/kasan/report_sw_tags.c index 7604b46239d4..1b026793ad57 100644 --- a/mm/kasan/report_sw_tags.c +++ b/mm/kasan/report_sw_tags.c @@ -48,9 +48,12 @@ const char *get_bug_type(struct kasan_access_info *info) object = nearest_obj(cache, page, (void *)addr); alloc_meta = kasan_get_alloc_meta(cache, object); - for (i = 0; i < KASAN_NR_FREE_STACKS; i++) - if (alloc_meta->free_pointer_tag[i] == tag) - return "use-after-free"; + if (alloc_meta) { + for (i = 0; i < KASAN_NR_FREE_STACKS; i++) { + if (alloc_meta->free_pointer_tag[i] == tag) + return "use-after-free"; + } + } return "out-of-bounds"; } diff --git a/mm/kasan/sw_tags.c b/mm/kasan/sw_tags.c index e17de2619bbf..5dcd830805b2 100644 --- a/mm/kasan/sw_tags.c +++ b/mm/kasan/sw_tags.c @@ -170,6 +170,8 @@ void kasan_set_free_info(struct kmem_cache *cache, u8 idx = 0; alloc_meta = kasan_get_alloc_meta(cache, object); + if (!alloc_meta) + return; #ifdef CONFIG_KASAN_SW_TAGS_IDENTIFY idx = alloc_meta->free_track_idx; @@ -187,6 +189,8 @@ struct kasan_track *kasan_get_free_track(struct kmem_cache *cache, int i = 0; alloc_meta = kasan_get_alloc_meta(cache, object); + if (!alloc_meta) + return NULL; #ifdef CONFIG_KASAN_SW_TAGS_IDENTIFY for (i = 0; i < KASAN_NR_FREE_STACKS; i++) { From patchwork Mon Nov 23 20:14:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11926705 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7BA84C388F9 for ; Mon, 23 Nov 2020 20:40:05 +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 0A86220721 for ; Mon, 23 Nov 2020 20:40:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="RySbyPV6"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Q7pV78bn"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="Va6STH1a" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0A86220721 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+linux-arm-kernel=archiver.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=NJ/MSjv1P9dQvVDbCBuOym1GjqOiZPU9ABIgJ62h6EE=; b=RySbyPV6rK85YZ+tx0gqeiI/i fSjy+Z7qqAT4qQvnQ9V/GAYIVvTkl1kwRvlJby/VicffiMV56ConPGIzWh5KxzffbarV6TuDepVOz Ibzgcf4/qHuWZOJgyCGz6SQ43Me78fgXyJPn6FdAHgg7VtZyLIWCe4ndc50iU/WId1d8gNWSV/zTz bKsOmjYCt8UEf+xrXf1oLBJuurzxAMYoRyZ1QOpiSAlsiy8LFpR0HvgMyVzaQmPr1S4mDmj6ZfF1W XM5lvhWlyZ4NnUPQkCKlCCEj2Aw4Qih/qx0iEOwWallFgRjJqfdm5RWQXGOMGTTDCD0vCkmWS7Sl4 8EmgYz8kQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIcH-0004Ze-Ek; Mon, 23 Nov 2020 20:39:17 +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 1khIO2-0006KM-P1 for linux-arm-kernel@merlin.infradead.org; Mon, 23 Nov 2020 20:24:34 +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=jlSh18JA+tyc0YTMYNGOzncWOn17Ui2VWegewVhQQAI=; b=Q7pV78bncCTa3GroED4vJlpL75 7FoS4oPDHxQmtMK4zqiP982xFXinoZsbAAIIpVMWZoddDKua6bDI1cxkCRvwIj7xlfD0oIoT+yoCr SZsxxjcnFPUusZWDr8rjuA3zitocffIWFCHNqnGaoXoXgtBCuY2qZQRoPxZp5sBrbpgExYxSo/PkT Za3cLFB2zrZv/2j4G5rflLVR0nfc7mDUVISKxmk6Ha2KQmtLNH27MZs2fxkZKP4eJsycR/VcNqOQc vAtk/OkMWfvhqhX+kannezBz6lDOUT0DXnW74KxQDxzYdrqAIcjxto/JkcWt9rDbu077zMTHq5hi/ 9Nu9RLNQ==; Received: from mail-qt1-x84a.google.com ([2607:f8b0:4864:20::84a]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIFU-0006PT-JS for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2020 20:15:51 +0000 Received: by mail-qt1-x84a.google.com with SMTP id y5so14465900qtb.13 for ; Mon, 23 Nov 2020 12:15:39 -0800 (PST) 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=jlSh18JA+tyc0YTMYNGOzncWOn17Ui2VWegewVhQQAI=; b=Va6STH1aX4wYunU0iMuz4BvFHnwWptWCMWXmt/xofeqd3owQuGpwtvjYit4rl6mlW2 hhm5iDeTzV3r8r1qtqi5fdwTQs/TSfD/bCoDouUVq/mqil3HrggfywpVxpheL6ZEWpIl zDXMe40hvq88yS3PuIjxsWaxgjZyKl/B05KVNcChbJkk49tAW2TDEREdWyEig5SkLtvs 5K5C3H1Yizp2NapbQ8UOeKQZdiMwc5N0OfbB8Dc3yzVaEvt/fAhl005CJycepaLAgkY1 zyVIgqpv8eZepV66RBshT0P3UBs6jkxe5tAKTYnNSfeugX8uOp+AF7kVSkrFVfKZ4WBw kmbQ== 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=jlSh18JA+tyc0YTMYNGOzncWOn17Ui2VWegewVhQQAI=; b=pqu6hRp0ka7PDlq0j4EUb/7MT6hZuuD08KHE5P+7Qt9p/A/n+kdDASlxBidDsBPrUs PrA9/7B1dgZGghoIApEjaGSdYVGXz0WVQL2vqDk2impiljYkzb9ftFSKqnVp1kR+Xx2j wwvmzc+425yMqecHnMo6jZojrjd/O1JWbhpzzd85wZqgMvXCi6QGHew/dWUw47NjiyW4 p/rAKDcryG+C2ggzpoMclaC0lUi+ud7j382gGFwaIQGghnIQnl0N5mVFKbhd3EH0EFi9 me33KDxtj2Q3w7pqOwialEUNS73lHyVHEIyqBc2C9kCXkg/UT/sOFnsUWksg7wFO7Px0 neag== X-Gm-Message-State: AOAM531J8hlIfLq9JuIv38ct0jHJQM9Jm24AnPtec3ea2IoZZGv15EGQ sg6ThX3jSJxlyV4DhJ+KUZJBheSTILoxB7Qu X-Google-Smtp-Source: ABdhPJxiz/yK/mWtOWOXNmT0lUD67I1dkQtTBgb4Q9Y4cmrtA6Kl6akYtyMC6LEbXAx67mmzam5gwyx0dWQN53nE X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a0c:804a:: with SMTP id 68mr1172222qva.1.1606162536399; Mon, 23 Nov 2020 12:15:36 -0800 (PST) Date: Mon, 23 Nov 2020 21:14:48 +0100 In-Reply-To: Message-Id: <37497e940bfd4b32c0a93a702a9ae4cf061d5392.1606162397.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH mm v4 18/19] kasan, mm: allow cache merging with no metadata From: Andrey Konovalov To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201123_201545_123470_2F0DE1B7 X-CRM114-Status: GOOD ( 16.25 ) 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-arm-kernel@lists.infradead.org, Marco Elver , Catalin Marinas , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Konovalov , Andrey Ryabinin , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The reason cache merging is disabled with KASAN is because KASAN puts its metadata right after the allocated object. When the merged caches have slightly different sizes, the metadata ends up in different places, which KASAN doesn't support. It might be possible to adjust the metadata allocation algorithm and make it friendly to the cache merging code. Instead this change takes a simpler approach and allows merging caches when no metadata is present. Which is the case for hardware tag-based KASAN with kasan.mode=prod. Co-developed-by: Vincenzo Frascino Signed-off-by: Vincenzo Frascino Signed-off-by: Andrey Konovalov Reviewed-by: Dmitry Vyukov Reviewed-by: Marco Elver Link: https://linux-review.googlesource.com/id/Ia114847dfb2244f297d2cb82d592bf6a07455dba --- include/linux/kasan.h | 21 +++++++++++++++++++-- mm/kasan/common.c | 11 +++++++++++ mm/slab_common.c | 3 ++- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 2610438120ce..83860aa4e89c 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -81,17 +81,30 @@ struct kasan_cache { }; #ifdef CONFIG_KASAN_HW_TAGS + DECLARE_STATIC_KEY_FALSE(kasan_flag_enabled); + static __always_inline bool kasan_enabled(void) { return static_branch_likely(&kasan_flag_enabled); } -#else + +#else /* CONFIG_KASAN_HW_TAGS */ + static inline bool kasan_enabled(void) { return true; } -#endif + +#endif /* CONFIG_KASAN_HW_TAGS */ + +slab_flags_t __kasan_never_merge(void); +static __always_inline slab_flags_t kasan_never_merge(void) +{ + if (kasan_enabled()) + return __kasan_never_merge(); + return 0; +} void __kasan_unpoison_range(const void *addr, size_t size); static __always_inline void kasan_unpoison_range(const void *addr, size_t size) @@ -238,6 +251,10 @@ static inline bool kasan_enabled(void) { return false; } +static inline slab_flags_t kasan_never_merge(void) +{ + return 0; +} static inline void kasan_unpoison_range(const void *address, size_t size) {} static inline void kasan_alloc_pages(struct page *page, unsigned int order) {} static inline void kasan_free_pages(struct page *page, unsigned int order) {} diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 249ccba1ecf5..da79f340f3a6 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -87,6 +87,17 @@ asmlinkage void kasan_unpoison_task_stack_below(const void *watermark) } #endif /* CONFIG_KASAN_STACK */ +/* + * Only allow cache merging when stack collection is disabled and no metadata + * is present. + */ +slab_flags_t __kasan_never_merge(void) +{ + if (kasan_stack_collection_enabled()) + return SLAB_KASAN; + return 0; +} + void __kasan_alloc_pages(struct page *page, unsigned int order) { u8 tag; diff --git a/mm/slab_common.c b/mm/slab_common.c index 0b5ae1819a8b..075b23ce94ec 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -54,7 +55,7 @@ static DECLARE_WORK(slab_caches_to_rcu_destroy_work, */ #define SLAB_NEVER_MERGE (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER | \ SLAB_TRACE | SLAB_TYPESAFE_BY_RCU | SLAB_NOLEAKTRACE | \ - SLAB_FAILSLAB | SLAB_KASAN) + SLAB_FAILSLAB | kasan_never_merge()) #define SLAB_MERGE_SAME (SLAB_RECLAIM_ACCOUNT | SLAB_CACHE_DMA | \ SLAB_CACHE_DMA32 | SLAB_ACCOUNT) From patchwork Mon Nov 23 20:14:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11926707 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DFBDC63697 for ; Mon, 23 Nov 2020 20:40:40 +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 19957204FD for ; Mon, 23 Nov 2020 20:40:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="TZ6AFAzk"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="A+QcfVId"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="uqQ8B6Ep" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 19957204FD 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+linux-arm-kernel=archiver.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=WE2JfGv0j6gSaLznuBGAC+xrLsKj7YHN1nFpXILa0Ak=; b=TZ6AFAzkSrh53IOw/CtURtEgV 0GuYlKhpYxbhMWhDtF+gPnhE1HVQKCCxLfVAzqE5u3/2L/ozrsBqKYz1aY2MRGeK1l1A2OpBLfblG Nqcsd+X+p7/tj0G4Kh5lLeflN31vIG9qJtNplXhfEgWXGX+R4ugWGOoiyfZmKuvKzSn1Da8ZI4qp4 B6BYXr1a4NVmxCfup3BUSoNxgxvsENrlic+bL1ZkZOELUCzSonG+SZu3wNVaYgcaXb/soNm5k2Qtu IRnh2tN2lKJ409cGnEVFWRosAb6WkiLUaMKgs6KcshWt3OgLKdePaUqnuEQKMeluC5AeEoIJx1OO9 ylE2FDXOw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIbm-0004LL-Uq; Mon, 23 Nov 2020 20:38:47 +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 1khINz-0006KM-MU for linux-arm-kernel@merlin.infradead.org; Mon, 23 Nov 2020 20:24:31 +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=TwVlqrzbK9OEiBxZdI+rhahWnVEZAm2Aq662xuQkBRk=; b=A+QcfVIdtHdOqf9rg4F8RqLB2F Km70FUk0h/KX7/iwEgUfW3/O15JMbWY4OLsFA8Wxn4Eo4qUyYlHxkbqiwrqZuLTYSV4FVAiJdw6tQ nWTgZi98c8rt1tB+6ciciz19vKaBy4bJ26+QbrHk15t+VaeREUpY4cBlPRUSX5Zq5ErE4XHt1cLPM Hxc6+p0mPxysnR9itYmVjYgZHa7+81UHKsXe2DfJKuU8aaXNQxT6PuK32uC2oeVKIfAvw+g0Vdt8p ajM4j/fgXL/P4dvqPzz8N6MKP82or22Vt9T0ry18DX2g9XHGYwLn1uHbQVClCnMDTVXhkaJx+zERV tpcbti5A==; 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 1khIFS-0006Pf-MD for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2020 20:15:52 +0000 Received: by mail-wm1-x349.google.com with SMTP id k128so153556wme.7 for ; Mon, 23 Nov 2020 12:15:41 -0800 (PST) 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=TwVlqrzbK9OEiBxZdI+rhahWnVEZAm2Aq662xuQkBRk=; b=uqQ8B6EpC4T/2lxNybU341nD8fDdjhKpzUTwU2e4ferVQvVepB8uQNU2REwbGUy3g/ 0qEO4ZEIsopPWv+M219KKOUkpTeF+nFBz6mhTKTgpfsz+KiCXW2q1DaixzqU9/Orv1ii e68Qj2srZr5CnCQjrrhFoLLX175ot/Cg8byb19aDBZHbcGW3dOK6STudnvvvGpXTd/GO VmSzfQcO6K1weVP7Gb1UIzqehrI+05zH0cG9++TTKvuLmBv30gkQzAbs0I/QorOyy24h czoWPjP/oAvCela52mxB6a3Sj1EhfE4zW+O55twy12yPp13BdLz7wx5CsRr27AEWlWIu gzHQ== 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=TwVlqrzbK9OEiBxZdI+rhahWnVEZAm2Aq662xuQkBRk=; b=NJbQ+0XOT3d0eTFTV9PxmAcqGTrrK37QjCBqG9Ya7ILRiAbK1lQGmA9K+xs6ps6iY6 slm8zipAjNiVNBOfbZNg0D/2uIT1yfmPNDBMmg8AkUF8S2K4qCtb3tNPaJVX8XoKMdo+ 0NfnoRRGWM5tVnwx4VyYTxkEBEDcLLkirVZPdrZT8LBzSnsiJ3wBF9d1ylSidKlc8QzD Mr07cRE1L/vtEzsDexf2F2LFH5gvKScuknFayOOqyD9kMpeonUcrCTMAzWHy2Yu5X9jj o28perRoUxz1VdihpR4oVRK+BUmnP9WdoHx+fNq2me+F3PlCHO5ZpKxMCzn1F2sdtHe+ EsAg== X-Gm-Message-State: AOAM531XPTZcTZml830UXJNZT7inRaW9FhJvi/NHzcshvPKrWqA8YAkE f9y/Mcgl8jFfrYNeQnXcyBsyp9rBllZvNtya X-Google-Smtp-Source: ABdhPJyxAaUGQRYsH2bnvCcaL3nzl/2XkJ+Q0PHrKcJNhSF+GngeQ1mFM6Gpvx+ob7yFchVxOiWIZqS0Y3OfMugd X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a7b:cf09:: with SMTP id l9mr646052wmg.54.1606162538948; Mon, 23 Nov 2020 12:15:38 -0800 (PST) Date: Mon, 23 Nov 2020 21:14:49 +0100 In-Reply-To: Message-Id: <748daf013e17d925b0fe00c1c3b5dce726dd2430.1606162397.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH mm v4 19/19] kasan: update documentation From: Andrey Konovalov To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201123_201543_155629_025C2B76 X-CRM114-Status: GOOD ( 34.63 ) 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-arm-kernel@lists.infradead.org, Marco Elver , Catalin Marinas , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Konovalov , Andrey Ryabinin , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This change updates KASAN documentation to reflect the addition of boot parameters and also reworks and clarifies some of the existing sections, in particular: defines what a memory granule is, mentions quarantine, makes Kunit section more readable. Signed-off-by: Andrey Konovalov Reviewed-by: Dmitry Vyukov Reviewed-by: Marco Elver Link: https://linux-review.googlesource.com/id/Ib1f83e91be273264b25f42b04448ac96b858849f --- Documentation/dev-tools/kasan.rst | 186 +++++++++++++++++++----------- 1 file changed, 116 insertions(+), 70 deletions(-) diff --git a/Documentation/dev-tools/kasan.rst b/Documentation/dev-tools/kasan.rst index ffbae8ce5748..0d5d77919b1a 100644 --- a/Documentation/dev-tools/kasan.rst +++ b/Documentation/dev-tools/kasan.rst @@ -4,8 +4,9 @@ The Kernel Address Sanitizer (KASAN) Overview -------- -KernelAddressSANitizer (KASAN) is a dynamic memory error detector designed to -find out-of-bound and use-after-free bugs. KASAN has three modes: +KernelAddressSANitizer (KASAN) is a dynamic memory safety error detector +designed to find out-of-bound and use-after-free bugs. KASAN has three modes: + 1. generic KASAN (similar to userspace ASan), 2. software tag-based KASAN (similar to userspace HWASan), 3. hardware tag-based KASAN (based on hardware memory tagging). @@ -39,23 +40,13 @@ CONFIG_KASAN_INLINE. Outline and inline are compiler instrumentation types. The former produces smaller binary while the latter is 1.1 - 2 times faster. Both software KASAN modes work with both SLUB and SLAB memory allocators, -hardware tag-based KASAN currently only support SLUB. -For better bug detection and nicer reporting, enable CONFIG_STACKTRACE. +while the hardware tag-based KASAN currently only support SLUB. + +For better error reports that include stack traces, enable CONFIG_STACKTRACE. To augment reports with last allocation and freeing stack of the physical page, it is recommended to enable also CONFIG_PAGE_OWNER and boot with page_owner=on. -To disable instrumentation for specific files or directories, add a line -similar to the following to the respective kernel Makefile: - -- For a single file (e.g. main.o):: - - KASAN_SANITIZE_main.o := n - -- For all files in one directory:: - - KASAN_SANITIZE := n - Error reports ~~~~~~~~~~~~~ @@ -140,22 +131,75 @@ freed (in case of a use-after-free bug report). Next comes a description of the accessed slab object and information about the accessed memory page. In the last section the report shows memory state around the accessed address. -Reading this part requires some understanding of how KASAN works. - -The state of each 8 aligned bytes of memory is encoded in one shadow byte. -Those 8 bytes can be accessible, partially accessible, freed or be a redzone. -We use the following encoding for each shadow byte: 0 means that all 8 bytes -of the corresponding memory region are accessible; number N (1 <= N <= 7) means -that the first N bytes are accessible, and other (8 - N) bytes are not; -any negative value indicates that the entire 8-byte word is inaccessible. -We use different negative values to distinguish between different kinds of -inaccessible memory like redzones or freed memory (see mm/kasan/kasan.h). +Internally KASAN tracks memory state separately for each memory granule, which +is either 8 or 16 aligned bytes depending on KASAN mode. Each number in the +memory state section of the report shows the state of one of the memory +granules that surround the accessed address. + +For generic KASAN the size of each memory granule is 8. The state of each +granule is encoded in one shadow byte. Those 8 bytes can be accessible, +partially accessible, freed or be a part of a redzone. KASAN uses the following +encoding for each shadow byte: 0 means that all 8 bytes of the corresponding +memory region are accessible; number N (1 <= N <= 7) means that the first N +bytes are accessible, and other (8 - N) bytes are not; any negative value +indicates that the entire 8-byte word is inaccessible. KASAN uses different +negative values to distinguish between different kinds of inaccessible memory +like redzones or freed memory (see mm/kasan/kasan.h). In the report above the arrows point to the shadow byte 03, which means that the accessed address is partially accessible. For tag-based KASAN this last report section shows the memory tags around the -accessed address (see Implementation details section). +accessed address (see `Implementation details`_ section). + +Boot parameters +~~~~~~~~~~~~~~~ + +Hardware tag-based KASAN mode (see the section about different mode below) is +intended for use in production as a security mitigation. Therefore it supports +boot parameters that allow to disable KASAN competely or otherwise control +particular KASAN features. + +The things that can be controlled are: + +1. Whether KASAN is enabled at all. +2. Whether KASAN collects and saves alloc/free stacks. +3. Whether KASAN panics on a detected bug or not. + +The ``kasan.mode`` boot parameter allows to choose one of three main modes: + +- ``kasan.mode=off`` - KASAN is disabled, no tag checks are performed +- ``kasan.mode=prod`` - only essential production features are enabled +- ``kasan.mode=full`` - all KASAN features are enabled + +The chosen mode provides default control values for the features mentioned +above. However it's also possible to override the default values by providing: + +- ``kasan.stacktrace=off`` or ``=on`` - enable alloc/free stack collection + (default: ``on`` for ``mode=full``, + otherwise ``off``) +- ``kasan.fault=report`` or ``=panic`` - only print KASAN report or also panic + (default: ``report``) + +If ``kasan.mode`` parameter is not provided, it defaults to ``full`` when +``CONFIG_DEBUG_KERNEL`` is enabled, and to ``prod`` otherwise. + +For developers +~~~~~~~~~~~~~~ + +Software KASAN modes use compiler instrumentation to insert validity checks. +Such instrumentation might be incompatible with some part of the kernel, and +therefore needs to be disabled. To disable instrumentation for specific files +or directories, add a line similar to the following to the respective kernel +Makefile: + +- For a single file (e.g. main.o):: + + KASAN_SANITIZE_main.o := n + +- For all files in one directory:: + + KASAN_SANITIZE := n Implementation details @@ -164,10 +208,10 @@ Implementation details Generic KASAN ~~~~~~~~~~~~~ -From a high level, our approach to memory error detection is similar to that -of kmemcheck: use shadow memory to record whether each byte of memory is safe -to access, and use compile-time instrumentation to insert checks of shadow -memory on each memory access. +From a high level perspective, KASAN's approach to memory error detection is +similar to that of kmemcheck: use shadow memory to record whether each byte of +memory is safe to access, and use compile-time instrumentation to insert checks +of shadow memory on each memory access. Generic KASAN dedicates 1/8th of kernel memory to its shadow memory (e.g. 16TB to cover 128TB on x86_64) and uses direct mapping with a scale and offset to @@ -194,7 +238,10 @@ function calls GCC directly inserts the code to check the shadow memory. This option significantly enlarges kernel but it gives x1.1-x2 performance boost over outline instrumented kernel. -Generic KASAN prints up to 2 call_rcu() call stacks in reports, the last one +Generic KASAN is the only mode that delays the reuse of freed object via +quarantine (see mm/kasan/quarantine.c for implementation). + +Generic KASAN prints up to two call_rcu() call stacks in reports, the last one and the second to last. Software tag-based KASAN @@ -304,15 +351,15 @@ therefore be wasteful. Furthermore, to ensure that different mappings use different shadow pages, mappings would have to be aligned to ``KASAN_GRANULE_SIZE * PAGE_SIZE``. -Instead, we share backing space across multiple mappings. We allocate +Instead, KASAN shares backing space across multiple mappings. It allocates 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 +KASAN hooks into the vmap infrastructure to lazily clean up unused shadow memory. -To avoid the difficulties around swapping mappings around, we expect +To avoid the difficulties around swapping mappings around, KASAN expects that the part of the shadow region that covers the vmalloc space will not be covered by the early shadow page, but will be left unmapped. This will require changes in arch-specific code. @@ -323,24 +370,31 @@ architectures that do not have a fixed module region. CONFIG_KASAN_KUNIT_TEST & CONFIG_TEST_KASAN_MODULE -------------------------------------------------- -``CONFIG_KASAN_KUNIT_TEST`` utilizes the KUnit Test Framework for testing. -This means each test focuses on a small unit of functionality and -there are a few ways these tests can be run. +KASAN tests consist on two parts: + +1. Tests that are integrated with the KUnit Test Framework. Enabled with +``CONFIG_KASAN_KUNIT_TEST``. These tests can be run and partially verified +automatically in a few different ways, see the instructions below. -Each test will print the KASAN report if an error is detected and then -print the number of the test and the status of the test: +2. Tests that are currently incompatible with KUnit. Enabled with +``CONFIG_TEST_KASAN_MODULE`` and can only be run as a module. These tests can +only be verified manually, by loading the kernel module and inspecting the +kernel log for KASAN reports. -pass:: +Each KUnit-compatible KASAN test prints a KASAN report if an error is detected. +Then the test prints its number and status. + +When a test passes:: ok 28 - kmalloc_double_kzfree -or, if kmalloc failed:: +When a test fails due to a failed ``kmalloc``:: # kmalloc_large_oob_right: ASSERTION FAILED at lib/test_kasan.c:163 Expected ptr is not null, but is not ok 4 - kmalloc_large_oob_right -or, if a KASAN report was expected, but not found:: +When a test fails due to a missing KASAN report:: # kmalloc_double_kzfree: EXPECTATION FAILED at lib/test_kasan.c:629 Expected kasan_data->report_expected == kasan_data->report_found, but @@ -348,46 +402,38 @@ or, if a KASAN report was expected, but not found:: kasan_data->report_found == 0 not ok 28 - kmalloc_double_kzfree -All test statuses are tracked as they run and an overall status will -be printed at the end:: +At the end the cumulative status of all KASAN tests is printed. On success:: ok 1 - kasan -or:: +Or, if one of the tests failed:: not ok 1 - kasan -(1) Loadable Module -~~~~~~~~~~~~~~~~~~~~ + +There are a few ways to run KUnit-compatible KASAN tests. + +1. Loadable module +~~~~~~~~~~~~~~~~~~ With ``CONFIG_KUNIT`` enabled, ``CONFIG_KASAN_KUNIT_TEST`` can be built as -a loadable module and run on any architecture that supports KASAN -using something like insmod or modprobe. The module is called ``test_kasan``. +a loadable module and run on any architecture that supports KASAN by loading +the module with insmod or modprobe. The module is called ``test_kasan``. -(2) Built-In -~~~~~~~~~~~~~ +2. Built-In +~~~~~~~~~~~ With ``CONFIG_KUNIT`` built-in, ``CONFIG_KASAN_KUNIT_TEST`` can be built-in -on any architecure that supports KASAN. These and any other KUnit -tests enabled will run and print the results at boot as a late-init -call. +on any architecure that supports KASAN. These and any other KUnit tests enabled +will run and print the results at boot as a late-init call. -(3) Using kunit_tool -~~~~~~~~~~~~~~~~~~~~~ +3. Using kunit_tool +~~~~~~~~~~~~~~~~~~~ -With ``CONFIG_KUNIT`` and ``CONFIG_KASAN_KUNIT_TEST`` built-in, we can also -use kunit_tool to see the results of these along with other KUnit -tests in a more readable way. This will not print the KASAN reports -of tests that passed. Use `KUnit documentation `_ for more up-to-date -information on kunit_tool. +With ``CONFIG_KUNIT`` and ``CONFIG_KASAN_KUNIT_TEST`` built-in, it's also +possible use ``kunit_tool`` to see the results of these and other KUnit tests +in a more readable way. This will not print the KASAN reports of the tests that +passed. Use `KUnit documentation `_ +for more up-to-date information on ``kunit_tool``. .. _KUnit: https://www.kernel.org/doc/html/latest/dev-tools/kunit/index.html - -``CONFIG_TEST_KASAN_MODULE`` is a set of KASAN tests that could not be -converted to KUnit. These tests can be run only as a module with -``CONFIG_TEST_KASAN_MODULE`` built as a loadable module and -``CONFIG_KASAN`` built-in. The type of error expected and the -function being run is printed before the expression expected to give -an error. Then the error is printed, if found, and that test -should be interpretted to pass only if the error was the one expected -by the test.