From patchwork Thu Jan 14 19:36:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12020741 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=-17.0 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 4EA75C433DB for ; Thu, 14 Jan 2021 19:41: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 822012343B for ; Thu, 14 Jan 2021 19:41:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 822012343B 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=8XolGNRvNeuLV/Flfd0e9hBPazwMBtfXxjWAqbCKJ/Y=; b=rHrMFCF0gX9n35xZN0eLLsLFc ihtVwWmS18uaaBaTtBCVp9IX2HuN9wNq+JRcmh8nvQgjzOT91i1zwwkuGUVuDMZxm0VG7zA/UYWmw lkAWdeVKQVmDAqn3YkdxV2E9UY1hhimRhaQ86ojqhqh0iSFwLVJIGjvFAXVkYCPAUKNg3b6D6/Gmt ld9VObI0MSZVhZgWz8dQgcIL4l6+p8xpREfdgm1HF+hJSb0eEFGx8L6W8YxacJ3k3AjdtKW8nLDGN eKDNDi6yT2rD+MX71ELTKkb/18y8eN3I8ya9m2eKwWZq8YuBLltoxU6V7b9jufzU8tbncqAdOXmmG iWhhtJ+4Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l08SC-0004zG-2Y; Thu, 14 Jan 2021 19:38:44 +0000 Received: from mail-qt1-x849.google.com ([2607:f8b0:4864:20::849]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l08Qa-0004IN-4P for linux-arm-kernel@lists.infradead.org; Thu, 14 Jan 2021 19:37:16 +0000 Received: by mail-qt1-x849.google.com with SMTP id i1so5321667qtw.4 for ; Thu, 14 Jan 2021 11:37:01 -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=40xb9lbPD7zjMi02902hc3827F2UNMsjtXT9ahxodwY=; b=fSQSLNHoENpI0ec8evQk8rMlbFX6AnX1SFn2JpS7bY3McyjlZdC63MMgV2LuXJi3mX wCL9pP+rrMWH2haSnOQrUaobCH/BOozhFfygZJWCGFFMQT5GUbY6Dq/P932IcrenWSFw F3x4sJGHnnzQfrvAn+fUUUG4miJDGg07zJTr7qlqFAy9D5indOUbOPqzqbOicAfx5Tfm mm690UJuNFBKTc8tT9fzDeWg0PJXH61cx4Hc4sWrV9bik1cMdobTZNZEi43ELLTJAlGi RLsZyVhjAqdmCBPLam8O87CBTvhk8pvD8cbLWIydnadUyh4t11EHAIgFBZIkqw/E1nd4 jFMQ== 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=40xb9lbPD7zjMi02902hc3827F2UNMsjtXT9ahxodwY=; b=TgpchRgdH8fV++XLYmztsIhi+JVDreQuBdrTqKhlj2lPwH/seK+Is7pF4Odnd9vRsQ A0oTjtZTJqFnT6cpqvYAmRdgyTgw3dGHq/etAy1TLoE8pA1zHZMOcqOpNFJDxFo/5KdK Kwp+eWZuMPnGNMJDoGzTcHIgZeQX73izaoC8DCgjXeGej5N99dW3pYtkHxbg300++OXb 1heDoB7BJbv7Mx1ltjY2Bf47lkrYjYmR4WWyNsZW8ZXfp1HP4lnv7n5QUrhAwSWGrvIB AT8QtLIIzE5/1/Db8fPWIkGaYjuBkSWxz92btByeuwD7uuKsriBVRK6R9mMTXdg7BHY7 QxDA== X-Gm-Message-State: AOAM530cz+HTKnEmmEXz9EeYrxHKkhplZzzhPSS01HS/eyfLdE+waLIs XRZk1moDUnA7Yy3dZXWWz5iWB4g9I35p5fSA X-Google-Smtp-Source: ABdhPJydJEDTyqj8QSzBooNuNDFg7Kou+F8Lcz2o/vySqYkkn4r+L5+G5+g5Yn9t0brOix7oCtucDFNVxBsW60ui X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a0c:99c8:: with SMTP id y8mr8427012qve.35.1610653020179; Thu, 14 Jan 2021 11:37:00 -0800 (PST) Date: Thu, 14 Jan 2021 20:36:27 +0100 In-Reply-To: Message-Id: <03fae8b66a7f4b85abadc80a2d216ac4db815444.1610652890.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog Subject: [PATCH v3 11/15] kasan: move _RET_IP_ to inline wrappers From: Andrey Konovalov To: Andrew Morton , Catalin Marinas , Vincenzo Frascino , Dmitry Vyukov , Alexander Potapenko , Marco Elver X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210114_143704_275007_4FA23C00 X-CRM114-Status: GOOD ( 14.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: Branislav Rankov , Andrey Konovalov , Kevin Brodsky , Will Deacon , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, Andrey Ryabinin , Peter Collingbourne , Evgenii Stepanov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Generic mm functions that call KASAN annotations that might report a bug pass _RET_IP_ to them as an argument. This allows KASAN to include the name of the function that called the mm function in its report's header. Now that KASAN has inline wrappers for all of its annotations, move _RET_IP_ to those wrappers to simplify annotation call sites. Link: https://linux-review.googlesource.com/id/I8fb3c06d49671305ee184175a39591bc26647a67 Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver Reviewed-by: Alexander Potapenko --- include/linux/kasan.h | 20 +++++++++----------- mm/mempool.c | 2 +- mm/slab.c | 2 +- mm/slub.c | 4 ++-- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 5e0655fb2a6f..bba1637827c3 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -181,19 +181,18 @@ static __always_inline void * __must_check kasan_init_slab_obj( } 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) +static __always_inline bool kasan_slab_free(struct kmem_cache *s, void *object) { if (kasan_enabled()) - return __kasan_slab_free(s, object, ip); + return __kasan_slab_free(s, object, _RET_IP_); 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) +static __always_inline void kasan_slab_free_mempool(void *ptr) { if (kasan_enabled()) - __kasan_slab_free_mempool(ptr, ip); + __kasan_slab_free_mempool(ptr, _RET_IP_); } void * __must_check __kasan_slab_alloc(struct kmem_cache *s, @@ -237,10 +236,10 @@ static __always_inline void * __must_check kasan_krealloc(const void *object, } void __kasan_kfree_large(void *ptr, unsigned long ip); -static __always_inline void kasan_kfree_large(void *ptr, unsigned long ip) +static __always_inline void kasan_kfree_large(void *ptr) { if (kasan_enabled()) - __kasan_kfree_large(ptr, ip); + __kasan_kfree_large(ptr, _RET_IP_); } bool kasan_save_enable_multi_shot(void); @@ -273,12 +272,11 @@ static inline void *kasan_init_slab_obj(struct kmem_cache *cache, { return (void *)object; } -static inline bool kasan_slab_free(struct kmem_cache *s, void *object, - unsigned long ip) +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_free_mempool(void *ptr) {} static inline void *kasan_slab_alloc(struct kmem_cache *s, void *object, gfp_t flags) { @@ -298,7 +296,7 @@ static inline void *kasan_krealloc(const void *object, size_t new_size, { return (void *)object; } -static inline void kasan_kfree_large(void *ptr, unsigned long ip) {} +static inline void kasan_kfree_large(void *ptr) {} #endif /* CONFIG_KASAN */ diff --git a/mm/mempool.c b/mm/mempool.c index 624ed51b060f..79959fac27d7 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_slab_free_mempool(element, _RET_IP_); + kasan_slab_free_mempool(element); else if (pool->alloc == mempool_alloc_pages) kasan_free_pages(element, (unsigned long)pool->pool_data); } diff --git a/mm/slab.c b/mm/slab.c index d7c8da9319c7..afeb6191fb1e 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -3421,7 +3421,7 @@ static __always_inline void __cache_free(struct kmem_cache *cachep, void *objp, memset(objp, 0, cachep->object_size); /* Put the object into the quarantine, don't touch it for now. */ - if (kasan_slab_free(cachep, objp, _RET_IP_)) + if (kasan_slab_free(cachep, objp)) return; /* Use KCSAN to help debug racy use-after-free. */ diff --git a/mm/slub.c b/mm/slub.c index 75fb097d990d..0afb53488238 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -1514,7 +1514,7 @@ static inline void *kmalloc_large_node_hook(void *ptr, size_t size, gfp_t flags) static __always_inline void kfree_hook(void *x) { kmemleak_free(x); - kasan_kfree_large(x, _RET_IP_); + kasan_kfree_large(x); } static __always_inline bool slab_free_hook(struct kmem_cache *s, void *x) @@ -1544,7 +1544,7 @@ static __always_inline bool slab_free_hook(struct kmem_cache *s, void *x) KCSAN_ACCESS_WRITE | KCSAN_ACCESS_ASSERT); /* KASAN might put x into memory quarantine, delaying its reuse */ - return kasan_slab_free(s, x, _RET_IP_); + return kasan_slab_free(s, x); } static inline bool slab_free_freelist_hook(struct kmem_cache *s,