Received: by 2002:a05:7412:d008:b0:f9:6acb:47ec with SMTP id bd8csp216689rdb; Tue, 19 Dec 2023 14:31:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IHo0QT1qmFalA8VuPRITu3wjwFSxIikMd+jsRuFf6M87I6SN68zivwdLPjDg/US+qkH2LxB X-Received: by 2002:a7b:cb4d:0:b0:40c:50d5:f7ac with SMTP id v13-20020a7bcb4d000000b0040c50d5f7acmr7424003wmj.60.1703025104902; Tue, 19 Dec 2023 14:31:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703025104; cv=none; d=google.com; s=arc-20160816; b=lWx+t/m2UXa7fMttzc5G0J6ob6KqoZbWOA6c34ba2FqTOQFA4JhIqUaoLQxuQtFeIL Wo2tXyKI0UfLa+ra/BOO14uTidok9DkakJUXb8lZ4IR6ly8y5dbB0JSskQhCYjBFFPIK JHGRhhm3SRGxSEQiCUxDHSW3sk8+F6uJi3PAzYkklWc31MxTrOSJ45yXy9MzDNTPDiwY UuRxu6NDEVwVkO4qJrDfXDCrmlEeSMNlJxyR5d99ZbISbPwPIM0JxEy9pRYM3H0G6EbO +R3/YgPuKL/VlswvB5o3bBNs79/SognuzdO6DBk9K0ZnOpUgEWZRONHWWVNVLrlwqC6s hxCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=TOZdtH5KljVO+QBwvb475Ri4NSt7i5y2rX8Y2gdn2wY=; fh=AIzsiqkKUtrB7QnM+XRgAblgvDINIC5pDvD0mg8EzrU=; b=fDlRd2t8k58D2KKIP6ogotS17lJ0bnVTLT3nTULo6zhJHeqLd9t3ikE9JdFHvCt/e9 eqkuvVok/g27bankdlsrP4xHv3I5iRCSahbvRLuQ4TQGOW5ncCArrIwbvSfxM79xxWcE /pi/dUn0o1dqUCi2Dr2v28C+FkAkoJPo6X2Qaox3D10vSXmZJxN0BL6YLSfaSjmzugO0 CAkpCXBZczStotTsCZi/VLIN1kgYbW0Xf8mkFYL+URQORwdFPC+eoVMwYQvM99G31ug/ HcoRQbPFQkvQgsa2aWYVuRrUxRdgOkoMRt0/zfHFCqkondzWZIdkFCkguadgvFehE3zT xrsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Ctrg2ZB1; spf=pass (google.com: domain of linux-kernel+bounces-6050-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6050-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id e5-20020a170906504500b00a2353a27a3fsi2348532ejk.910.2023.12.19.14.31.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 14:31:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-6050-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Ctrg2ZB1; spf=pass (google.com: domain of linux-kernel+bounces-6050-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6050-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id A50411F25E9B for ; Tue, 19 Dec 2023 22:31:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 70A4040BFC; Tue, 19 Dec 2023 22:30:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Ctrg2ZB1" X-Original-To: linux-kernel@vger.kernel.org Received: from out-184.mta0.migadu.com (out-184.mta0.migadu.com [91.218.175.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C009F3D0DB for ; Tue, 19 Dec 2023 22:30:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=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=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: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT 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, -- 2.25.1