From patchwork Thu Dec 21 20:04:43 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: 13502596 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 EDC26C35274 for ; Thu, 21 Dec 2023 20:05:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 68BE66B007E; Thu, 21 Dec 2023 15:05:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 63B266B0080; Thu, 21 Dec 2023 15:05:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 52ACB6B0083; Thu, 21 Dec 2023 15:05:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 42D3D6B007E for ; Thu, 21 Dec 2023 15:05:03 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E3D8A140E12 for ; Thu, 21 Dec 2023 20:05:02 +0000 (UTC) X-FDA: 81591904044.10.277C7B7 Received: from out-188.mta1.migadu.com (out-188.mta1.migadu.com [95.215.58.188]) by imf07.hostedemail.com (Postfix) with ESMTP id F2F8B40006 for ; Thu, 21 Dec 2023 20:05:00 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=ca6Xr6Os; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf07.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.188 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703189101; a=rsa-sha256; cv=none; b=KBjqjAQErATEVev2+5DV1QoVN1A6opgz4n6aJ8m+2OsA68FVNgZHxjRfHexK1mkp4peYpv aWfqiRkrdi5jtdwpioaAzTvKpr6RnhSzdGQ8GG453YkNjxoOHLmV7TNWRzPB5tkwIIRcIE 1NEJCu6vYdEHKJvdtQzIPiIARZMgBQE= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=ca6Xr6Os; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf07.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.188 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=1703189101; 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=+hJyqXb/2fG9kaa/Bl39ZO/TtJVAZ8OgDJUIBMdnwuM=; b=IHpT+h/zhhNWYf2G4bPXAKDZL9oh4/vXkso+ZHJm4zVoPjB9Q9U57FBr8MQVcGeG/F5i8h xvwKnVTufUMr0lYxCG5J+Ul+/y5nnp9dYWw0eSmxtafNwMMRw82cKwxx0YieVrj4FXTjzW aK+U1wnkmDY/IF/YaxEDjn/mJt/vZxk= 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=1703189099; 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=+hJyqXb/2fG9kaa/Bl39ZO/TtJVAZ8OgDJUIBMdnwuM=; b=ca6Xr6Os/Z3oFun+6KyDxiIacA2tRaVxTTFDHDXDXQXtiQWsYC5+HPech6L4MV3aDTlI07 j3QG0NjRC9B+YgnnxEmb3EgpisveCkpCHQQWA6eNmn+8rbL4RjMp1UGbU7g5fyeyc5HMZ8 qEqcpGuZ87c1j2vSIZxFI6Ddhg+Wa5s= From: andrey.konovalov@linux.dev To: Marco Elver Cc: Andrey Konovalov , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm 01/11] kasan/arm64: improve comments for KASAN_SHADOW_START/END Date: Thu, 21 Dec 2023 21:04:43 +0100 Message-Id: <140108ca0b164648c395a41fbeecb0601b1ae9e1.1703188911.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: F2F8B40006 X-Stat-Signature: 3gxibm1gy5mtek3cr5p5muuozgj44t5p X-HE-Tag: 1703189100-894866 X-HE-Meta: U2FsdGVkX198v6d+qnHMaEadvuplQF8rSQnUvCNVeY6vPnCYJxfNDUi7sJaz3DGLB329mjSAs8CsyDZdoIR/aLGGmtj6F7VHQestvjF95bKrhU7Bvj8EMZVsmsuId+VBTbwNaa7eSlkPUKXQM+lCtprweo7AuiyyhJC/q7OcbV5/9N21kU4dk899y/F/XbUoaQTlvZZ6gj86DGkfzT0lgHlXrOou7GcXdCjgZ8ORSfkVKiHO+CfFA4e4pbYizvflVkHMlYUrVniK24CYP04M1n5vptWlcIUeEmF8t0UEsI3lakbIsF/9GIrwL3SVwl9Sy1KsLZY8zlBOb3I0BtrZUJEkr1ShEbYskp0csNXYuHs3DeCi1pN51LJBdPWTU1YiLuHCxYTGAGzTjMTRzyk8yQQRKjoKkg/qKO7aBihWIx/DtpQqcEfcEJBZnGlOgv6UHRAB5WfJV38G5i52LluNLINXgKXZCsOMOFX5ARUduJdsTOtlUVkQjNMvY3DrUj1bA06i/LCa/UfmhWsgR+FJoGRHBa0nk+2kEUQyX5uaegQa6e4qM+itrC2n7DYTDvkLRrCjsTyJpS8Fww+TXJbYGZvsrfBO83wZiaId8tLWXsPDnRK4daztqI1HRAWRRq1aOuXAJAha7FqW7BziashceHlzTml8OlrLs8fG/sZVEef5uhBfh6S0u3e3P3WuYI9wz/Jn31SczUPYUnrVjNX1PW9Mip4bHIXvTLsvuyypirF/K0oRc8g9durKM8M5k+4FNx5TJN1TtAVr71me4N8QpjbEPGRB0xEH6I5R+dm6qoFz2ky6BOVZ0cFt8aMjS/Grrv0LBryytCkx7W4hO18AzdiDFuK7rbyca/K0nNKgr0nG+RfiiFRVcMKAP8A4X9GhKmDquLZETTR54D7JvJFgW6KwpTophKyQwo8jIKcZ0qXpS08BU3Rp4h0vX7afIkMTXFo/LLwS8RACV6+MIIl 5a215E7R cZGUe7KVCQUkYlpW7p3Qb9SZvxz0dyAkXE2LqNeLZG677f5PH5FKv8fBgCnUZQTmw+kq5lwguX/GvL8A6hULFQN0KDbiOr6CkU9zPFDdxHJyZOLoUhXiQtQfNGstcaDeS0qwZSz/ejCyyvMHPLtngaGZWID7qvsUCQOWbnvPBBWHM3OU4jmUv78BqSpkMNprUT1PAssh6R5skPkritHOZP5l9gQ== 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 Unify and improve the comments for KASAN_SHADOW_START/END definitions from include/asm/kasan.h and include/asm/memory.h. Also put both definitions together in include/asm/memory.h. Also clarify the related BUILD_BUG_ON checks in mm/kasan_init.c. Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm/kasan.h | 22 +------------------ arch/arm64/include/asm/memory.h | 38 +++++++++++++++++++++++++++------ arch/arm64/mm/kasan_init.c | 5 +++++ 3 files changed, 38 insertions(+), 27 deletions(-) diff --git a/arch/arm64/include/asm/kasan.h b/arch/arm64/include/asm/kasan.h index 12d5f47f7dbe..7eefc525a9df 100644 --- a/arch/arm64/include/asm/kasan.h +++ b/arch/arm64/include/asm/kasan.h @@ -15,29 +15,9 @@ #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) +asmlinkage void kasan_early_init(void); void kasan_init(void); - -/* - * KASAN_SHADOW_START: beginning of the kernel virtual addresses. - * KASAN_SHADOW_END: KASAN_SHADOW_START + 1/N of kernel virtual addresses, - * where N = (1 << KASAN_SHADOW_SCALE_SHIFT). - * - * KASAN_SHADOW_OFFSET: - * This value is used to map an address to the corresponding shadow - * address by the following formula: - * shadow_addr = (address >> KASAN_SHADOW_SCALE_SHIFT) + KASAN_SHADOW_OFFSET - * - * (1 << (64 - KASAN_SHADOW_SCALE_SHIFT)) shadow addresses that lie in range - * [KASAN_SHADOW_OFFSET, KASAN_SHADOW_END) cover all 64-bits of virtual - * addresses. So KASAN_SHADOW_OFFSET should satisfy the following equation: - * KASAN_SHADOW_OFFSET = KASAN_SHADOW_END - - * (1ULL << (64 - KASAN_SHADOW_SCALE_SHIFT)) - */ -#define _KASAN_SHADOW_START(va) (KASAN_SHADOW_END - (1UL << ((va) - KASAN_SHADOW_SCALE_SHIFT))) -#define KASAN_SHADOW_START _KASAN_SHADOW_START(vabits_actual) - void kasan_copy_shadow(pgd_t *pgdir); -asmlinkage void kasan_early_init(void); #else static inline void kasan_init(void) { } diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index fde4186cc387..0f139cb4467b 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -65,15 +65,41 @@ #define KERNEL_END _end /* - * Generic and tag-based KASAN require 1/8th and 1/16th of the kernel virtual - * address space for the shadow region respectively. They can bloat the stack - * significantly, so double the (minimum) stack size when they are in use. + * Generic and Software Tag-Based KASAN modes require 1/8th and 1/16th of the + * kernel virtual address space for storing the shadow memory respectively. + * + * The mapping between a virtual memory address and its corresponding shadow + * memory address is defined based on the formula: + * + * shadow_addr = (addr >> KASAN_SHADOW_SCALE_SHIFT) + KASAN_SHADOW_OFFSET + * + * where KASAN_SHADOW_SCALE_SHIFT is the order of the number of bits that map + * to a single shadow byte and KASAN_SHADOW_OFFSET is a constant that offsets + * the mapping. Note that KASAN_SHADOW_OFFSET does not point to the start of + * the shadow memory region. + * + * Based on this mapping, we define two constants: + * + * KASAN_SHADOW_START: the start of the shadow memory region; + * KASAN_SHADOW_END: the end of the shadow memory region. + * + * KASAN_SHADOW_END is defined first as the shadow address that corresponds to + * the upper bound of possible virtual kernel memory addresses UL(1) << 64 + * according to the mapping formula. + * + * KASAN_SHADOW_START is defined second based on KASAN_SHADOW_END. The shadow + * memory start must map to the lowest possible kernel virtual memory address + * and thus it depends on the actual bitness of the address space. + * + * As KASAN inserts redzones between stack variables, this increases the stack + * memory usage significantly. Thus, we double the (minimum) stack size. */ #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) #define KASAN_SHADOW_OFFSET _AC(CONFIG_KASAN_SHADOW_OFFSET, UL) -#define KASAN_SHADOW_END ((UL(1) << (64 - KASAN_SHADOW_SCALE_SHIFT)) \ - + KASAN_SHADOW_OFFSET) -#define PAGE_END (KASAN_SHADOW_END - (1UL << (vabits_actual - KASAN_SHADOW_SCALE_SHIFT))) +#define KASAN_SHADOW_END ((UL(1) << (64 - KASAN_SHADOW_SCALE_SHIFT)) + KASAN_SHADOW_OFFSET) +#define _KASAN_SHADOW_START(va) (KASAN_SHADOW_END - (UL(1) << ((va) - KASAN_SHADOW_SCALE_SHIFT))) +#define KASAN_SHADOW_START _KASAN_SHADOW_START(vabits_actual) +#define PAGE_END KASAN_SHADOW_START #define KASAN_THREAD_SHIFT 1 #else #define KASAN_THREAD_SHIFT 0 diff --git a/arch/arm64/mm/kasan_init.c b/arch/arm64/mm/kasan_init.c index 555285ebd5af..4c7ad574b946 100644 --- a/arch/arm64/mm/kasan_init.c +++ b/arch/arm64/mm/kasan_init.c @@ -170,6 +170,11 @@ asmlinkage void __init kasan_early_init(void) { BUILD_BUG_ON(KASAN_SHADOW_OFFSET != KASAN_SHADOW_END - (1UL << (64 - KASAN_SHADOW_SCALE_SHIFT))); + /* + * We cannot check the actual value of KASAN_SHADOW_START during build, + * as it depends on vabits_actual. As a best-effort approach, check + * potential values calculated based on VA_BITS and VA_BITS_MIN. + */ BUILD_BUG_ON(!IS_ALIGNED(_KASAN_SHADOW_START(VA_BITS), PGDIR_SIZE)); BUILD_BUG_ON(!IS_ALIGNED(_KASAN_SHADOW_START(VA_BITS_MIN), PGDIR_SIZE)); BUILD_BUG_ON(!IS_ALIGNED(KASAN_SHADOW_END, PGDIR_SIZE)); From patchwork Thu Dec 21 20:04:44 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: 13502597 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 5F2B3C46CCD for ; Thu, 21 Dec 2023 20:05:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BB92F6B0080; Thu, 21 Dec 2023 15:05:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B6F0F6B0083; Thu, 21 Dec 2023 15:05:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 970546B0085; Thu, 21 Dec 2023 15:05:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 748F16B0083 for ; Thu, 21 Dec 2023 15:05:03 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 467A1A131F for ; Thu, 21 Dec 2023 20:05:03 +0000 (UTC) X-FDA: 81591904086.01.CA61C5F Received: from out-176.mta1.migadu.com (out-176.mta1.migadu.com [95.215.58.176]) by imf19.hostedemail.com (Postfix) with ESMTP id 5F6961A000A for ; Thu, 21 Dec 2023 20:05:01 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=oUd4oho2; spf=pass (imf19.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.176 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703189101; 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=25+JPAVVR93qloIeZBPh87TvRbXcdeZ++9g3nzTCJ2g=; b=pd0YgiZOKCNkEIceSFzkyPvtOTM0TVXZ/NY9q+G9nnl6Jpb17qmNxyo7Tt1oK1XScZBTYT Yp6KoC37rIbZwdCjNrmEl0ZDSPFgHNdyqfUoZG2mLvTu6ZIEYVeg/s6nDGH1KVjkGUcr0H wSXPYy46OKmmzn/+Lxms7D+6pCx3SUw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703189101; a=rsa-sha256; cv=none; b=BlKVP/UQTDPbgWmS0HflNc8Q8N5FoAKYOE9y9Trhj2gZ37Byq92tfsGVFf0PMoMptt1995 L5wfnnsM5XAUqU2Ezz3fwbgDlQLQzyeCFw/t7y2pjlrFcQ/o8pP7mi4/8sPNXEaWIaRQUK AkovFBj9K9A++NWk61Vd04Uc1ajYpDM= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=oUd4oho2; spf=pass (imf19.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.176 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=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=1703189099; 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=25+JPAVVR93qloIeZBPh87TvRbXcdeZ++9g3nzTCJ2g=; b=oUd4oho2PQFVBsMx441Y1BJ9xZLJRj3/NEa+HI+PvsMu+h8/Evf4eJR6JIIS7+fS93FGb7 Ih/Fyn0cbQWAZzwK+nS3P7ZRUaf95dp2MAee2vmD/jR6DwOerV5e/55LchsDaXoVGmFMIn 0QPWF12bI5PU1x2N2e+NkASW14dnAIM= From: andrey.konovalov@linux.dev To: Marco Elver Cc: Andrey Konovalov , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm 02/11] mm, kasan: use KASAN_TAG_KERNEL instead of 0xff Date: Thu, 21 Dec 2023 21:04:44 +0100 Message-Id: <71db9087b0aebb6c4dccbc609cc0cd50621533c7.1703188911.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Stat-Signature: htk5uwabczakiu4hhqr9czeub9oq4f5m X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 5F6961A000A X-Rspam-User: X-HE-Tag: 1703189101-888792 X-HE-Meta: U2FsdGVkX1+9F07nKVIspvmOrtQreAOq7P9ufFztW0qeNVhyicNAgMSR0X3WvhiCsf8Qzw2qnNeCE54cJJ5ikkhAE0MuYxnr1O9S0iGYJHQGhXIJmVGD9jyC1MDiS/u8ndk3IiRGdiRdwNoR+DAyZi7fCo+BznH+D7+3wUmKhshNjLsFDJ+imd4qZvsctr5MHHSR0pZk757knUw11j3RqU5oBIJWq7cHOCtrp6tk/XMOpJ16JPktzQwOfAeySK+I0fden2u64SFiHfP/DszVm2bKsabvD6ElJJdDvSIxmS7u61HllVH6WMjTjIO82S34YIkvecO6Nxsr8qFip0ipvXFZIOL3TZSLyT24E+oC/B3YGPqtFq9U64dymqENxQ3zQNu/4Bm9xX/qmicNVFWSN26yf6ftJxQDGM6x3F0HAlkvpYposMA416a6t9/4pstlSwQV1o9wsNko61sW6uVJWMMb2R+DPZzkkOq71S7LbSw+68zuLNW82vksmvmpPx7U5L1S7u4M2FsjwT20UpLQPtfViurfnFWewIjRdQunA7YTegqoYacQOoIRxpx5HoYiI+PERbLD4MIweFmOwD3aWNfb8HlOHTQM0KUtD9TYpng9wfqatuMgRLQ5ChuFYJ5O/m9p5hHq58UjWbKlLwET2icGVxT9Yg7rn+QseuvEmmubYPaCMNyDdGeJ8mC3S72aD5ihHPhylMRZo9o4fhRgxWYntzLJ/yvEPPbPdddtmWDaJJ+shy3rV0HHKGwNKPXqPspCd/YFWM4VUpniTDVAKhOz7xts9rJxdoadZGpWDX7W+6IsUHx7BbGzuO268JX29eOqPU78GowF/fA/cadwsoWyZhTK5nvULDCbKo6LEeK8u4eO3YoYONu1Zof+5uSgWo9MHlBZh/MJPyncvSwnpMC+avM/qDW7+toAVflPG15sN2DHedMed9EwvYXPeO3oCZr5dVCeogvwlgzsIcX yERsPYFA 04lDCYuBNRtvvIe758EMMlpBVrXOH/5wAcRwQJj3K4hh0n4fC1WtgwXYu0kXCTNSxWUSk2cRm99VBp7qYU0tXL9/fy2vj1XoJCJ5humRYJ57iPN5IaP7jQ9uK2VuCZM+LEiRnaMxfkb8jCZbB1BWR3BRktvmCZQlwkE1qMfGjS6VhNah4yW/FB8hULEQqVuDkArmORr+k35L3z4p+lnuKIxfGalcSPQnXQgpQeIYRVM4+ZKQq3W+OXxEq+acjZksArDvA 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 Use the KASAN_TAG_KERNEL marco instead of open-coding 0xff in the mm code. This macro is provided by include/linux/kasan-tags.h, which does not include any other headers, so it's safe to include it into mm.h without causing circular include dependencies. Signed-off-by: Andrey Konovalov --- include/linux/kasan.h | 1 + include/linux/mm.h | 4 ++-- mm/page_alloc.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index d49e3d4c099e..dbb06d789e74 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -4,6 +4,7 @@ #include #include +#include #include #include #include diff --git a/include/linux/mm.h b/include/linux/mm.h index a422cc123a2d..8b2e4841e817 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1815,7 +1815,7 @@ static inline void vma_set_access_pid_bit(struct vm_area_struct *vma) static inline u8 page_kasan_tag(const struct page *page) { - u8 tag = 0xff; + u8 tag = KASAN_TAG_KERNEL; if (kasan_enabled()) { tag = (page->flags >> KASAN_TAG_PGSHIFT) & KASAN_TAG_MASK; @@ -1844,7 +1844,7 @@ static inline void page_kasan_tag_set(struct page *page, u8 tag) static inline void page_kasan_tag_reset(struct page *page) { if (kasan_enabled()) - page_kasan_tag_set(page, 0xff); + page_kasan_tag_set(page, KASAN_TAG_KERNEL); } #else /* CONFIG_KASAN_SW_TAGS || CONFIG_KASAN_HW_TAGS */ diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 7ea9c33320bf..51e85760877a 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1059,7 +1059,7 @@ static inline bool should_skip_kasan_poison(struct page *page, fpi_t fpi_flags) if (IS_ENABLED(CONFIG_KASAN_GENERIC)) return deferred_pages_enabled(); - return page_kasan_tag(page) == 0xff; + return page_kasan_tag(page) == KASAN_TAG_KERNEL; } static void kernel_init_pages(struct page *page, int numpages) From patchwork Thu Dec 21 20:04:45 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: 13502599 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 4CDF2C46CD4 for ; Thu, 21 Dec 2023 20:05:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 438F06B0083; Thu, 21 Dec 2023 15:05:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3AB476B0088; Thu, 21 Dec 2023 15:05:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 181646B0085; Thu, 21 Dec 2023 15:05:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 063F86B0083 for ; Thu, 21 Dec 2023 15:05:04 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id CFBB9A171A for ; Thu, 21 Dec 2023 20:05:03 +0000 (UTC) X-FDA: 81591904086.23.110B37D Received: from out-172.mta1.migadu.com (out-172.mta1.migadu.com [95.215.58.172]) by imf21.hostedemail.com (Postfix) with ESMTP id F1E9B1C0016 for ; Thu, 21 Dec 2023 20:05:01 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Gsy7nZlb; spf=pass (imf21.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.172 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703189102; 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=KWohJbv99PLbGcicyqYuN0s/R1C+lxZK4GlvmO4roNU=; b=MW0veVzPIQwr3vTMK5OA4/LynBsjW19GiOGi/KXu2O/l+dg9iXbME9sAt/UFAkRItZygD4 +ER3EkF2Wr39mo8F29k3OHfCCyge76htnen7r4JkF0XBeVPwx981r/HVAzskggqKiyFpyH bmeJJS9/KbmkgRMlTWT9jYTQ59bFIPM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703189102; a=rsa-sha256; cv=none; b=WRcGx2D87XSe2EQ5jG0Qz0jRHKOynDx6Vc0L8my4dfdcBf9YN+xETS+WewhBWrpfFGAvBu MbPOr9PTNhrXaAGxUrQf4k/icOPVgw+vS1CoX6y2OJfLMN90LgxoLeNULY1ExIBUt06WnJ lGJS7WP3VKU0isTnJehFqQDYAek6Tvk= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Gsy7nZlb; spf=pass (imf21.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.172 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=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=1703189100; 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=KWohJbv99PLbGcicyqYuN0s/R1C+lxZK4GlvmO4roNU=; b=Gsy7nZlbu3H2IDnesAWQe9qDJ7nAP2p+eXRNRSe4j32CC4JwsP4uLzkQ4/jEEkvX8mdv6F CcL25sh8fWcrq+2FBZ5UvJ9asZqD0ZHeEOOP3+qLu1cMEpc6sPWjqhJ9qWg89a+PRbHrc2 K5hSrC+2HrBEnLQVSDx5tp5XvH3drbU= From: andrey.konovalov@linux.dev To: Marco Elver Cc: Andrey Konovalov , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm 03/11] kasan: improve kasan_non_canonical_hook Date: Thu, 21 Dec 2023 21:04:45 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Stat-Signature: 5r83cnkntujky6h3zaau7ontuww8xqzz X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: F1E9B1C0016 X-Rspam-User: X-HE-Tag: 1703189101-254883 X-HE-Meta: U2FsdGVkX19UQZSIwY9GEclHgXjpQyt6wRX5CwoPiT2tOzfYarNXG1dFH/CAHi6WZzmTczpamPw8h5pe+xAF+WWTSBmb3A6eleYTP5aYtPW4FTeDctmrqP9x5RXly5zQtlVcGOPE15iR0YMOfulDnMFt+yIVkoDloFAlm3pK41/95ErLcuJsJRodjmW0nRLjJj9fseMBfp3VXkcgG6+U5u3AlhIdsVK+a7GguN9wEDvmTzRwCwIRHBwm9sfJb8mpvw2bw7rg5Jff0Qqlbw+WdljGWi04MwtzlGpOBZwlgAf1r3KdLeSlmSNLatmNSIHY4gtsDHJ1q7j3PPxfEIfdblhsijcKuDsTGYG2Rvl41WQB13R9D/WTB9WdYZ4LYMC23eUWKYP6kaXHnFOaT8X/L2rKoyJPiN3kDcWFP12bF7SjOnPebO8oMCLd44mXLM8qKpO0DjHLCJOP5Mia3dmHpMhA6zbH/2O7SEEFejT5NWouVckGzowewfboQBZ/8fHNuqR+IrJgDu67gbU8l2k0/IAgk1uw+mLbeJBO0ikbAsZeKBqKYCcJT5CJmf9uaoMvPK4oRsMn3ktou/DOoMA5VuriKBiYG7k13DgNAqFJJTRuvmqk+nruLHBwO1AJ3nSD4tYvtu6ExQ9GdVoDYQ06K0JXy9wWHWg8WH2hShxaLmnuzDd0LsghHMSd1WoTmSU58vLS9eYTaWbnOm4uRCp/Q+hmgTQ2rYU/ZDW0V777E5qDmBK1vVf4MSB+N64QnLxqNAov+elbFSBdVq72Zcq5WK/5vIQ3Jttgt42EGIlNPoPnQT5NS9taKNWJC0G4rO3bZf8rederXiujZn0H3jKyYwZwpJ39OeAFKtMkb9ij0NHGMlHslQrBtaHRExkXoKZ7XshFRE79eYJrcdmuu85T4a849rr1pEgzZemmF9D65LCDSk2PMXUeIXuNg3jcifeaC8gA9HyECUZIm5moWxM a4SnOpNf yZvJOi9ZoVMmUUxKJ3PAHEph/qxJd+3U2ZlDGKD5f/jv1tnN43Akd801+9K6Dp51JYOCotRQ32EAqP56N0QjSQQj218c32JdzDcLsYngHNpIi0Xf+1oF19gGmNNo8G5WlL3GRI2tYNF2ItvOLff+XVSXupGrVfwgYd0SyGveNyyQmYBWe65A46Ltbfp0u85Y0pQUcNlsz8GOcG93Z1zu4VIQluISZ0K8yfHDG 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 Make kasan_non_canonical_hook to be more sure in its report (i.e. say "probably" instead of "maybe") if the address belongs to the shadow memory region for kernel addresses. Also use the kasan_shadow_to_mem helper to calculate the original address. Also improve the comments in kasan_non_canonical_hook. Signed-off-by: Andrey Konovalov --- mm/kasan/kasan.h | 6 ++++++ mm/kasan/report.c | 34 ++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 69e4f5e58e33..0e209b823b2c 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -307,6 +307,12 @@ struct kasan_stack_ring { #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) +static __always_inline bool addr_in_shadow(const void *addr) +{ + return addr >= (void *)KASAN_SHADOW_START && + addr < (void *)KASAN_SHADOW_END; +} + #ifndef kasan_shadow_to_mem static inline const void *kasan_shadow_to_mem(const void *shadow_addr) { diff --git a/mm/kasan/report.c b/mm/kasan/report.c index a938237f6882..4bc7ac9fb37d 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -635,37 +635,43 @@ void kasan_report_async(void) #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) /* - * With CONFIG_KASAN_INLINE, accesses to bogus pointers (outside the high - * canonical half of the address space) cause out-of-bounds shadow memory reads - * before the actual access. For addresses in the low canonical half of the - * address space, as well as most non-canonical addresses, that out-of-bounds - * shadow memory access lands in the non-canonical part of the address space. - * Help the user figure out what the original bogus pointer was. + * With compiler-based KASAN modes, accesses to bogus pointers (outside of the + * mapped kernel address space regions) cause faults when KASAN tries to check + * the shadow memory before the actual memory access. This results in cryptic + * GPF reports, which are hard for users to interpret. This hook helps users to + * figure out what the original bogus pointer was. */ void kasan_non_canonical_hook(unsigned long addr) { unsigned long orig_addr; const char *bug_type; + /* + * All addresses that came as a result of the memory-to-shadow mapping + * (even for bogus pointers) must be >= KASAN_SHADOW_OFFSET. + */ if (addr < KASAN_SHADOW_OFFSET) return; - orig_addr = (addr - KASAN_SHADOW_OFFSET) << KASAN_SHADOW_SCALE_SHIFT; + orig_addr = (unsigned long)kasan_shadow_to_mem((void *)addr); + /* * For faults near the shadow address for NULL, we can be fairly certain * that this is a KASAN shadow memory access. - * For faults that correspond to shadow for low canonical addresses, we - * can still be pretty sure - that shadow region is a fairly narrow - * chunk of the non-canonical address space. - * But faults that look like shadow for non-canonical addresses are a - * really large chunk of the address space. In that case, we still - * print the decoded address, but make it clear that this is not - * necessarily what's actually going on. + * For faults that correspond to the shadow for low or high canonical + * addresses, we can still be pretty sure: these shadow regions are a + * fairly narrow chunk of the address space. + * But the shadow for non-canonical addresses is a really large chunk + * of the address space. For this case, we still print the decoded + * address, but make it clear that this is not necessarily what's + * actually going on. */ if (orig_addr < PAGE_SIZE) bug_type = "null-ptr-deref"; else if (orig_addr < TASK_SIZE) bug_type = "probably user-memory-access"; + else if (addr_in_shadow((void *)addr)) + bug_type = "probably wild-memory-access"; else bug_type = "maybe wild-memory-access"; pr_alert("KASAN: %s in range [0x%016lx-0x%016lx]\n", bug_type, From patchwork Thu Dec 21 20:04:46 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: 13502600 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 B4E36C35274 for ; Thu, 21 Dec 2023 20:05:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DBBE66B0085; Thu, 21 Dec 2023 15:05:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CCC106B0088; Thu, 21 Dec 2023 15:05:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD04C6B0089; Thu, 21 Dec 2023 15:05:04 -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 9BB546B0085 for ; Thu, 21 Dec 2023 15:05:04 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 62B64120CDB for ; Thu, 21 Dec 2023 20:05:04 +0000 (UTC) X-FDA: 81591904128.19.3E5BDE3 Received: from out-173.mta1.migadu.com (out-173.mta1.migadu.com [95.215.58.173]) by imf08.hostedemail.com (Postfix) with ESMTP id 8F577160024 for ; Thu, 21 Dec 2023 20:05:02 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=T3Q2NIda; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf08.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.173 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703189102; a=rsa-sha256; cv=none; b=tXNs0zMmReKzWLmxNftf5eF1UFNU7CyrEg8mZuIGiLu81U++NtreKZ7oMTSZUJ8Qwk8mwx 7OPTJ0LFV3/2IrjlssB2PVjo/Nrw0mbNZMkKTI/vf6gXJglyvgNpyjf1T+G1uqLh13b47k gXeZirIujFJItVqM9jcJ3UtGXWhfVX4= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=T3Q2NIda; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf08.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.173 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=1703189102; 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=02IeghrfT0ytg5MuYoXhCbr9XM7hY33pPyxRWGvQP4Y=; b=8JH159qFYm5XjnOPhFqFP0aAl90qkJq3OWnWPn4gK5/c6y+Tlf2nCmSsJpP5xLBbH43j97 KhH+S7zdifu7q4ovINhVF0Tm2kZ1DtLzoIPGLOtDJecu3nR1Pa4NBQWC6ez1tgf6L2xrkw b+VQdlh/WcZshc7VvsH4aBQ1vsTok1c= 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=1703189101; 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=02IeghrfT0ytg5MuYoXhCbr9XM7hY33pPyxRWGvQP4Y=; b=T3Q2NIdanun939NScwaTG7WLvoYmfTTFiLEYJ3J+HNG2IsD+W9B/KY5/3GWHlronvX+HVx UO/qV9RzLo7I2y0mo6AY2SLB81+1FFxAYBxngYWc6AIhArd5EEHVGN3+RLEDZyXA+UgF4y 2f6iUwmX7QGqhFZ2rrVU/A585fQMbwc= From: andrey.konovalov@linux.dev To: Marco Elver Cc: Andrey Konovalov , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm 04/11] kasan: clean up kasan_requires_meta Date: Thu, 21 Dec 2023 21:04:46 +0100 Message-Id: <8086623407095ac1c82377a2107dcc5845f99cfa.1703188911.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 8F577160024 X-Stat-Signature: xonxrk7au67w6nd89r476edt7tcigq11 X-HE-Tag: 1703189102-234254 X-HE-Meta: U2FsdGVkX18e+pxw8uPM48xhfsKJsXuRy8eFfoYhijNT/eu3XXGAd5ysU75I6HaaBFC11/E1zWmYHulMi2mru0jice+Zs9WvWc7SKnHxS3aXD/vPdlmH7lg2joYkXdR9ia4RWNK0DWsFjxF63KkC6FFTwusV094fftAYE3nr/HiyTtg+Ge2JfKvh3zb1vEPcESC7J8jpiWOAV362aFDYr/KCfOwhKXuxmHQbQ0QfTPwvJcM3M7GYoJcXesNhdDboXxSW0k2S86l852fsi3rjJDOC46XjUIGdHhlNoZzeE8nMptnjXzpBk9ib6eo+uI0zpEEZXWenXHGp3/BRbm/BPsq5rmPFP1ZxWasicZaaYklMTv80YF/VjYHmnI5lOdte0zT3ZcWXx0ivB1QQQYLd7nv5lTIJtB/ehvK2F0M9veZgpp696ucY1YFWnJoS26wOvsRmWqDASRkkPd3AauW9PMfRKxdhAnnxnbI4EAHeVxpLIGuSpzpbeR7LGYbDqPHVad5XCg3N9LMowL7dGacnFg8Sesjh6tXqmDwNd+jHmR2Q6wAYQCZR5LbfrJEItrdzrhKxuIt8LulMxaWYek2zwjyOw6WLCVO7DQDS0zz4gXmmvnmLziEv/yhwzkE64Cib8VgYajIgpPuzFRd04YEoY7qNXA39YD9D+GIiI8EU8yVYhcerisMLbAto3b9rRZToMYpCNv3o+6MDzsh4qXyUbCxJdiVm6bHzKwp4LS1UNVnEmHuDW7XVwZlM9cjWi+277vUEHwTrraOrGX3kEJZzUosL7WIsuzsGJ8hoWlv+o2vgIKDKTiMIUkGzetZz1sVF95pqRaRMmLeMfqlGaw3rRY/WBXh8KErAvUS0Nn8LSY/ItM973RAaLuBZuCFEv8N4Q2F3EdeqlDti3hLF+mGJ7qB7BwENV+DBGon8ktl6jl0LcFsGaIaafv6nu4YniEF75PKTuyGlleR5AZAQR5u lxRvHVYo k2tIT1JemRfzyVAtWa02i9S/JLy79GzLf3+T0Hsevq+FuJkFiQ5kqpJSQfdVjaVFsIAIQ7aAr8H4nwZuYyjtOaXDnPY6CxNd98pKYHMSETi9g8liq9D0Es3+l6H68xxekZsqnqGBut9pCJ3FCyCkx7wk+ppg9ebq4GPxp0y4B2XR+b+DmGTDLEHzHD0HGVEuuQDv/sXI/wnT1efuEXrld+t9Dsg== 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 Currently, for Generic KASAN mode, kasan_requires_meta is defined to return kasan_stack_collection_enabled. Even though the Generic mode does not support disabling stack trace collection, kasan_requires_meta was implemented in this way to make it easier to implement the disabling for the Generic mode in the future. However, for the Generic mode, the per-object metadata also stores the quarantine link. So even if disabling stack collection is implemented, the per-object metadata will still be required. Fix kasan_requires_meta to return true for the Generic mode and update the related comments. This change does not fix any observable bugs but rather just brings the code to a cleaner state. Signed-off-by: Andrey Konovalov --- mm/kasan/kasan.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 0e209b823b2c..38af25b9c89c 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -101,21 +101,21 @@ static inline bool kasan_sample_page_alloc(unsigned int order) #ifdef CONFIG_KASAN_GENERIC -/* Generic KASAN uses per-object metadata to store stack traces. */ +/* + * Generic KASAN uses per-object metadata to store alloc and free stack traces + * and the quarantine link. + */ static inline bool kasan_requires_meta(void) { - /* - * Technically, Generic KASAN always collects stack traces right now. - * However, let's use kasan_stack_collection_enabled() in case the - * kasan.stacktrace command-line argument is changed to affect - * Generic KASAN. - */ - return kasan_stack_collection_enabled(); + return true; } #else /* CONFIG_KASAN_GENERIC */ -/* Tag-based KASAN modes do not use per-object metadata. */ +/* + * Tag-based KASAN modes do not use per-object metadata: they use the stack + * ring to store alloc and free stack traces and do not use qurantine. + */ static inline bool kasan_requires_meta(void) { return false; From patchwork Thu Dec 21 20:04:47 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: 13502601 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 27AC6C46CCD for ; Thu, 21 Dec 2023 20:05:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DE03F6B0089; Thu, 21 Dec 2023 15:05:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D682E6B008C; Thu, 21 Dec 2023 15:05:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C0B5D6B0092; Thu, 21 Dec 2023 15:05:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id ADAD96B0089 for ; Thu, 21 Dec 2023 15:05:05 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 5B317A160F for ; Thu, 21 Dec 2023 20:05:05 +0000 (UTC) X-FDA: 81591904170.30.ACE2898 Received: from out-187.mta1.migadu.com (out-187.mta1.migadu.com [95.215.58.187]) by imf30.hostedemail.com (Postfix) with ESMTP id A78E08001D for ; Thu, 21 Dec 2023 20:05:03 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=D1d+7ZX8; spf=pass (imf30.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.187 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703189103; a=rsa-sha256; cv=none; b=y+/VmDa9SnfIuKvnAlQWDLEm9SUKwGZ3YjJmKC/EfKthcco0jsiJLO1yqbnTO+P9ELakl9 4k1lSGo5J5qAe6lgjmFjW6Zb0n/JoH5TR2IYfwVC63u2mMkLSbg/XtgmcwkmtIvvUIV0ZJ FC5vc226ntomwVzLvaboRpk0PxF1W6o= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=D1d+7ZX8; spf=pass (imf30.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.187 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703189103; 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=yJpT5npX9+Mi4/2vKIXBMX5Zb3QcQCwOWJP1qz8pE0M=; b=ucBQJLM9/Uc0hVLiffB5S2XfyYLM+nYfkTajUCj1y0preLz+x/4Zqcd3AcOTJB3n4C1hFQ iJUz8M2DZgvfYqmbCcry8E/XMDMrM4vE9/4HEQKg1fAc2LLnIeCUGEISHHcB6X2QYdU5mO DitGZIhTtIWsXczBc+QBAIlS0rlYHnI= 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=1703189101; 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=yJpT5npX9+Mi4/2vKIXBMX5Zb3QcQCwOWJP1qz8pE0M=; b=D1d+7ZX8K/5XJRivQkOs08EDlsgfMyw9smPDLE+z0+/A5XJO1xiUqRuZmE0KKjzXfCVjOl B9Re2Z/G6jvedBYwergcLq/h7gQe6/xiCIpFFxCDZnzStwThLFWfJDZzzYMVmxbBjsmc1F kpPC6wGFc7aq4172XBiDkq6JKDgFx/0= From: andrey.konovalov@linux.dev To: Marco Elver Cc: Andrey Konovalov , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm 05/11] kasan: update kasan_poison documentation comment Date: Thu, 21 Dec 2023 21:04:47 +0100 Message-Id: <992a302542059fc40d86ea560eac413ecb31b6a1.1703188911.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: A78E08001D X-Stat-Signature: 99tnrzawps6z3e1areqgax3d9iwe9d8z X-Rspam-User: X-HE-Tag: 1703189103-436621 X-HE-Meta: U2FsdGVkX19coLkKC0MtJFx6mc9fxAIsmUrb62Fg9mPvd0HWGL6Ef3u+oQrqB/pC9opOH2X40QYES9W94yUi0seS104oqjgKrbbGXXL/7oZrQqH0HSHfoFF8EQ1uHhkWDAMooxdjV2se2BRaperDdiH4wDC9m3IQi/FZ1SC4ZmMITEk11iO02JvhakLdpyaBH50zrjZu8V8OM/lX2FNdweQqZagvBd3iWQ56Iu8hdy3w9borJFkulP3SEerArOrsMKPrTlnID+xy4VX4fPp1jOoq874fK+KSp982ScvKMrLR6C/mPpuztPIxQFjDQy0urGee/gpERiNBJHdQvZ9Be1qm/fWHMRvVKGhGcVyVAXk0EWh0O6EfHQraQRlmViHfkXqSFFOAr0MSFOSPrCt5iqDDCK9WOjht7VoIwtotLrQx4ptRcEir5UBi2GOdfU5u9CpV0oCgTTCp5owcv6gkm2O7FE0T2XdksU9cVghuJFjWVea8SEz5GZJ3B7u66EtS8/FByFHG3Ws9DADhWAMWGDlFqFZIDMYhL98bo920yxw77DNo2dpNq+uGIwPeMHb10ZVqod1VU5M3HIPtRlnx0/GwfN+xbQOPVN6lqLc64KoVrWImmA1+ov1LCKBVCbWR+d2PI0Glqjttd0zM0bwypAgpjB/OLDHlz4P0VqwzHefFnvh8H7uAIFpdA14GjP7qUp/Ukax4NklsUTDeBNX/BqJdtf10rofIhrVpDP4kk30FVNJF45wPZ8ncgsvvoY1Ax/p3Kiy0J6B5oHkKmCA3GiS71f8I6Wu7DtQGoT9V1q9aXrpxaiMbOVe9n7/Bfkan9hJ8GhamqzedBK2ooEcZ83uH/16e5CUiBuyMSBEM0UskM6VXVbO5yO9Zu8dU3DGzXyEWa4bSJTYG3gmHmEJQQbQBuOChOI8NKsy9Zcb3OMECOXc6JKHTgjmlCE1Bx4h2RhL3CCJkJ6sgjBKFDyL 1FNBlJjP CXBdN3e5vYnE+anaX5qyqTW7Q7ighWUGVnuHql5I44KpYkJOsg2h0mFZCgkgMwSjmDU1HgD96pyxk9PrwrYTooTSfAYOiSdPNPiKC5kjgWODADWKCm84UkSjsa83wzw4bvc0AVdwLsomeqCFNR+YO+3w+tLzC7KNVwAQZLt5hcDNVzQ0LJp1IeSMquMrQZLKvtCz1ARNdIANR3wXDq2jdGQH5Lw== 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 The comment for kasan_poison says that the size argument gets aligned by the function to KASAN_GRANULE_SIZE, which is wrong: the argument must be already aligned when it is passed to the function. Remove the invalid part of the comment. Signed-off-by: Andrey Konovalov --- mm/kasan/kasan.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 38af25b9c89c..1c34511090d7 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -513,8 +513,6 @@ static inline bool kasan_byte_accessible(const void *addr) * @size - range size, must be aligned to KASAN_GRANULE_SIZE * @value - value that's written to metadata for the range * @init - whether to initialize the memory range (only for hardware tag-based) - * - * The size gets aligned to KASAN_GRANULE_SIZE before marking the range. */ void kasan_poison(const void *addr, size_t size, u8 value, bool init); From patchwork Thu Dec 21 20:04:48 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: 13502603 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 1E4D5C46CCD for ; Thu, 21 Dec 2023 20:06:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0C1EC6B0099; Thu, 21 Dec 2023 15:06:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F3D776B009A; Thu, 21 Dec 2023 15:06:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF7EA6B009C; Thu, 21 Dec 2023 15:06:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id B69E86B009A for ; Thu, 21 Dec 2023 15:06:08 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 91694A053E for ; Thu, 21 Dec 2023 20:06:08 +0000 (UTC) X-FDA: 81591906816.19.BEDD2A9 Received: from out-174.mta0.migadu.com (out-174.mta0.migadu.com [91.218.175.174]) by imf18.hostedemail.com (Postfix) with ESMTP id 8BD431C0034 for ; Thu, 21 Dec 2023 20:06:06 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=b9Brp+Gw; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf18.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.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=1703189166; 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=gSZaD965ObbhfRb2wl16gx9k0NFu/9CcW8O4J7mEceM=; b=ThdUr+GO6nQAY55/nP2UkwgEq1skHP07ToKPww7oF6ndjzSpzpFEMF8clwybyBgLwi4zjc ie5gozSsa2FcIQvHGmmR5n3d7vDHRWudxoK4tLtggaUyGFkbzgYVkWhEsRKmVY5Z21UPH2 pXTerQlrXb8dmSdYyDrXkmSBn3tHML0= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=b9Brp+Gw; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf18.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.174 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703189166; a=rsa-sha256; cv=none; b=suCkBB5dgoxxAGV+zzF0zf4LBAxRMwueoF05/xADDdAsARuptygbaKFyKMX6guhTqCiGU5 i77BcKaCSsPK10bv5eL7udWBx8irXhjfHham6YLlZNjAIB6dO4Si56A2y1FPsMuyORdAhL 3B3ErwYPG1RizkhzBBuQ9NvrI4NHizU= 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=1703189164; 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=gSZaD965ObbhfRb2wl16gx9k0NFu/9CcW8O4J7mEceM=; b=b9Brp+GwaAs8486L9eFNPsKBa+ZcAtwpfYQSQNwgNbwsobfM5YdIdTv7QlTk+BZjKdK9i+ vM+1DvB2mrXJOSHWT8Ex00o2C9qkxJuCHnbWABmaNBRFH42VhSFNwm8VJ/Zi/RdPA/9XKa vQ9svxQBNSQqoxiVPrTTZhhN4tftlRM= From: andrey.konovalov@linux.dev To: Marco Elver Cc: Andrey Konovalov , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm 06/11] kasan: clean up is_kfence_address checks Date: Thu, 21 Dec 2023 21:04:48 +0100 Message-Id: <1065732315ef4e141b6177d8f612232d4d5bc0ab.1703188911.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 8BD431C0034 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: p1nqqx9dnu66qxp3tiqxk1et5c6obbfh X-HE-Tag: 1703189166-928846 X-HE-Meta: U2FsdGVkX181khkMI6WUEV1+F2u39m8BzhqyaWuMGZN777RyJO8e3A48SKcX2gBvidsUOqHHH1no32/G0naD7NB8ckkBv6IGf+OdZnucILkDqJ1R2EDu5r8jQId9i7mUtvbkM6FGQAJkEPVTuyL9iNggLzplbfvgNGqZ5Ms5oPjiMmzenikPNgzQnag5StB+SR6mp1Bs9QJv1LAV2VrNRXmNJlvvTNQNdRu1NIaGJbpDIiwueQb0qKSLvBm+sp5NPjBaOmW71ZbulTGKL3mXYDx0bL2I6sHVouk0JdglBrkCmbJ6oRkVmUOHsDuEldLf3bMJjiasD49d16Chq/v4Q0AgMb/IyOIs05ZyTwzx84Agqp6hcnrHwCdqDLXsKTOaalEZid/QN4k9LPtiyCrJPOsi1MnOgxlQ8TEaLK92oGED3cndU5zMATBZ9ItYMt/CfFEZn6Q5ftErMkR17AH8tkjz9g+s9MrKVqh3jVPkP7lrfSAxjxNd2Kp5rIRmJQjG5V7B/pUX7H1Bn40/+M2OJpzccwQHlxsUXyBWPSG3vgfmIuzCi7nEBtybqIbR2ZPIG2x9q1mg/dZHXDRWurYpJ3KdRil9jdOUwc48DCJAE5bnmNETFVXycptLi7X/RETBKyyHvSgWyTIOvfe+znWrKPD1TLBKEPNO2tCLMuNKfepThdYMffUpByGgMZkmmVXvH5XU0mQoKFhhh37fFC/aXErgNcS0G7zo6np32CgIzIKsuWDYihg2Z8LT/NZwIR6OJshkbdXyjI1ihL1YMK0I+1p5i6nYmZw/ZcscPfts925ZHxWxFMGOQrT+JFZV5zWlzN2pbPxTjTSpUh5fpsYsINZCRDVsJ6UNQSSO6s/4Pt+nboSVLs35avJNNd7vP1aPFjAqV2R1qHsCPzEzmPculIC6YVSiIZa+MjcXfaZIxYUnTi9RphFca1440MbdVkSDmmpChx1G5c/d0n11tFX S4q1OGZB 5wddwVuOq1s1HzHfsT92bvE9YCh8HelNfCzCYK66RamESJNK4D2AcFeGkMHhn0wsg0lGr06rCGFJUiji51QSgaDnC8ygys/TwKdDrWV4kJ0LnZTCyEhDXeI1PnLoq1qfN7Gp4dMftLKSJ9cK9SrOrMS+3Vl67rKzrS07MEUrJLrmo0qe2w0cfXQWa9wGRRtTiOASpQ/Zkk22EJK4AY1W8ibqS6xTwcOQi3TlA 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 1. Do not untag addresses that are passed to is_kfence_address: it tolerates tagged addresses. 2. Move is_kfence_address checks from internal KASAN functions (kasan_poison/unpoison, etc.) to external-facing ones. Note that kasan_poison/unpoison are never called outside of KASAN/slab code anymore; the comment is wrong, so drop it. 3. Simplify/reorganize the code around the updated checks. Signed-off-by: Andrey Konovalov --- mm/kasan/common.c | 26 +++++++++++++++++--------- mm/kasan/kasan.h | 16 ++-------------- mm/kasan/shadow.c | 12 ------------ 3 files changed, 19 insertions(+), 35 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index f4255e807b74..86adf80cc11a 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -79,6 +79,9 @@ EXPORT_SYMBOL(kasan_disable_current); void __kasan_unpoison_range(const void *address, size_t size) { + if (is_kfence_address(address)) + return; + kasan_unpoison(address, size, false); } @@ -218,9 +221,6 @@ static inline bool poison_slab_object(struct kmem_cache *cache, void *object, tagged_object = object; object = kasan_reset_tag(object); - if (is_kfence_address(object)) - return false; - if (unlikely(nearest_obj(cache, virt_to_slab(object), object) != object)) { kasan_report_invalid_free(tagged_object, ip, KASAN_REPORT_INVALID_FREE); return true; @@ -247,7 +247,12 @@ static inline bool poison_slab_object(struct kmem_cache *cache, void *object, bool __kasan_slab_free(struct kmem_cache *cache, void *object, unsigned long ip, bool init) { - bool buggy_object = poison_slab_object(cache, object, ip, init); + bool buggy_object; + + if (is_kfence_address(object)) + return false; + + buggy_object = poison_slab_object(cache, object, ip, init); return buggy_object ? true : kasan_quarantine_put(cache, object); } @@ -359,7 +364,7 @@ void * __must_check __kasan_kmalloc(struct kmem_cache *cache, const void *object if (unlikely(object == NULL)) return NULL; - if (is_kfence_address(kasan_reset_tag(object))) + if (is_kfence_address(object)) return (void *)object; /* The object has already been unpoisoned by kasan_slab_alloc(). */ @@ -417,7 +422,7 @@ 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))) + if (is_kfence_address(object)) return (void *)object; /* @@ -483,6 +488,9 @@ bool __kasan_mempool_poison_object(void *ptr, unsigned long ip) return true; } + if (is_kfence_address(ptr)) + return false; + slab = folio_slab(folio); return !poison_slab_object(slab->slab_cache, ptr, ip, false); } @@ -492,9 +500,6 @@ void __kasan_mempool_unpoison_object(void *ptr, size_t size, unsigned long ip) struct slab *slab; gfp_t flags = 0; /* Might be executing under a lock. */ - if (is_kfence_address(kasan_reset_tag(ptr))) - return; - slab = virt_to_slab(ptr); /* @@ -507,6 +512,9 @@ void __kasan_mempool_unpoison_object(void *ptr, size_t size, unsigned long ip) return; } + if (is_kfence_address(ptr)) + return; + /* Unpoison the object and save alloc info for non-kmalloc() allocations. */ unpoison_slab_object(slab->slab_cache, ptr, size, flags); diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 1c34511090d7..5fbcc1b805bc 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -466,35 +466,23 @@ static inline u8 kasan_random_tag(void) { return 0; } static inline void kasan_poison(const void *addr, size_t size, u8 value, bool init) { - addr = kasan_reset_tag(addr); - - /* Skip KFENCE memory if called explicitly outside of sl*b. */ - if (is_kfence_address(addr)) - return; - if (WARN_ON((unsigned long)addr & KASAN_GRANULE_MASK)) return; if (WARN_ON(size & KASAN_GRANULE_MASK)) return; - hw_set_mem_tag_range((void *)addr, size, value, init); + hw_set_mem_tag_range(kasan_reset_tag(addr), size, value, init); } static inline void kasan_unpoison(const void *addr, size_t size, bool init) { u8 tag = get_tag(addr); - addr = kasan_reset_tag(addr); - - /* Skip KFENCE memory if called explicitly outside of sl*b. */ - if (is_kfence_address(addr)) - return; - if (WARN_ON((unsigned long)addr & KASAN_GRANULE_MASK)) return; size = round_up(size, KASAN_GRANULE_SIZE); - hw_set_mem_tag_range((void *)addr, size, tag, init); + hw_set_mem_tag_range(kasan_reset_tag(addr), size, tag, init); } static inline bool kasan_byte_accessible(const void *addr) diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c index 0154d200be40..30625303d01a 100644 --- a/mm/kasan/shadow.c +++ b/mm/kasan/shadow.c @@ -135,10 +135,6 @@ void kasan_poison(const void *addr, size_t size, u8 value, bool init) */ addr = kasan_reset_tag(addr); - /* Skip KFENCE memory if called explicitly outside of sl*b. */ - if (is_kfence_address(addr)) - return; - if (WARN_ON((unsigned long)addr & KASAN_GRANULE_MASK)) return; if (WARN_ON(size & KASAN_GRANULE_MASK)) @@ -175,14 +171,6 @@ void kasan_unpoison(const void *addr, size_t size, bool init) */ addr = kasan_reset_tag(addr); - /* - * Skip KFENCE memory if called explicitly outside of sl*b. Also note - * that calls to ksize(), where size is not a multiple of machine-word - * size, would otherwise poison the invalid portion of the word. - */ - if (is_kfence_address(addr)) - return; - if (WARN_ON((unsigned long)addr & KASAN_GRANULE_MASK)) return; From patchwork Thu Dec 21 20:04:49 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: 13502602 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 28FA1C35274 for ; Thu, 21 Dec 2023 20:06:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B47C66B0098; Thu, 21 Dec 2023 15:06:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AD0946B0099; Thu, 21 Dec 2023 15:06:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 971EE6B009A; Thu, 21 Dec 2023 15:06:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 832656B0098 for ; Thu, 21 Dec 2023 15:06:08 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 45F501A0C9C for ; Thu, 21 Dec 2023 20:06:08 +0000 (UTC) X-FDA: 81591906816.20.4F93B9A Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [91.218.175.180]) by imf22.hostedemail.com (Postfix) with ESMTP id 94FA3C0012 for ; Thu, 21 Dec 2023 20:06:06 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=UQy5FdaO; spf=pass (imf22.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.180 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703189166; 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=FJl4ImE4TRrDXvrAPN+dS4cgTUzwQEr6h+ILfia+IPo=; b=8rC09zks98B2ls0WDRR62Ha+cjIY/cYbNlyH3oD31JXfnKSMsRRKh7cWthtywKVsbRAHbF 8bbbJGjZTmU82pNlxihyJK0AZWGKtzFRfMNehw+OzcII4fZYwNTvRpvaG9qFxvRcqaAXxz 4a4tw8V0tgoNgP6KCsy3Qe71fmfvQIA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703189166; a=rsa-sha256; cv=none; b=BX1JLtmWwt7PYw4JSBAhCUyQTxC7oHzfRqlcLpLRmNpxqwr2LWKCr3sEie0/8Uht6oCSK1 diyP9U0nK2R09+HvqD4xTGxLmJfZSjghgIsKBbY7hG7OCqFzn19kaUvIfW8F1ZzsMib+by dWYMZFbEa6luOpJZgzwZbbj4Q10aNJg= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=UQy5FdaO; spf=pass (imf22.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.180 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=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=1703189165; 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=FJl4ImE4TRrDXvrAPN+dS4cgTUzwQEr6h+ILfia+IPo=; b=UQy5FdaOJP3WHcVUkGmBl3aQkcqo5p6PbagnBT8wp0ljLIpod/Ojsrg7YfgnIjF56yHZRq Hho7BHFtctI8tiFKBQkJ21sW2wiU4BcM7mHrjBDpphYej6wGMhj1TMy2nV0GXg97lpUgq8 tU7rBZD5CJd5flB9JqJlXxWqDy6GX1E= From: andrey.konovalov@linux.dev To: Marco Elver Cc: Andrey Konovalov , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm 07/11] kasan: respect CONFIG_KASAN_VMALLOC for kasan_flag_vmalloc Date: Thu, 21 Dec 2023 21:04:49 +0100 Message-Id: <3e5c933c8f6b59bd587efb05c407964be951772c.1703188911.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 94FA3C0012 X-Rspam-User: X-Stat-Signature: 9f6ky3zn4wpxn7wskugizndjqqgruzy3 X-Rspamd-Server: rspam03 X-HE-Tag: 1703189166-894388 X-HE-Meta: U2FsdGVkX186+WA13jMN1V9Njnk/VJtcnaErqo03/d5AXkoEqCMOKRiu4urSkLVFcmDaNrEy4NgdxfgODE/agmXROcvk32yYc1mSXcZGHrh1wa8Zqi+o7FYR/w9cM5bwt1khV9rTuQDHQ0Dd8FHPkXuZLPOUr1TFFuNVaUA+8+xQty2KRVoeigeW6ifxEENEtZZLKt2W9Q3oFiD7M/ZpeAY+kv3YdjH8cgQAT0dfrG6AhV8yuKXMaiSLkVXUrBSacgCuHrPlVC9S19n30p70bwQtBVD2+VeLjQIACTjKbB3bBsdSxSPNHNgv+mz3IxtALpYoPKQfdilYVh2vQm0RLUv6XHpsOW87Sfmtnr1Wthork7O21FC3xXrAkAVIXpAL6M7tUFW+LQd8ZMC217w2WUra0Ybc99iDiuDL/Uv5lYx7a1xYhhH+8dzuEr+Z7v6bh//esoKEJHcEwM5bQcTFcsJfgm+b5bFle/u0P3nGuoJnwet2qvbwf2k52FXuqeH+tQTQ2W9ZuhAgxV6U/1K4rzeWUAoMy8n6D736Jg85+idAdXGeeb28tV/RtAYhVZffJAC3vUsurw2MIUY8eJ3HiXuxsS6/n0866qD+XwTsHFRVJEfxMKE0EgwEnH1nGmlUNNYBdtCxSYFiywDywibDvTtWd/KuNy6LnneyYy8T6O5WFsU87Q/YF0oTa9ENoobfsINGU57KZKK6Hp9JV+PO3IJQ8YpJWrcv8ChpCKJV3rky1fNXXu5kXhZfY3tVGbOleCZ065pvFhClTJo5YyM4dtEgDnJX/lbJo+czBlh3iuYB85l4cvK3tPbGModul1pcB3kJgJZa9DaaXJULsRBQ0iP5GoWeYGJ8Gj73HdBC7Xiw1v1W21xQj/rOm8Ym4+Zc78EHEu7zRTe9bGvxouJGgQHiG2M0znHE8at4xiVfXqBeXgkGsasSJv1Kd+8BblxMzNQ8JMYQ76RvToy4VAJ gFcbC+iN RychmduLpFzNkNxAYB+iddO5r5dLj/Lb+d27Gx9FQ7zTBh8B+ib60ZhWDCX2fAQ+BkwaR5ibMU8wY0aTK121dccYYdHOhv9X7TTpDdlquczGKEHGms1iUr4Jfl+bb41yUYld4qNZ9A5/YwzKn1K/7h18P2h+yxz+NY8Ef/po5o6Du1f7pktlpKyMfisRImg61UBS6iPQrRTI6JIkDxmlQHDmUOg== 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 Never enable the kasan_flag_vmalloc static branch unless CONFIG_KASAN_VMALLOC is enabled. This does not fix any observable bugs (vmalloc annotations for the HW_TAGS mode are no-op with CONFIG_KASAN_VMALLOC disabled) but rather just cleans up the code. Signed-off-by: Andrey Konovalov --- mm/kasan/hw_tags.c | 7 +++++++ mm/kasan/kasan.h | 1 + 2 files changed, 8 insertions(+) diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c index 06141bbc1e51..80f11a3eccd5 100644 --- a/mm/kasan/hw_tags.c +++ b/mm/kasan/hw_tags.c @@ -57,7 +57,11 @@ enum kasan_mode kasan_mode __ro_after_init; EXPORT_SYMBOL_GPL(kasan_mode); /* Whether to enable vmalloc tagging. */ +#ifdef CONFIG_KASAN_VMALLOC DEFINE_STATIC_KEY_TRUE(kasan_flag_vmalloc); +#else +DEFINE_STATIC_KEY_FALSE(kasan_flag_vmalloc); +#endif #define PAGE_ALLOC_SAMPLE_DEFAULT 1 #define PAGE_ALLOC_SAMPLE_ORDER_DEFAULT 3 @@ -119,6 +123,9 @@ static int __init early_kasan_flag_vmalloc(char *arg) if (!arg) return -EINVAL; + if (!IS_ENABLED(CONFIG_KASAN_VMALLOC)) + return 0; + if (!strcmp(arg, "off")) kasan_arg_vmalloc = KASAN_ARG_VMALLOC_OFF; else if (!strcmp(arg, "on")) diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 5fbcc1b805bc..dee105ba32dd 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -49,6 +49,7 @@ DECLARE_PER_CPU(long, kasan_page_alloc_skip); static inline bool kasan_vmalloc_enabled(void) { + /* Static branch is never enabled with CONFIG_KASAN_VMALLOC disabled. */ return static_branch_likely(&kasan_flag_vmalloc); } From patchwork Thu Dec 21 20:04:50 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: 13502604 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 C0D9CC35274 for ; Thu, 21 Dec 2023 20:06:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A36D76B009A; Thu, 21 Dec 2023 15:06:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 94AB76B009B; Thu, 21 Dec 2023 15:06:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 776DC6B009C; Thu, 21 Dec 2023 15:06:09 -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 5A7626B009A for ; Thu, 21 Dec 2023 15:06:09 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 0C16F1C03B6 for ; Thu, 21 Dec 2023 20:06:09 +0000 (UTC) X-FDA: 81591906858.12.35D9DC1 Received: from out-176.mta0.migadu.com (out-176.mta0.migadu.com [91.218.175.176]) by imf08.hostedemail.com (Postfix) with ESMTP id 34AA1160027 for ; Thu, 21 Dec 2023 20:06:06 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=USMsmCfc; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf08.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.176 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=1703189167; 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=ColijDwhDovJxdnzDPHxNzx5OycMVFqUSNs1GHs5mVk=; b=hJAbra9o+ECKGBW3UVm0njra0AZZEbk8qAr6asxIjbIkU9Mqhni/DtvVFcjbVcq93TNIJK uQT5ldTK7A+pLip0DseT+kOIDAyTCaHnaPcmB3wrGNkBjWOcoG/Sm9VSey3IYERIwtY67d ON3Gq9CP9RzwCP5Nzn2LDmClBZ5EX2M= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=USMsmCfc; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf08.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.176 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703189167; a=rsa-sha256; cv=none; b=ASaKPnPqZ7vdd70jbJHuaakgRssS77TcZUFAupq9Wy2x8/XvK1BC6lQUAv0K+W/Noh1lIY xM3QoGNo9mj/r4pbYMX6A6B2ZX2MDJ9qtbB6y6IMIcaM9tMYs3YW8Pay6qnGw85nOPFXzo 2jaZMwE9ul1aEP1bx/Y+1f/EmjmEaNY= 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=1703189165; 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=ColijDwhDovJxdnzDPHxNzx5OycMVFqUSNs1GHs5mVk=; b=USMsmCfcfZYE03AC87Gmpyp9gmlr/kMJv0pWBUPw9nx0sHm6vrJx9MiJnMGDlRy1Np+vvg xVnk34bog6bJEXPpd1W0ZhX/6rrSohpzazwxYlJ0CsIiIqPW+tM023kd9Pj1/tI00TxpVr 7puIg/6gNeTx8rsKTuL0nS4IqNynK+s= From: andrey.konovalov@linux.dev To: Marco Elver Cc: Andrey Konovalov , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm 08/11] kasan: check kasan_vmalloc_enabled in vmalloc tests Date: Thu, 21 Dec 2023 21:04:50 +0100 Message-Id: <954456e50ac98519910c3e24a479a18eae62f8dd.1703188911.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 34AA1160027 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: fa7rft1kgnr5wu64yqyher6wrhqew3g1 X-HE-Tag: 1703189166-949720 X-HE-Meta: U2FsdGVkX1+1LWCgGkm43UmxYOvJQ4NBI1MFtafL1eGY1eLHtgjuxnsog9oUxq/IR/Al/0HLQJ+D1mEZ9qBBK6zppiiPvs717p3oMmxXTYKNVedJaVWevjpAyWiihHBslU70LzE0q5P26+uUBqz0uMfO3lMkcml+9Uf8BOC1W9GroKOlilcerG+Y++jVCfSC4aobXJDML/COOcn4o1sahexKXjPKEGxH0U8tHw0N946xSt6xeMPSks5h6lHoFvNTXUJ7yMcI/HAPotVpBU5Tq6FGeaT7gAcMGK1kryWCiocWklWVfS9/lKL9Uo3n0QfH+RmHB3DjgfbJZgewhRm3A0GZMcAQ+zZRZgLnD0CoUGnpd9buyMeJBJpp2CsK43jN7093oN4Jt20h02g130ze2314W/CKq2Y0MjeJo/XJogHnAEb0AZtUbMQtJdBKx5CVctaZ3DgEz2ITBnukaRgZZIKmwhFfowcfozFwHX6naXN76YxmR8do+i22eNztN2huQM9QZ1aMOAHH+30ptZCf1UD+WH44zsbUaLdnVwu3qqu/ePkly3FEqSJYn3M1MsZukmOUEep6HIDrYT2OQgRvmQzTm2dSccqSFHJyXwnuBN4NQVXyKRCcFjSrovFuBJ1GO/1JCnHii4q3r5X5Qwt/WgRtj5YW7MJEbFdK7Y29GZLM97879d0fVCgh2WMytX6AWYJqJEQFlB4XeqorYk+zCkAjT+RLylUqgMsPbj4zjf8qbSusmgHGSmzGoouJipqnY3+mfIDjFL7PGpgUHJdi2uwWJ54ALmBKO932Z0yWTxeTU2PADS8UDBGrfbIYcfg9XhL8bXE6jUOixvP+N9J7AGjyQMFy1Se+LmCIVCHAga46GHYQICyM1eai90Tq6YegDlRQBj04txg/a+I3VCrH189UK535+qSiN2shwjZcXyAmqIGiqzGEjaxemvI/mi7iHL29yxTClDEMCeYSELK QI1hOrgR C+r3HG6Fapk+HbdWzZCs3fPCCC/L0q0F28HZqIlP0kmPbvmbu5wDMlgNMacd1Ys00uOGK+Hr7XbtUDo31HEwjST984HXlP2MOQAWFuJps73p01IIPLK/Z0YM/bva6MzVraat4oKKSVt4Z6OtAAayhJgOSZ1J/gBw/NPgKwXkRtnI+xCAKdOiP2khpKuEVnvFett3x2CiCDQxFY4rysQsz2CVPbw== 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 Check that vmalloc poisoning is not disabled via command line when running the vmalloc-related KASAN tests. Skip the tests otherwise. Signed-off-by: Andrey Konovalov --- mm/kasan/hw_tags.c | 1 + mm/kasan/kasan.h | 5 +++++ mm/kasan/kasan_test.c | 11 ++++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c index 80f11a3eccd5..2b994092a2d4 100644 --- a/mm/kasan/hw_tags.c +++ b/mm/kasan/hw_tags.c @@ -62,6 +62,7 @@ DEFINE_STATIC_KEY_TRUE(kasan_flag_vmalloc); #else DEFINE_STATIC_KEY_FALSE(kasan_flag_vmalloc); #endif +EXPORT_SYMBOL_GPL(kasan_flag_vmalloc); #define PAGE_ALLOC_SAMPLE_DEFAULT 1 #define PAGE_ALLOC_SAMPLE_ORDER_DEFAULT 3 diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index dee105ba32dd..acc1a9410f0d 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -83,6 +83,11 @@ static inline bool kasan_sample_page_alloc(unsigned int order) #else /* CONFIG_KASAN_HW_TAGS */ +static inline bool kasan_vmalloc_enabled(void) +{ + return IS_ENABLED(CONFIG_KASAN_VMALLOC); +} + static inline bool kasan_async_fault_possible(void) { return false; diff --git a/mm/kasan/kasan_test.c b/mm/kasan/kasan_test.c index 1c77c73ff287..496154e38965 100644 --- a/mm/kasan/kasan_test.c +++ b/mm/kasan/kasan_test.c @@ -1540,6 +1540,9 @@ static void vmalloc_helpers_tags(struct kunit *test) KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_VMALLOC); + if (!kasan_vmalloc_enabled()) + kunit_skip(test, "Test requires kasan.vmalloc=on"); + ptr = vmalloc(PAGE_SIZE); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); @@ -1574,6 +1577,9 @@ static void vmalloc_oob(struct kunit *test) KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_VMALLOC); + if (!kasan_vmalloc_enabled()) + kunit_skip(test, "Test requires kasan.vmalloc=on"); + v_ptr = vmalloc(size); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, v_ptr); @@ -1627,6 +1633,9 @@ static void vmap_tags(struct kunit *test) KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_VMALLOC); + if (!kasan_vmalloc_enabled()) + kunit_skip(test, "Test requires kasan.vmalloc=on"); + p_page = alloc_pages(GFP_KERNEL, 1); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p_page); p_ptr = page_address(p_page); @@ -1745,7 +1754,7 @@ static void match_all_not_assigned(struct kunit *test) free_pages((unsigned long)ptr, order); } - if (!IS_ENABLED(CONFIG_KASAN_VMALLOC)) + if (!kasan_vmalloc_enabled()) return; for (i = 0; i < 256; i++) { From patchwork Thu Dec 21 20:04:51 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: 13502605 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 7C817C46CCD for ; Thu, 21 Dec 2023 20:06:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 29C336B009B; Thu, 21 Dec 2023 15:06:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0E6536B009C; Thu, 21 Dec 2023 15:06:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA0E86B009D; Thu, 21 Dec 2023 15:06:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C40B76B009B for ; Thu, 21 Dec 2023 15:06:09 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 62BF5801FA for ; Thu, 21 Dec 2023 20:06:09 +0000 (UTC) X-FDA: 81591906858.09.E94E723 Received: from out-175.mta0.migadu.com (out-175.mta0.migadu.com [91.218.175.175]) by imf20.hostedemail.com (Postfix) with ESMTP id CAEFE1C002D for ; Thu, 21 Dec 2023 20:06:07 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=eN0oFbJi; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf20.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.175 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=1703189168; 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=a/6/sI3HKZf6Tm/zhA/G4IhIpYOeRmpfsNisTtqnMzE=; b=5GqbMlK7Z71cUnjRZLhzU2ovMHmQrZ/BsgNbiATlbE35fJKXH3Hdl6grEennaRWrmrUhti JVNAZOGvCZQdw/4nmRSmzMU9H0VYcl5+vzFusj5hfzjcRqse+ksdZxEOyjOOvGIo09RqNe eHnTFQF5ZDMyFUd9DBfQ8UBBpFLksts= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=eN0oFbJi; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf20.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.175 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703189168; a=rsa-sha256; cv=none; b=bFU0EOZNEAnepmtmkdsVMmDwFu74+TzDp+WAWwES+RviCpMHwdyggF87q7y6L1BKyXbYgT 0sBbsFsf9xarezGlkQ1W6lBK1jZ6NIr0w747beN0WaUbamcFIJtEeV69AgIWNKfrqgVJSo U5ie8wVSiXdLo+TIaW6dNRuZgohq9oA= 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=1703189166; 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=a/6/sI3HKZf6Tm/zhA/G4IhIpYOeRmpfsNisTtqnMzE=; b=eN0oFbJiwT3zUnq2cxeXoUm44eMoYM8NmUuh4m/ta8P8IRSzUOmK1w4vpgo38zt4d8LCrA exyl7aMfq6fUaijIp7KICaNRhlJzWlDY/wAMTLTJJ2IRzzSfwwE40tPn7y2fMMvcsd7cRE +bxk8A7+0pKfZWEiGw/4jcKK7Qx1fWE= From: andrey.konovalov@linux.dev To: Marco Elver Cc: Andrey Konovalov , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm 09/11] kasan: export kasan_poison as GPL Date: Thu, 21 Dec 2023 21:04:51 +0100 Message-Id: <171d0b8b2e807d04cca74f973830f9b169e06fb8.1703188911.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: CAEFE1C002D X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: dzib8ez84b9ig7adq5wzgsnca6f3x98r X-HE-Tag: 1703189167-14380 X-HE-Meta: U2FsdGVkX18Ap9blhsmcvJ4qJnHjN6yI3ZE8DFCCN3wHcO76bJqcSqkupAql8fQLJ6Ou40cMZunbj6A2WAajFATE4dmBNzrEahLa6Kw4kNiQwWEZq0EFUwn6k6mpqvuxqRTbNdXk7bjugwbBswZloBq20nL/nKuBg25kKMtE5Bc5bMOq0gDMXIJvecTP1Q7vcePQILZW3qKvdAFSPu0d7NNUKa2q7VXi3LeO6mDeE3L+uYnohYJE7fSqyC5xYaVZzKX43+Ysm9eErl8atrmr0bZsXX2+wuM2nvzirGmzcKErUayNtTt419E87h1lIvYs3KpUQsVJzCIKmxG0NWMNLgp2rLXzrfHknfbDiz1jrtMiJ3yFVFUZXxhXHFsSwddlKSgyvt5M6DCSUWMdBhd6UZmQlMvFrAX7RtrzB9YrQ896DgVAb+vanIr598eoQvUiv4wK6VjhMpJvDxWVTjZDnc87FUVTvsZoz2RX0LQ18rKK7OEutFybtvc83aYg92rJFaIHmjsSX9+TgmBSDEmQbMestSjitalgMGZ/LtXhoySCttNZLLKqfReeyiFTZSKNDL3aq63w+mtMXT68Asj7ospYNKhRy7YFQ1fNh6hXj4wZFTWnztW4G/hUWe53rH0cYhdAfsmHDtcvGfOk8w5BtPcEEQw38rlkaQNcMZP7RuyszUrBWisVsMz5GeniXvvOV44cuYAij67vkw0cuy67FF2wW02+bHasSeeVGWLdQT0uQ22kiYjTs1HRgApYVIWv/Y6+0TFihKno3TYlfElblvdMGjfDFij0PO1CgzMtUTw6KW95MThcYOp2WycW1EeWhwqffxASFsSA5IXFeA7JqjllN4F0Sjd219NKXK8TSaQ7s5643kB4wVdNO3nazpHilCo+Ro+abzWSsL+CoMYFaN0SJoIuVz54bxw5+X2QYMgTNlE5TbOdK80gJ3PqDXiBHQxF/VvcoJQ= 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 KASAN uses EXPORT_SYMBOL_GPL for symbols whose exporting is only required for KASAN tests when they are built as a module. kasan_poison is one on those symbols, so export it as GPL. Signed-off-by: Andrey Konovalov --- mm/kasan/shadow.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c index 30625303d01a..9ef84f31833f 100644 --- a/mm/kasan/shadow.c +++ b/mm/kasan/shadow.c @@ -145,7 +145,7 @@ void kasan_poison(const void *addr, size_t size, u8 value, bool init) __memset(shadow_start, value, shadow_end - shadow_start); } -EXPORT_SYMBOL(kasan_poison); +EXPORT_SYMBOL_GPL(kasan_poison); #ifdef CONFIG_KASAN_GENERIC void kasan_poison_last_granule(const void *addr, size_t size) From patchwork Thu Dec 21 20:04:52 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: 13502606 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 7FFA7C35274 for ; Thu, 21 Dec 2023 20:06:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 729CB6B009C; Thu, 21 Dec 2023 15:06:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6B2126B009D; Thu, 21 Dec 2023 15:06:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 495C36B00A0; Thu, 21 Dec 2023 15:06:10 -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 1DE4F6B009D for ; Thu, 21 Dec 2023 15:06:10 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id F2E6940CE3 for ; Thu, 21 Dec 2023 20:06:09 +0000 (UTC) X-FDA: 81591906858.01.F58B94C Received: from out-182.mta0.migadu.com (out-182.mta0.migadu.com [91.218.175.182]) by imf25.hostedemail.com (Postfix) with ESMTP id 546D5A0007 for ; Thu, 21 Dec 2023 20:06:08 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=KmqU694Z; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf25.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.182 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=1703189168; 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=itOhYdVtqZdvAR7o0Q16gEQdZUJ+zDuxto8wg6YMX5U=; b=FGsJ+YsMxarlJcZMPWnzKRlt10sv4+2m+FvmCJAjiFJuSjMKFnKfhwonVgl7m/FR9/aQmz Y5zQRM1YCgY/t8ipjeYEPu7VM3C8xtxxEUgMZHvMIwq4S2s1xfJFrCYbfAsjCEMdNNo5ro BhBtoyAHV2gKlHKOod2Z6VlPQkZaWcc= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=KmqU694Z; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf25.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.182 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703189168; a=rsa-sha256; cv=none; b=nxN+gHdXPPq1jwmjJTgUtyWpSK39jbDg5xdehlXCW2cQ7ZNlDW6D3A5OxY0BAYfNnfQdWn tLce19fr9ULuxAjJJKgyivirLMZv7SWeah/H+UKytUVxGmNzkvubddDZ3OfsVW7G3VyIT8 SJYIMA6VolpGQQm+emN36n2rJaL4bHY= 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=1703189167; 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=itOhYdVtqZdvAR7o0Q16gEQdZUJ+zDuxto8wg6YMX5U=; b=KmqU694Zt6wu9nrYTkctmmkfBJq7NuWGLfuL6LQc4yRHrVvgSk9TrEaIkENsIsxAhzy0iD M5jyxL69O1qWaiZjFMO8J3Kk4OIyyumpmCcqjeJvbednSEB0sn4BUCn5787rVS16/+WTWn vHxsZcIZaRd0Vg3+r7Go8wBuNHm2nL0= From: andrey.konovalov@linux.dev To: Marco Elver Cc: Andrey Konovalov , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm 10/11] kasan: remove SLUB checks for page_alloc fallbacks in tests Date: Thu, 21 Dec 2023 21:04:52 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 546D5A0007 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: hqt5943tuypxgjaoek8si8c5n81n3prs X-HE-Tag: 1703189168-184780 X-HE-Meta: U2FsdGVkX19Ggi/5s6QM9mOO6E/RfCaxNoLlCB2A4aZQAGavUk1lCr5N3Lhm3bO2oJfz6KT68A6+pBt6DupTwcq4uvqiHNbHszNNpw/qUk3D2IPB+BNRykJtI841lRn0QopdQPeduSXIa/JoRQZAhC32dQUkJqcik9OqF67BpCrMVCCZovGQy9HtuwIJyJDG5RO4XXxfkSALU88/5lhRUOGsA5aT0zRA9injvgnKwjJyCW543olNC/nKTkIROIDNDurknuS+eB/nqiTiUmd1CrBp5dn0l+aq+ct+ffEvKWbMnARaZNaqHgPTwhs73noN9kXZKlqy9dtmWEf7SWebVVhZK1rm6YMadTjww+frwpXUV+Xdgwvjbu/E4VlPzm7wT0mlbF/XztZqDyXDsEq7IeR2G4gizNCeXUxF0EjuEvB4g3nmNzE0L/W0RxfqWFIzRdUlxhHY6Ov32Nhw5x+L1hAd/qDjSBTUBGgduRKORyfViCWwpPXmYkFsWwy2SyRow1C5RDtYE08+RcXEPJyd38R5uGow8ubx2tW0lgnCjI8KH7pZT3k6R46eAY2rCjgZux3Ze76cNQzcyao+8Ne7oUx2G7AdLt0ji6TsvfXwgIyr3my+aTY1tlDWif7tSBq8pwoU6aVyxX+AQzigugCCu5Ofoec4PN8mSQ88G1a8ztyr9pAMlcFraoqJ6GTuByKwWoH8J/RroWoHGyrclln3MuY74UcjSWUjgzhY7u/AU/WzmRMGozjG5l7CTkBe9+7rp7nJR9x7oONsRGMFD0FuhcnJ4RGvzmZa7tr3PIwCE2kMQ86oznQ0puMmD/PG3BW4YFMmOs9sYrRlYFWOBCy6kYA6bm/5dX1y9zunRGryjcVCdb+QgCQwvg6foXIz2e/4OA0U3YBFrxc/LNnOkpSza1S2wJGvFYaDl8ojYvgAR1L1jEb2iInlyHLPVRIGmEGnJKGRYfXQ7NQ= 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 A number of KASAN tests rely on the fact that calling kmalloc with a size larger than an order-1 page falls back onto page_alloc. This fallback was originally only implemented for SLUB, but since commit d6a71648dbc0 ("mm/slab: kmalloc: pass requests larger than order-1 page to page allocator"), it is also implemented for SLAB. Thus, drop the SLUB checks from the tests. Signed-off-by: Andrey Konovalov --- mm/kasan/kasan_test.c | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/mm/kasan/kasan_test.c b/mm/kasan/kasan_test.c index 496154e38965..798df4983858 100644 --- a/mm/kasan/kasan_test.c +++ b/mm/kasan/kasan_test.c @@ -215,7 +215,7 @@ static void kmalloc_node_oob_right(struct kunit *test) /* * Check that KASAN detects an out-of-bounds access for a big object allocated - * via kmalloc(). But not as big as to trigger the page_alloc fallback for SLUB. + * via kmalloc(). But not as big as to trigger the page_alloc fallback. */ static void kmalloc_big_oob_right(struct kunit *test) { @@ -233,8 +233,7 @@ static void kmalloc_big_oob_right(struct kunit *test) /* * The kmalloc_large_* tests below use kmalloc() to allocate a memory chunk * that does not fit into the largest slab cache and therefore is allocated via - * the page_alloc fallback for SLUB. SLAB has no such fallback, and thus these - * tests are not supported for it. + * the page_alloc fallback. */ static void kmalloc_large_oob_right(struct kunit *test) @@ -242,8 +241,6 @@ static void kmalloc_large_oob_right(struct kunit *test) char *ptr; size_t size = KMALLOC_MAX_CACHE_SIZE + 10; - KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_SLUB); - ptr = kmalloc(size, GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); @@ -258,8 +255,6 @@ static void kmalloc_large_uaf(struct kunit *test) char *ptr; size_t size = KMALLOC_MAX_CACHE_SIZE + 10; - KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_SLUB); - ptr = kmalloc(size, GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); kfree(ptr); @@ -272,8 +267,6 @@ static void kmalloc_large_invalid_free(struct kunit *test) char *ptr; size_t size = KMALLOC_MAX_CACHE_SIZE + 10; - KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_SLUB); - ptr = kmalloc(size, GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); @@ -407,18 +400,12 @@ static void krealloc_less_oob(struct kunit *test) static void krealloc_large_more_oob(struct kunit *test) { - /* page_alloc fallback is only implemented for SLUB. */ - KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_SLUB); - krealloc_more_oob_helper(test, KMALLOC_MAX_CACHE_SIZE + 201, KMALLOC_MAX_CACHE_SIZE + 235); } static void krealloc_large_less_oob(struct kunit *test) { - /* page_alloc fallback is only implemented for SLUB. */ - KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_SLUB); - krealloc_less_oob_helper(test, KMALLOC_MAX_CACHE_SIZE + 235, KMALLOC_MAX_CACHE_SIZE + 201); } @@ -1144,9 +1131,6 @@ static void mempool_kmalloc_large_uaf(struct kunit *test) size_t size = KMALLOC_MAX_CACHE_SIZE + 1; void *extra_elem; - /* page_alloc fallback is only implemented for SLUB. */ - KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_SLUB); - extra_elem = mempool_prepare_kmalloc(test, &pool, size); mempool_uaf_helper(test, &pool, false); @@ -1215,9 +1199,6 @@ static void mempool_kmalloc_large_double_free(struct kunit *test) size_t size = KMALLOC_MAX_CACHE_SIZE + 1; char *extra_elem; - /* page_alloc fallback is only implemented for SLUB. */ - KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_SLUB); - extra_elem = mempool_prepare_kmalloc(test, &pool, size); mempool_double_free_helper(test, &pool); @@ -1272,9 +1253,6 @@ static void mempool_kmalloc_large_invalid_free(struct kunit *test) size_t size = KMALLOC_MAX_CACHE_SIZE + 1; char *extra_elem; - /* page_alloc fallback is only implemented for SLUB. */ - KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_SLUB); - extra_elem = mempool_prepare_kmalloc(test, &pool, size); mempool_kmalloc_invalid_free_helper(test, &pool); From patchwork Thu Dec 21 20:04:53 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: 13502607 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 C0A31C46CCD for ; Thu, 21 Dec 2023 20:06:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C9FE6B009E; Thu, 21 Dec 2023 15:06:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 74E916B00A0; Thu, 21 Dec 2023 15:06:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 57C206B00A1; Thu, 21 Dec 2023 15:06:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 3D5DC6B009E for ; Thu, 21 Dec 2023 15:06:11 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 179AE1C1620 for ; Thu, 21 Dec 2023 20:06:11 +0000 (UTC) X-FDA: 81591906942.20.9D3485D Received: from out-175.mta0.migadu.com (out-175.mta0.migadu.com [91.218.175.175]) by imf08.hostedemail.com (Postfix) with ESMTP id 51F2B160027 for ; Thu, 21 Dec 2023 20:06:09 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=UstQbyfW; spf=pass (imf08.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.175 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703189169; 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=jLiJLNrkVOviOAnhN8fsOfgjq7KcvOUpOIZZlqspNbg=; b=tD22rVNShXPw6BGNSgajigWxuAz6xJE9yTpfXZPQ6x5Ro/lKj21xf4r04GfLsO+Fbqf+Se Y7e2c28bekCLMqBEXI8q1fTDNZZtc5U/6qJQDeXoXW+x2QfTcLSVHh7CPGWbsmBJmlQf5X foJsOw4Lz3lZfTpccsSzNrUaTb10kWo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703189169; a=rsa-sha256; cv=none; b=Fx1NaCKy++FaWO/NinovK5keiCebfJ/o3g0maEAlNqfnLTg6oSS7Glmjilc9uUQAhNJvxh S62+K35pLLQv2I7CSzT/ihajCaZI3RD+PlPjvReFPiXaSuRht2mRoPIGHVNKvZj02wdTEg prmFymZ6ferrdMa7O6bFTg1uMo1b4fc= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=UstQbyfW; spf=pass (imf08.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.175 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=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=1703189167; 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=jLiJLNrkVOviOAnhN8fsOfgjq7KcvOUpOIZZlqspNbg=; b=UstQbyfWlazleiIZsd06p6GGsiGbF7Mk+SEC7V7KErkAUJltuZuqjmSUhenEEKoFJe2Ldb 4tUiUzH6Uvv0RFu+cj+WbPn+gOqF8clgrSf7LbqyBVZlfKgonrRaUwbKKmHlfEcXGpHP7+ mC3opDKQo6UxTJoeylICS86c/ZXC9RI= From: andrey.konovalov@linux.dev To: Marco Elver Cc: Andrey Konovalov , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm 11/11] kasan: speed up match_all_mem_tag test for SW_TAGS Date: Thu, 21 Dec 2023 21:04:53 +0100 Message-Id: <6fe51262defd80cdc1150c42404977aafd1b6167.1703188911.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 51F2B160027 X-Rspam-User: X-Stat-Signature: nb1tfecqfhq45z1gb35biku8b7tnxr1f X-Rspamd-Server: rspam03 X-HE-Tag: 1703189169-766979 X-HE-Meta: U2FsdGVkX18A4tTHiZQFR462Mvpe30e4Toy+QzYpCb3FiI0+rgl4kJDNhPFn6m9SBgV8rTQgWAs8tDVstks0wCcug8qWg9R21e6gZBXTGtbclXxsFwZXEO7eXPuZ4x9c60EJA4kVazhm7MPXQYcN++Ip3HXAHYCvBP9Zom4ZrM170s3Mcv+ZFQg7YADvtXCftsWP3DAanaZZIt3tEdUhPEXYjIESXyUg9Vt7i8Vs2Mel5eI4SZl+hVOEWTI4iCSlazrg1/PKSigwzSgjwo1+YfHTPWBlTF+AS1NOVa6K4A3lQibL5fT5mFYQehtF5QMvnayVKgkLYhT1SkVMcdjev6JC1vrrplRI89GzRvf91DX2FLnT06YzV/jJjVSlCYmJ43IaPVDlYzfvUXGLmBB5eu09QXbU6o5J1X8UYzVlG/mgX1By7fEHVrPK/t3JrrYiHjgvG3eui0ILEYf28ud1Qspoq9wXR3HU1QJkNX3Z7e6uYHHUpaRj4jCtP8z2/DMfZz+9WX8NTqEGvr9PWPl+nXMrQdPRWzF06SSqzwr7fvCpQWtb+Xmm9LHYaAh4UHHh7dFPhxzhrx2u740n18EgnoakZmMv+uvJ+ACYgscuWxgzL7Sorulk/ZUesiXJyDsX9RPC+Pz6Kcy3igBdf8Q1hV+kK51wBFFejjm9PzqGqrcYgLJDlIzSj0i2vA+V6Oup2pFSur8mAhrf5BwMjsAdKjJLPRqrDe9/4ME08VJlE7fRgvePPH1tQRpEq/jIcFK75iGq7FbIuHNbGYj+vhf3nmPTWHExcBLb5Wuphxi4DXHXVn+mLvvs3pqpJSFujpXO6180rH5ZqI7DAs709UGJBfsmb76/0k4DHb2nlXout4oXUlIE9vWiymN19UIqqoGg9URkDzIr/8SFgzHWwHgC9Epw6nWCZYfL/g67MMVuxc1nlGg6dZW+mpkGZjRLFXZA5cvDDwJ273R3rn46nnl 6qzvGywj SObZ86g3/cHOSXDrbng5aG8FO2hYUWFbfGCsWHtXslYSopjbIooe8lB0Ai85YptZWw/6+2hjiYLCdRaETgkJ/iGVqLxDQZC87tbo9Quk1a093N+aemSWBQYhWDpwlk6714+RRoZSo2M6Fx099867AniDC7qasG/VXstiY1KNeoXoYyPPk0nKNdtS7MAuP+csA6p53SLNpnBRnpr/Yvh+Vaszmpg== 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 Checking all 256 possible tag values in the match_all_mem_tag KASAN test is slow and produces 256 reports. Instead, just check the first 8 and the last 8. Signed-off-by: Andrey Konovalov --- mm/kasan/kasan_test.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mm/kasan/kasan_test.c b/mm/kasan/kasan_test.c index 798df4983858..9c3a1aaab21b 100644 --- a/mm/kasan/kasan_test.c +++ b/mm/kasan/kasan_test.c @@ -1785,6 +1785,14 @@ static void match_all_mem_tag(struct kunit *test) /* For each possible tag value not matching the pointer tag. */ for (tag = KASAN_TAG_MIN; tag <= KASAN_TAG_KERNEL; tag++) { + /* + * For Software Tag-Based KASAN, skip the majority of tag + * values to avoid the test printing too many reports. + */ + if (IS_ENABLED(CONFIG_KASAN_SW_TAGS) && + tag >= KASAN_TAG_MIN + 8 && tag <= KASAN_TAG_KERNEL - 8) + continue; + if (tag == get_tag(ptr)) continue;