From patchwork Mon Nov 6 20:10:27 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: 13447466 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 7A4C1C4332F for ; Mon, 6 Nov 2023 20:13:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 17B646B02AE; Mon, 6 Nov 2023 15:13:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 12CFD6B02AF; Mon, 6 Nov 2023 15:13:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F35BE6B02B0; Mon, 6 Nov 2023 15:13:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E41906B02AE for ; Mon, 6 Nov 2023 15:13:53 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C325D80924 for ; Mon, 6 Nov 2023 20:13:53 +0000 (UTC) X-FDA: 81428630346.25.9363E10 Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [91.218.175.180]) by imf09.hostedemail.com (Postfix) with ESMTP id 04F00140020 for ; Mon, 6 Nov 2023 20:13:51 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="gW/TzhDf"; spf=pass (imf09.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.180 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1699301632; 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=FAC2S7cvKWC0F44BA8JFK/nUEMkMZjl2M4MUzuWuDcc=; b=TQma8zyUGTM+oUBQYlrlYEFE7psucUvLjiIoMYza+YlCTMs9oJHCQiPpRup5vDqs+w6nHY CqFj8Cdmq/23CIrA34QGdPVASxV/sF3IRyw+EcvHUAw+DO3dDPET4XxmQzThXmxs5rkL2h 4jHotAvMR8CkOPbabxMUhmSPV3iSY+0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699301632; a=rsa-sha256; cv=none; b=TOKe+PK5Pc1dH73RWkMPJ+SKnYrcUwA8Ys436vbwMKrqmUH+zKLSA/KncLXbrAW58S7T6x 4CyhRts/eg7Y1/xWXWBbNpb/Xu2k7kzbtil6GBSASreFTdfSsfxc+D4olbzZYG/innuXr0 wIFsulTosd3S52IY/a30sEZGZWe/jSY= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="gW/TzhDf"; spf=pass (imf09.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.180 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev 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=1699301629; 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=FAC2S7cvKWC0F44BA8JFK/nUEMkMZjl2M4MUzuWuDcc=; b=gW/TzhDfZHPF/6G1OrNDQlLOWzEZX/fdM1cYbnvPQJyE+kylQJLDKf+bdGnEZPKJYJFBTJ 4QEyp11eHyzBaGYnGOiz5gn3Q6Jl2PEmI90MIeHA3Z1ZMwOIDu2AEjJhNEEem2iCH7tksZ EO/mX3B4YVf6+hMEYQMPvEmF3YvoFx4= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH RFC 18/20] kasan: rename and document kasan_(un)poison_object_data Date: Mon, 6 Nov 2023 21:10:27 +0100 Message-Id: <1128fd5cf1051270bc7e5978479a983a918626f5.1699297309.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 04F00140020 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: guemodgu4crg9mnj98bighe188wjpn3u X-HE-Tag: 1699301631-161589 X-HE-Meta: U2FsdGVkX1+4cjYUI1tZD0x7AruM+kzID9he4ZNxtM3mP1APNHyaGS68gbzBEW5WoOImw8We//sr7M4fqYuMUu8gp0pAQwwzl8NU8DJuKd98TSThSrbMd7UB+0UuxNeReUf9QeNexMyKLgXDcwgbSH1CJGr7gWFlF1rL0uWtLqIsTg3GRDRCaPANWPs/PJww4YmWsjjimo9qTU6kKcmBGzbe+7W7JPEFxJsTHlvY0iPG4Xri+nsVS2VMYVmvPhsuw+ySx6v2LW7AwD63PD2O590Qs/OEpaGmecWwB/o5heO1oFA7iO8VTpmHutefNTUBSOFRKnKGtOKcTfJVrN3O4qTiQAUCAWdzuYUw70rQBbQMTv3nfSCrHRySEWloZEAZhykwKw4WLbwqyr48NuTltJN9mHZaN4tDdkdJdTI8hdFRYri3uZs9tO77aLeei9ZL1Fq0dw7EzubUzahFEZS5U8/iajZ1VsgkCPAchvIAGpSTZ5NDcZtPd8v4sgT5wC28S0btaAa5YJ2p3L+7QnzeVaVBsalF9hHmo2W4/VtUSeP4QaSDIeXeSVaRpnnjNt1wFqbmCEtYC9jreispWqVpQbeberc1CuuI3tlwHsXOO7saOPVgOK+w7iATbNiq1MNmXB6Bny5+C91u8BMOLckMdqem9OpXfj2ETNuHTsoR8c/ZDU/71J9DkGIyENu1Rlo+7eLyp4uNsz+C/h0bn7uAcJpb9TVgpas4hMSujdg58cAtsGvV9rVAFPK+HD+yjDJAUDaJcBh6tYo1DoAuNH782p8bk1hiotZHegOiyRWotoc8ZLKcGtUHfuQ/3lJ7m5koMPrpZ9YyZ80NP8sP9PKz6neVTWzfBNqnCIOFRLd/3Vk0fz0aLEXg1jWwu1qPFsC3nXDvVkkSDqnCKevG5joADfs/YMEXG7Tjdaq99XRs1sepVVjGp8zFNKLeJFY197QalbXKngCZG+JWWyjqKFm 1PCav9fY 8CHfggGOwfMVfuH5u1qpDceH2TsC++LVqy0T96Ee0Ku43nxYagPynbcoZ/y7eSnIXPc6NAQg3de9bvecQr9gUwRZcBOR6Y1H9UsN+mCsnrz98X3IY6NOxAfPp7U7quz98/lOKdhNc4QI567BC6yUKAycsoab2YuXU3X7cDkPw+SC6v0aD4ipDAZ3sLjqObxfFyamZQETWXFrC+IjTDTylHqPQMpI0//LxyBd1 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 Rename kasan_unpoison_object_data to kasan_unpoison_new_object and add a documentation comment. Do the same for kasan_poison_object_data. The new names and the comments should suggest the users that these hooks are intended for internal use by the slab allocator. The following patch will remove non-slab-internal uses of these hooks. No functional changes. Signed-off-by: Andrey Konovalov --- include/linux/kasan.h | 35 +++++++++++++++++++++++++++-------- mm/kasan/common.c | 4 ++-- mm/slab.c | 10 ++++------ mm/slub.c | 4 ++-- net/core/skbuff.c | 8 ++++---- 5 files changed, 39 insertions(+), 22 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 7392c5d89b92..d49e3d4c099e 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -129,20 +129,39 @@ static __always_inline void kasan_poison_slab(struct slab *slab) __kasan_poison_slab(slab); } -void __kasan_unpoison_object_data(struct kmem_cache *cache, void *object); -static __always_inline void kasan_unpoison_object_data(struct kmem_cache *cache, +void __kasan_unpoison_new_object(struct kmem_cache *cache, void *object); +/** + * kasan_unpoison_new_object - Temporarily unpoison a new slab object. + * @cache: Cache the object belong to. + * @object: Pointer to the object. + * + * This function is intended for the slab allocator's internal use. It + * temporarily unpoisons an object from a newly allocated slab without doing + * anything else. The object must later be repoisoned by + * kasan_poison_new_object(). + */ +static __always_inline void kasan_unpoison_new_object(struct kmem_cache *cache, void *object) { if (kasan_enabled()) - __kasan_unpoison_object_data(cache, object); + __kasan_unpoison_new_object(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 __kasan_poison_new_object(struct kmem_cache *cache, void *object); +/** + * kasan_unpoison_new_object - Repoison a new slab object. + * @cache: Cache the object belong to. + * @object: Pointer to the object. + * + * This function is intended for the slab allocator's internal use. It + * repoisons an object that was previously unpoisoned by + * kasan_unpoison_new_object() without doing anything else. + */ +static __always_inline void kasan_poison_new_object(struct kmem_cache *cache, void *object) { if (kasan_enabled()) - __kasan_poison_object_data(cache, object); + __kasan_poison_new_object(cache, object); } void * __must_check __kasan_init_slab_obj(struct kmem_cache *cache, @@ -342,9 +361,9 @@ static inline bool kasan_unpoison_pages(struct page *page, unsigned int order, return false; } static inline void kasan_poison_slab(struct slab *slab) {} -static inline void kasan_unpoison_object_data(struct kmem_cache *cache, +static inline void kasan_unpoison_new_object(struct kmem_cache *cache, void *object) {} -static inline void kasan_poison_object_data(struct kmem_cache *cache, +static inline void kasan_poison_new_object(struct kmem_cache *cache, void *object) {} static inline void *kasan_init_slab_obj(struct kmem_cache *cache, const void *object) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 65850d37fd27..9f11be6b00a8 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -133,12 +133,12 @@ void __kasan_poison_slab(struct slab *slab) KASAN_SLAB_REDZONE, false); } -void __kasan_unpoison_object_data(struct kmem_cache *cache, void *object) +void __kasan_unpoison_new_object(struct kmem_cache *cache, void *object) { kasan_unpoison(object, cache->object_size, false); } -void __kasan_poison_object_data(struct kmem_cache *cache, void *object) +void __kasan_poison_new_object(struct kmem_cache *cache, void *object) { kasan_poison(object, round_up(cache->object_size, KASAN_GRANULE_SIZE), KASAN_SLAB_REDZONE, false); diff --git a/mm/slab.c b/mm/slab.c index 9ad3d0f2d1a5..773c79e153f3 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -2327,11 +2327,9 @@ static void cache_init_objs_debug(struct kmem_cache *cachep, struct slab *slab) * They must also be threaded. */ if (cachep->ctor && !(cachep->flags & SLAB_POISON)) { - kasan_unpoison_object_data(cachep, - objp + obj_offset(cachep)); + kasan_unpoison_new_object(cachep, objp + obj_offset(cachep)); cachep->ctor(objp + obj_offset(cachep)); - kasan_poison_object_data( - cachep, objp + obj_offset(cachep)); + kasan_poison_new_object(cachep, objp + obj_offset(cachep)); } if (cachep->flags & SLAB_RED_ZONE) { @@ -2472,9 +2470,9 @@ static void cache_init_objs(struct kmem_cache *cachep, /* constructor could break poison info */ if (DEBUG == 0 && cachep->ctor) { - kasan_unpoison_object_data(cachep, objp); + kasan_unpoison_new_object(cachep, objp); cachep->ctor(objp); - kasan_poison_object_data(cachep, objp); + kasan_poison_new_object(cachep, objp); } if (!shuffled) diff --git a/mm/slub.c b/mm/slub.c index 63d281dfacdb..973f091ec5d1 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -1849,9 +1849,9 @@ static void *setup_object(struct kmem_cache *s, void *object) setup_object_debug(s, object); object = kasan_init_slab_obj(s, object); if (unlikely(s->ctor)) { - kasan_unpoison_object_data(s, object); + kasan_unpoison_new_object(s, object); s->ctor(object); - kasan_poison_object_data(s, object); + kasan_poison_new_object(s, object); } return object; } diff --git a/net/core/skbuff.c b/net/core/skbuff.c index b157efea5dea..63bb6526399d 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -337,7 +337,7 @@ static struct sk_buff *napi_skb_cache_get(void) } skb = nc->skb_cache[--nc->skb_count]; - kasan_unpoison_object_data(skbuff_cache, skb); + kasan_unpoison_new_object(skbuff_cache, skb); return skb; } @@ -1309,13 +1309,13 @@ static void napi_skb_cache_put(struct sk_buff *skb) struct napi_alloc_cache *nc = this_cpu_ptr(&napi_alloc_cache); u32 i; - kasan_poison_object_data(skbuff_cache, skb); + kasan_poison_new_object(skbuff_cache, skb); nc->skb_cache[nc->skb_count++] = skb; if (unlikely(nc->skb_count == NAPI_SKB_CACHE_SIZE)) { for (i = NAPI_SKB_CACHE_HALF; i < NAPI_SKB_CACHE_SIZE; i++) - kasan_unpoison_object_data(skbuff_cache, - nc->skb_cache[i]); + kasan_unpoison_new_object(skbuff_cache, + nc->skb_cache[i]); kmem_cache_free_bulk(skbuff_cache, NAPI_SKB_CACHE_HALF, nc->skb_cache + NAPI_SKB_CACHE_HALF);