From patchwork Tue Dec 19 22:28:54 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: 13499304 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 EE2E9C46CD3 for ; Tue, 19 Dec 2023 22:30:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 22D858D000E; Tue, 19 Dec 2023 17:30:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 167848D000D; Tue, 19 Dec 2023 17:30:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F22878D000E; Tue, 19 Dec 2023 17:30:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id D71D28D000D for ; Tue, 19 Dec 2023 17:30:23 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id B386240381 for ; Tue, 19 Dec 2023 22:30:23 +0000 (UTC) X-FDA: 81585012726.05.BB1F1F7 Received: from out-186.mta0.migadu.com (out-186.mta0.migadu.com [91.218.175.186]) by imf02.hostedemail.com (Postfix) with ESMTP id 24DC68000B for ; Tue, 19 Dec 2023 22:30:21 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Ctrg2ZB1; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf02.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.186 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=1703025022; 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=TOZdtH5KljVO+QBwvb475Ri4NSt7i5y2rX8Y2gdn2wY=; b=t/HS4oIQbH3XOym53wAoqXN1VyCq/iaiopBLnRBfU8TFHbKq0qeBHWx3RXplB5+/MPBHC1 yFf2QuFlFuJfEy+JDjIgeBaex0oCg7smb5Rfvz6Rdre7lf9xiu0R7NmByWlbGiKKfTuGYF VnXu4Ep9wwTICYNOVQsjiB5FXVTbb2Y= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Ctrg2ZB1; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf02.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.186 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703025022; a=rsa-sha256; cv=none; b=oqZ8Uyq28wWcHIsYL/hlqnz0m4atcURj/rGuVySsNoEFVMZ97sEypR+K26qcEBbJntIPvv VnbCr0vQyNLxS4mbi8xmgcYXuwAobed1jSEPyuD0dyk+DmVWs3rBuI5bP684LhWS5ZTHEy yy6s1eFWrPRJUXU/HGjJp94NdiBIRx0= 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=1703025020; 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=TOZdtH5KljVO+QBwvb475Ri4NSt7i5y2rX8Y2gdn2wY=; b=Ctrg2ZB1vr09mQJDl/g4xpRjwYVqozqH5I/yyeUDJ9kKUUsjofuMXHKU5XEuSmxPXCR5w9 dDaoAQH0Z6U4wMeGi6PrDUTFdO+Rj/pE+kqT96iJ8qj/ZdT+fG6UmURjrqCkw90n3UvUpY cDiRSDo85Tluc4i4aNZ0g57lX0tLRX8= 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 10/21] kasan: clean up and rename ____kasan_kmalloc Date: Tue, 19 Dec 2023 23:28:54 +0100 Message-Id: <5881232ad357ec0d59a5b1aefd9e0673a386399a.1703024586.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 24DC68000B X-Stat-Signature: tfthqxqkp99nnrhmum4ke8feeti9dw4g X-Rspam-User: X-HE-Tag: 1703025021-362784 X-HE-Meta: U2FsdGVkX1994SoxPluNOWsUJoil+FcQtt/sZS16Hgi1k9BEzN8+14VensJ13KtQLs/NwFIn23ciVrroqgHOiWxqlgwh00NLnaQ4uCOo0W9zPR0uW+ANY63QOo1SpAM6doYxmKF5EWT1cEqw7jf5eSyoo8gsgIzdyUZoAvkJvcg9Wor/5QUva1BscDG3wNLxaRFECfq4PmTe6E0aQdr2gnPgW308MMqzd2XCnAy7CS35rl6fzHRoz1QL6lbjrVKEjgaGemSaKH60dPwgMm0b+35uFQ2hHhVgEYZYn5nWCxS7wCLCztzqU0mgFFzQT7CN0LB9TfoVGsvzfLYYoORH2UXx6aRHRzB9mjDL1oj6oaFkUFlHPGuvmEwkJglWUhnWj4n/AKqg7wXgkUtX6Zu9W/HaISruGtN5Te0yzdzgNmc02xMs34cXl6ayrYsoIApdoFf21Fb5Axovori3EL2tZXGbT9tAZ3PVQW2/DJpCLmo+bFQ/lNpP4qxzuNqY0qbR8LbEeLTIQ27330FW1qNK4eeXliQY84FEhAiCW0sd2YoDH5MS71NQ+Ws9py+yNS8EpqOQiMeXLYfqW0Bc2MbqiceJUfJJzf0M3/dVOeswm2rQYdh2tc+spcD34nBTs+4eGK7MsVNpu5rVggp6R5EVTm2U3NvpUNDlrdgnZ2NIjyeu2TGbTN0l5HzQYOgYqOWt59KQJMQBg6s9Ya01jRNza5DEvrKXLu2V1rkifVboT99zZgvwLjcTDy0akYeS92Wc/U1WESBVxqA22Sz4D8ngvqxQunw3R+f7UvAIVI4gacARH5OldqFmVaCHwnHw1rUdHy4abGt24owYUo6tyhONQ1uEGogwmSxNuznmbddRvlEf+xXhyhKtDTIMkKvP2AJqpKzK3VjLujv2MiID22x8yzcEjMaMBCp6xSHJ1VHFeAwMgsWpY8CWLb4mZcNcclDaYqN8yE3JbrM= 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 Introduce a new poison_kmalloc_redzone helper function that poisons the redzone for kmalloc object. Drop the confusingly named ____kasan_kmalloc function and instead use poison_kmalloc_redzone along with the other required parts of ____kasan_kmalloc in the callers' code. This is a preparatory change for the following patches in this series. Signed-off-by: Andrey Konovalov --- mm/kasan/common.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 59146886e57d..1217b260abc3 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -312,26 +312,12 @@ void * __must_check __kasan_slab_alloc(struct kmem_cache *cache, return tagged_object; } -static inline void *____kasan_kmalloc(struct kmem_cache *cache, +static inline void poison_kmalloc_redzone(struct kmem_cache *cache, const void *object, size_t size, gfp_t flags) { unsigned long redzone_start; unsigned long redzone_end; - if (gfpflags_allow_blocking(flags)) - kasan_quarantine_reduce(); - - if (unlikely(object == NULL)) - return NULL; - - if (is_kfence_address(kasan_reset_tag(object))) - return (void *)object; - - /* - * The object has already been unpoisoned by kasan_slab_alloc() for - * kmalloc() or by kasan_krealloc() for krealloc(). - */ - /* * The redzone has byte-level precision for the generic mode. * Partially poison the last object granule to cover the unaligned @@ -355,14 +341,25 @@ static inline void *____kasan_kmalloc(struct kmem_cache *cache, if (kasan_stack_collection_enabled() && is_kmalloc_cache(cache)) kasan_save_alloc_info(cache, (void *)object, flags); - /* Keep the tag that was set by kasan_slab_alloc(). */ - return (void *)object; } 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); + if (gfpflags_allow_blocking(flags)) + kasan_quarantine_reduce(); + + if (unlikely(object == NULL)) + return NULL; + + if (is_kfence_address(kasan_reset_tag(object))) + return (void *)object; + + /* The object has already been unpoisoned by kasan_slab_alloc(). */ + poison_kmalloc_redzone(cache, object, size, flags); + + /* Keep the tag that was set by kasan_slab_alloc(). */ + return (void *)object; } EXPORT_SYMBOL(__kasan_kmalloc); @@ -408,6 +405,9 @@ void * __must_check __kasan_krealloc(const void *object, size_t size, gfp_t flag if (unlikely(object == ZERO_SIZE_PTR)) return (void *)object; + if (is_kfence_address(kasan_reset_tag(object))) + return (void *)object; + /* * Unpoison the object's data. * Part of it might already have been unpoisoned, but it's unknown @@ -420,8 +420,10 @@ void * __must_check __kasan_krealloc(const void *object, size_t size, gfp_t flag /* Piggy-back on kmalloc() instrumentation to poison the redzone. */ if (unlikely(!slab)) return __kasan_kmalloc_large(object, size, flags); - else - return ____kasan_kmalloc(slab->slab_cache, object, size, flags); + else { + poison_kmalloc_redzone(slab->slab_cache, object, size, flags); + return (void *)object; + } } bool __kasan_mempool_poison_pages(struct page *page, unsigned int order,