From patchwork Mon Nov 6 20:10:11 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: 13447416 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 45792C4167B for ; Mon, 6 Nov 2023 20:10:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A54B56B0286; Mon, 6 Nov 2023 15:10:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A04E26B0288; Mon, 6 Nov 2023 15:10:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8F2CD6B0289; Mon, 6 Nov 2023 15:10:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 71A1F6B0288 for ; Mon, 6 Nov 2023 15:10:38 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 49EB3808E6 for ; Mon, 6 Nov 2023 20:10:38 +0000 (UTC) X-FDA: 81428622156.03.AE22885 Received: from out-174.mta1.migadu.com (out-174.mta1.migadu.com [95.215.58.174]) by imf29.hostedemail.com (Postfix) with ESMTP id 74F0F120015 for ; Mon, 6 Nov 2023 20:10:36 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=aaX6KV+U; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf29.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.174 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=1699301436; 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=t/Tz91brdE21dTNWs0et2BZxKBCaFAccIIB/OCqkFS0=; b=3qh9kj6XIfJCcagwVeHYvvMlubcsUovb8oJsTHf0hg6DS9GaZ1DEYz5evJmQhkrn0dfnYd z1vDT2o0fakGpHqRJvxMzLv39jMPtms2ROGu5mEy36GhYWLKflP6KGvxnYfm/sgLXWorBx dCtzBiugzXdPnpXHhCHYIJ9KK+CGqsw= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=aaX6KV+U; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf29.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.174 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699301436; a=rsa-sha256; cv=none; b=PuNhAiq8WC0QNsPHrnfe360DabJSXa6aSyjTML4sk0feDxdg+sHyuaMUtXTYoOY4/PYM4s jZll8JRCenk0Rrjp7a0B9KHAZRWZbajz/CVs6BXSuiCsHXtsIwflRMrWr9zvGBo0D+lm9x Nw8vLODH5CSjq9mrCqzHUsWNVwaSNW4= 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=1699301435; 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=t/Tz91brdE21dTNWs0et2BZxKBCaFAccIIB/OCqkFS0=; b=aaX6KV+UWkGgoc/tFbUJHDU1fecvP/ug5k2WlsFn/kBP4/GWVGypJrvpu3Uccqw9G1op6n rqju0no4iU0SSp8Rg71WkOaGPzeamqnNgb+RhCgZ6NsdAvgl7d/PZXBvDZBn2USk1I6Xh7 af1WOsyuVc57E+UwVLOlLz3OCEp+fkY= 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 02/20] kasan: move kasan_mempool_poison_object Date: Mon, 6 Nov 2023 21:10:11 +0100 Message-Id: <8bf615539d11dba005e01a65267be1c0298887bc.1699297309.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Stat-Signature: inmjaz8bizjp1frpgc834x4n4cincyf1 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 74F0F120015 X-HE-Tag: 1699301436-192287 X-HE-Meta: U2FsdGVkX1/9JSad54dvDA5lNAxuLpaiMVsry21cR/J6H4/YAa0OsbIyRRCUfeebKQ+UFMTUNkV1jYEW1D4s9StG6wleOcX4n39aC0VrVT6WBd5dIxlo41HsiEmIBp/+vX7PptIjF7H7S5SjopT1ARu8PBAJ0Ha4gBJrqXHEjQYvTLwG+TwtUAr37s2BtNGMJ52PYnDR3RjU9L4Ex12p+9SmTWtWKR8B8noto6GDfWEUsgKpMmmfxxcCdbnDkOTNaSztj4hfyt6w/kzQSAi4tcPlxR3jjRzOCP8JJSOvpJbN8fLEeME4jymV1xDooUsa9EWKez/7Zy281apBR89ujGNDQFQlbm5EwWMnJNqLiUqVNZ10sI4DfzgmACUOh91nNm9TCOtE/81RlBEmaCLkrW1X/EIZyTZY9UEiW6S0FTOqhV40ydiLm9XDoUZSZRw/wj5TH+zNOCWMFNuZ0VPmgLPo9HA7O45a4cPqWa5t/PVHx6iyqyBCG6e5e2tKfyeVMG7JED2HLFc1h9L4U+/mX+ZdkTOrgEF2Dx7k085qq3mpED4a/s4ItMw5a2JULc9Bp6QC9YN7en/wHxx54i5sUp+CPnMU9gPM8jAOEidPcEax8po0EJUjxrwHrkqrX2xdoFGnZnKNNtBe2wTwmuEfQvONdZLlonOh2cTu6vv4FAmb8UwQQsEXOZXwO/2zlBMID/5FEtbjvOD2huHFMSfLuBXzqK0E9thxS/BuTvnOQb2X059LEiEq0U6ok2NBzBkBtM9tkkXulu2ZSSaxcukjmnFAL9S5LudugdVV8MobC9csmHtsqfdERar9KM3cSeIWItjv87NMCafGz6BUEIXHD65e+GdkZ1sozYWHH2yImaVx1u6qgSNiDgBjvAstMgKvvPK5QRHAFGaDCLyr6FZa7EFmJvNZAcmykvRvJvd2mztpEM+0sHq7hizCM/E3YMF9ZbkQqalcp1dSHR4xfFc 8CdStZIF pf8U7ZTW7yFYT6x/GUvtDwWQCA6AVvmaKoSVzC2qbtm0nWuWVAuxrFIiib4EmkQMJSsUArpEePr0rAjAhh/4zT8P1sta4tAcAmzL3ynaRpshQ24TJxil4o81SHAgHRQVPn4MTt5P7236srAyBAoGo3c2zKiG9C9Yao5+0bypDOzG8fvNfvcFABHwRPpSZ8K6G7ZxyiB1tc5woE5QsBqRX6dKdcQ== 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 e42d6f349ae2..69f4c66f0da3 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -272,29 +272,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) { @@ -442,6 +419,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)) {