From patchwork Tue Dec 19 22:28:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 13499297 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id ABF2EC46CD3 for ; Tue, 19 Dec 2023 22:29:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 782B86B0083; Tue, 19 Dec 2023 17:29:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7332E6B0099; Tue, 19 Dec 2023 17:29:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3FD946B0083; Tue, 19 Dec 2023 17:29:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 183CC6B0083 for ; Tue, 19 Dec 2023 17:29:17 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C7A18C094A for ; Tue, 19 Dec 2023 22:29:16 +0000 (UTC) X-FDA: 81585009912.15.98EBED6 Received: from out-185.mta1.migadu.com (out-185.mta1.migadu.com [95.215.58.185]) by imf10.hostedemail.com (Postfix) with ESMTP id BA736C0036 for ; Tue, 19 Dec 2023 22:29:14 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=UmTZEubK; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf10.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.185 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703024955; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=UD/Zwt/pPZV96U3h6ZFDRBLd7zSWBzdFKqeEs3HVWEE=; b=cZQVuGWwjrxoywH2tedye3jK0uXM0JJwZQH0ecHoyzc2xIqKSO4WqTi/iZ3W75kd5bgqFK qBY+d7ZmeqGih6oLUMHeKRvKk1UPbz0nTA5vSYEZETdT4ETD2ruhaqIR0pX6HIYOxJID86 8gvnLLDgPbDz19FnoD2/hVe8XyWEF3g= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=UmTZEubK; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf10.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.185 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703024955; a=rsa-sha256; cv=none; b=kYMgsPq2zZ91lu1FTZCb65zAXezV1DS8IuyaTXVSAGThRp5qpxG1w77++dz5X3fNS3sV2V QkA4jv0P+AdyG2tEps5/iSKdUjk3Wxw1ZgSve2PLcCRW0tQlxUhyfhShwhrLKyGkZ/doIq w0BdPaEneijpY4MtTse+aE/C+DHQmDY= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1703024953; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UD/Zwt/pPZV96U3h6ZFDRBLd7zSWBzdFKqeEs3HVWEE=; b=UmTZEubKzQoH/lyQhsn4scksM491Jqbo0EpqojoHRU0E+cXktICkazzTkFV4YlK3P70GL4 dgY6Fs06IrKmOBcUEU27QhbAyaN4aO/daowtIz1mMORsloednidVgfydYvYT7U3SjZHFk/ +5imE9/lInyqZ2hSS3qnfUmxERlUWdM= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Evgenii Stepanov , Breno Leitao , Alexander Lobakin , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm 02/21] kasan: move kasan_mempool_poison_object Date: Tue, 19 Dec 2023 23:28:46 +0100 Message-Id: <23ea215409f43c13cdf9ecc454501a264c107d67.1703024586.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: BA736C0036 X-Stat-Signature: hnz9baotddi8im5g1xmciydrm1hij8pw X-HE-Tag: 1703024954-994241 X-HE-Meta: U2FsdGVkX1+e6C0Rr6c4N/rWvuRjWkyaz7GZKd19GpL7/JjQ9Rb1ijBuR8NWp6OQL7S2ydJO515eKqBowUDbyKFs5Em5wd20IDDtAkfUNM0zVhbKLSXZOLRW+yXSA2vGbYzgIP6xuPABObY4Mw1nKxYjpFu6mYaxnTfow8w6UWHUUgkIP7ZLR4RUu+RwPaBOY+O+eT7QjX4KV/3YWolxJM9K5vmQ2a09265NWBjwCi0vgpwNzajKxdYdCABvyIcWOdomvFvN/fPCxsnOI0yhOGwVIA3lnTaUqs9yJcgSlm+dMtizoYcL/WlxSYJ2MYA/kbAF4tTK/AP9NMQs9WbHLuXBQVhXjNQVZhCTbdscwpDfZ5HEX5xehopVHTa5kqJon8iQnLB3TTwUHral4ZvHK74Mly8QF5ZG13U03SH6GIYeiPJ0wW50/tiSBT4eNe7vtZqnyrTGbczs1A5DS6vNfxTVIxL0QNM6hrz46q5TgE2G3eE1DJ/7aGURkenNjldictzJ57slexl0hkIyIp3ceJ/dldpzYTfWRxyHlCS199r+Rm+IBM4CJr5Spg6lPv5LGsZ/Qb2QGX+Lv9IAHFy7ClK/bUOMEKpt+CGFD77d9Ko2zvyGLdsB77l4FCD1BMtvR+ntiAn8D4z1Ayz7XJ/AHvZSGTQIfOFcnlQrhAYnGesGXfO7s71bVk7USuwWmumXbDZNSFfqR6g2AIVxgeBRk2wSoU8fbUxcLKl7EsPmSFHQWCvst98H7Y0CzdaNPkpQmgFIYSwub63fyGD0f/xFDyg2xYZ49SSEjMydjW/VuNBRdfwmc4hW7ec1L6Rf3KiG+nJ1lb0tb1dfP9yD97rqkWVjdXsGL73tgA8wez2efiCoNvz56Kw1bO9OZlTDSWiKKcYxhWsvGJrOwF/R/0vLDyGm6AqHaQ3LrdnR8jme8LoKI+P8F7jOObiAzvXBsknjl6Lw5UK9xiU7e193NHx i+5s5h7K 9o5eDU+YakWHq22MitwORK8ACV34TBEJbfp64v8JSPSXJb7LWITGsSFY18Zk+VMwrQQPBsSswoj+OP0ISlVi40vTQTfTtUu1OUC9YaUKdpok+AKfmnuRtd8Akaj1EnafJbxp6p++0NywjKUIZrNV46UbwNxeYcNsh7M85SFq0BZdRXswvObE6xRWV2gkjHBrhKFuDJG0tcAApYo0i4WtxLttCLjgInEAT2kHv X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Andrey Konovalov Move kasan_mempool_poison_object after all slab-related KASAN hooks. This is a preparatory change for the following patches in this series. No functional changes. Signed-off-by: Andrey Konovalov --- include/linux/kasan.h | 16 +++++++-------- mm/kasan/common.c | 46 +++++++++++++++++++++---------------------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 6310435f528b..0d1f925c136d 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -172,13 +172,6 @@ static __always_inline void kasan_kfree_large(void *ptr) __kasan_kfree_large(ptr, _RET_IP_); } -void __kasan_mempool_poison_object(void *ptr, unsigned long ip); -static __always_inline void kasan_mempool_poison_object(void *ptr) -{ - if (kasan_enabled()) - __kasan_mempool_poison_object(ptr, _RET_IP_); -} - void * __must_check __kasan_slab_alloc(struct kmem_cache *s, void *object, gfp_t flags, bool init); static __always_inline void * __must_check kasan_slab_alloc( @@ -219,6 +212,13 @@ static __always_inline void * __must_check kasan_krealloc(const void *object, return (void *)object; } +void __kasan_mempool_poison_object(void *ptr, unsigned long ip); +static __always_inline void kasan_mempool_poison_object(void *ptr) +{ + if (kasan_enabled()) + __kasan_mempool_poison_object(ptr, _RET_IP_); +} + /* * Unlike kasan_check_read/write(), kasan_check_byte() is performed even for * the hardware tag-based mode that doesn't rely on compiler instrumentation. @@ -256,7 +256,6 @@ static inline bool kasan_slab_free(struct kmem_cache *s, void *object, bool init return false; } static inline void kasan_kfree_large(void *ptr) {} -static inline void kasan_mempool_poison_object(void *ptr) {} static inline void *kasan_slab_alloc(struct kmem_cache *s, void *object, gfp_t flags, bool init) { @@ -276,6 +275,7 @@ static inline void *kasan_krealloc(const void *object, size_t new_size, { return (void *)object; } +static inline void kasan_mempool_poison_object(void *ptr) {} static inline bool kasan_check_byte(const void *address) { return true; diff --git a/mm/kasan/common.c b/mm/kasan/common.c index e0394d0ee7f1..fc7f711607e1 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -282,29 +282,6 @@ void __kasan_kfree_large(void *ptr, unsigned long ip) ____kasan_kfree_large(ptr, ip); } -void __kasan_mempool_poison_object(void *ptr, unsigned long ip) -{ - struct folio *folio; - - folio = virt_to_folio(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(!folio_test_slab(folio))) { - if (____kasan_kfree_large(ptr, ip)) - return; - kasan_poison(ptr, folio_size(folio), KASAN_PAGE_FREE, false); - } else { - struct slab *slab = folio_slab(folio); - - ____kasan_slab_free(slab->slab_cache, ptr, ip, false, false); - } -} - void * __must_check __kasan_slab_alloc(struct kmem_cache *cache, void *object, gfp_t flags, bool init) { @@ -452,6 +429,29 @@ void * __must_check __kasan_krealloc(const void *object, size_t size, gfp_t flag return ____kasan_kmalloc(slab->slab_cache, object, size, flags); } +void __kasan_mempool_poison_object(void *ptr, unsigned long ip) +{ + struct folio *folio; + + folio = virt_to_folio(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(!folio_test_slab(folio))) { + if (____kasan_kfree_large(ptr, ip)) + return; + kasan_poison(ptr, folio_size(folio), KASAN_PAGE_FREE, false); + } else { + struct slab *slab = folio_slab(folio); + + ____kasan_slab_free(slab->slab_cache, ptr, ip, false, false); + } +} + bool __kasan_check_byte(const void *address, unsigned long ip) { if (!kasan_byte_accessible(address)) {