Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp2375604rdf; Mon, 6 Nov 2023 12:12:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IEsloQkTc6+OE/2upDDaoqdH5dKcNa+HlwPo4LDa19cStozXv4sgOm4IzEiHzSxUvJjsFqM X-Received: by 2002:a05:6a21:998a:b0:15e:ab6:6e24 with SMTP id ve10-20020a056a21998a00b0015e0ab66e24mr36820233pzb.27.1699301556525; Mon, 06 Nov 2023 12:12:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699301556; cv=none; d=google.com; s=arc-20160816; b=WA00riDfESoHgiikNd/egJFcpybxanmSrlv5gG+nhr0QYgXYFrewtXrA+FuSxK1rVi uirBzdOW4s4v2SpSz6VaAtwMzn1Okjs02eZ6+/1955TZj/JENFfiUkL61g5GsQEkuodp OsV/58QXgEVRwnuViTT+jMQMkbLIByEgV7s3zbBV1dzhZZZKvh3q8anTxh3pX6x44pf/ JhBpB8rze+kuhmU6IdinJQwgouOjCzjDAJOkTae8ayEE5+kuJYT1Hchchgu9ZMHWIevQ bfY3ZcA6z8Top128xHdFJpgVdS8hcswbpjREQFUvjGGT/4CFkQufpmUYF34uIqMv2K6r pZ0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mCp2zVxGwC1RwRlWPaWBJT09DIYULTSyRat3kYinLuo=; fh=n5KN85tQTomq0Sa/nFFC9xbnc77mxkBzF8HoolO/QOw=; b=Ru8AyNtOErVAYPqyoz8SFXO8felcmu7hrR4s76W7bPLX2UnCjpNUezDSaERfLlWv/j LDNx+mSQJ5kcV2hn97ug+YFWzWWzPeEuZkH7FwLzS8NhiN7aqAERbyePHjvEbJgXVTCi +Q87nN6NmcimYiQ6hJ4SSM5ZZLXAGnkwpBO80FXJeg1w5v7v69pF80OlNFToG+dhDgWb 1uMUYyTBUGkWABkNXYb2dD3gfqDK6E1PCkFVLRd6VxNJzfSE3Not5WeRZlToBvF5HYa9 dTEVmukdq2WYxOsJD4cMJyp2hmnfslvTOw3m6A1Yaf5dKJANK8GUk6KBa0RkYTlDBsC2 A2cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=d537NTwR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id lp3-20020a17090b4a8300b0028024067027si9739934pjb.138.2023.11.06.12.12.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 12:12:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=d537NTwR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 5998D809842D; Mon, 6 Nov 2023 12:12:32 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233039AbjKFUMC (ORCPT + 99 others); Mon, 6 Nov 2023 15:12:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232865AbjKFULq (ORCPT ); Mon, 6 Nov 2023 15:11:46 -0500 Received: from out-186.mta1.migadu.com (out-186.mta1.migadu.com [IPv6:2001:41d0:203:375::ba]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB744D75 for ; Mon, 6 Nov 2023 12:11:42 -0800 (PST) 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=1699301501; 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=mCp2zVxGwC1RwRlWPaWBJT09DIYULTSyRat3kYinLuo=; b=d537NTwRPy7XHKrbuKDfSOCLE08WU2ewkqbATysLDcBjkJxGbnCtGoml9BLyk6/HLbiYso RIWijpSbPsp80ot8o8jmcjVSegnslv45cg4Nvd81jyQ1AX00FXznhsA0/PT1hlWfYlVBc3 NcK/vgYL8Yq2KxPrM8UJdzKMgl1NbA8= 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 10/20] kasan: clean up and rename ____kasan_kmalloc Date: Mon, 6 Nov 2023 21:10:19 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 06 Nov 2023 12:12:32 -0800 (PST) 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 683d0dad32f2..ceb06d5f169f 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -302,26 +302,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 @@ -345,14 +331,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); @@ -398,6 +395,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 @@ -410,8 +410,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, -- 2.25.1