Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3542411pxb; Mon, 24 Jan 2022 11:49:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJzurD6iaUP1RCXkVBTRxtmaZOU6DLQIQyUqYLCMa0iX+04VxRqkRTqVbzkMZjIbUc87MCQ6 X-Received: by 2002:a05:6a00:124b:b0:4c3:3eec:6294 with SMTP id u11-20020a056a00124b00b004c33eec6294mr15047836pfi.19.1643053773632; Mon, 24 Jan 2022 11:49:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643053773; cv=none; d=google.com; s=arc-20160816; b=yh10mSUqzWsMJzNWnmrVDmYwH7wdJTv54RAmJW2bjU2oZ/1OcdUPlyYvH7izkkHOKk wKNtGP0Ezth4Pkh3TEiQRO83xjNlrd3jn1SlGcQ1tDdqTXYB8N0AJAdSIW/+LgO0hRfF O2DVLtSX2dzplQKYVniypWFZD1DgyrelI/89kkF1zKtgKASfzJSCCmUwi9kueSRGDt0H XZfCck1L7OBKAQUViY/lQkoONDjnyQDP42Qdq0cKzWc9M59Ymmrv1HaKLPw2lmefsRIT 2AOPwExKWtK4c0WQULM9sNZi55iY+wb7Cb6d8TIuQ8R89xA8Yj4Dz3drdDy/ltQSTQbo ep+A== 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=4jFZKwC+1fGM+Zh4UMZz7D7AiRXqN4olJqxCqj+PmMQ=; b=zglyldM+hWMSZg07Abp/NhjcoZvnkVC+zeeCDTlNpGJsQId+/GUPm2YOf7PEj3af2C ZgeJN+lvoGW9ZRRaL9BOdByeD/Q++KtZh4FzjiCcUJcu3RzrXKANu1vutajYGZTNNUEs 4pj3RHPykG6sqQmzgrIcYzpQJrD0zuqvObaTQAh8rAlPDMBS7vVxFFrshUq1pYz+PtVx CaXdIyAlq1nnZ6P2kSuxGLJMS0o60vo6Dy82rCiZX9qm/YqNlAD4X34TPgtNcI/r2fsm KaxcERFsqhGfslzd8HY4kzw2WSmJDfLM0K1SXJoDDHwaCvPOXggu1zbiEBk5nlFMpDAl IT6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=UlCrGKBA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t19si12668780pgu.36.2022.01.24.11.49.20; Mon, 24 Jan 2022 11:49:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=UlCrGKBA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241746AbiAXSF1 (ORCPT + 99 others); Mon, 24 Jan 2022 13:05:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244918AbiAXSFU (ORCPT ); Mon, 24 Jan 2022 13:05:20 -0500 Received: from out2.migadu.com (out2.migadu.com [IPv6:2001:41d0:2:aacc::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC61EC06173B for ; Mon, 24 Jan 2022 10:05:19 -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=1643047518; 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=4jFZKwC+1fGM+Zh4UMZz7D7AiRXqN4olJqxCqj+PmMQ=; b=UlCrGKBAuA8d1oTsocL7IE0SrflMdbtAS5WghAmbZDW2VPLOwFw8aZW4KMlHfbLQbLVsOv IKwBQ6/nlpu7pV6MtgOi3bsz0kb6QK7pBollsSUM1NVShtvrCmfeloCG1ZxGhQ95NOQU3i eBA8N4ipq51wSOpDw/CTj5WXUtErR4A= From: andrey.konovalov@linux.dev To: Andrew Morton Cc: Andrey Konovalov , Marco Elver , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, linux-mm@kvack.org, Vincenzo Frascino , Catalin Marinas , Will Deacon , Mark Rutland , linux-arm-kernel@lists.infradead.org, Peter Collingbourne , Evgenii Stepanov , linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v6 20/39] kasan: add wrappers for vmalloc hooks Date: Mon, 24 Jan 2022 19:04:54 +0100 Message-Id: <3b8728eac438c55389fb0f9a8a2145d71dd77487.1643047180.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrey Konovalov Add wrappers around functions that [un]poison memory for vmalloc allocations. These functions will be used by HW_TAGS KASAN and therefore need to be disabled when kasan=off command line argument is provided. This patch does no functional changes for software KASAN modes. Signed-off-by: Andrey Konovalov Reviewed-by: Alexander Potapenko --- include/linux/kasan.h | 17 +++++++++++++++-- mm/kasan/shadow.c | 5 ++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 46a63374c86f..da320069e7cf 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -424,8 +424,21 @@ void kasan_release_vmalloc(unsigned long start, unsigned long end, unsigned long free_region_start, unsigned long free_region_end); -void kasan_unpoison_vmalloc(const void *start, unsigned long size); -void kasan_poison_vmalloc(const void *start, unsigned long size); +void __kasan_unpoison_vmalloc(const void *start, unsigned long size); +static __always_inline void kasan_unpoison_vmalloc(const void *start, + unsigned long size) +{ + if (kasan_enabled()) + __kasan_unpoison_vmalloc(start, size); +} + +void __kasan_poison_vmalloc(const void *start, unsigned long size); +static __always_inline void kasan_poison_vmalloc(const void *start, + unsigned long size) +{ + if (kasan_enabled()) + __kasan_poison_vmalloc(start, size); +} #else /* CONFIG_KASAN_VMALLOC */ diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c index bf7ab62fbfb9..39d0b32ebf70 100644 --- a/mm/kasan/shadow.c +++ b/mm/kasan/shadow.c @@ -475,8 +475,7 @@ void kasan_release_vmalloc(unsigned long start, unsigned long end, } } - -void kasan_unpoison_vmalloc(const void *start, unsigned long size) +void __kasan_unpoison_vmalloc(const void *start, unsigned long size) { if (!is_vmalloc_or_module_addr(start)) return; @@ -488,7 +487,7 @@ void kasan_unpoison_vmalloc(const void *start, unsigned long size) * Poison the shadow for a vmalloc region. Called as part of the * freeing process at the time the region is freed. */ -void kasan_poison_vmalloc(const void *start, unsigned long size) +void __kasan_poison_vmalloc(const void *start, unsigned long size) { if (!is_vmalloc_or_module_addr(start)) return; -- 2.25.1