From patchwork Tue Oct 22 01:57:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13844963 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 B6691D17158 for ; Tue, 22 Oct 2024 01:59:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 383BD6B0093; Mon, 21 Oct 2024 21:59:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 334886B0096; Mon, 21 Oct 2024 21:59:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 138D16B009A; Mon, 21 Oct 2024 21:59:22 -0400 (EDT) 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 E749E6B0093 for ; Mon, 21 Oct 2024 21:59:21 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8DA92C1C65 for ; Tue, 22 Oct 2024 01:59:04 +0000 (UTC) X-FDA: 82699580754.28.5884D22 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by imf20.hostedemail.com (Postfix) with ESMTP id B6C871C0020 for ; Tue, 22 Oct 2024 01:59:00 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=KjDKq7ej; spf=pass (imf20.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=samuel.holland@sifive.com; dmarc=pass (policy=reject) header.from=sifive.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729562209; 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=zwUiyMUd8hSbAOwVDn06T0GWpMaINHNufJwGBjiF7oM=; b=N8iwOA6LlK+WYRSJ7t+2rjKLO/a8BqoaxQjF4v59I3YyYtQYJFtmNoXfOwpvB0psmzyx/A uu2XGgfM2w7Gm7Ibc3LcvF2Z5QXfvSuWN8KfWICkOrJEUMaIIv3D7mnVNQzq7HLFQ6C+5H 0cypwaxlCGNdm9AstGvVuz/MNvqlFkk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729562209; a=rsa-sha256; cv=none; b=jZ+BEX48pwKGiL61vfaFHYcLkx58P6usE2M41e3jpHX5F/uVbzMgC5YuWKLmWNhnIggvPo RTW8Tf+KhF3efds+WFZE2vPhSFkBiIXWPEHBN7Bwzrdqh1BVCcadoZMUou2seK+4W5Gm0r yicxlrrNfaDhYZkSH1TJEN6uPB8uSPI= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=KjDKq7ej; spf=pass (imf20.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=samuel.holland@sifive.com; dmarc=pass (policy=reject) header.from=sifive.com Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-71e5130832aso3535980b3a.0 for ; Mon, 21 Oct 2024 18:59:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1729562358; x=1730167158; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zwUiyMUd8hSbAOwVDn06T0GWpMaINHNufJwGBjiF7oM=; b=KjDKq7ejX6Owoq+i5B1bfMVKrlT+1gH3w2fe7Dp/KQqhr89HRx3oe8++ORlW3Ubdnp soGJoMjsa6qgyKcxlXdU8pjvupGKZOfGMt03dI0EAgRwQOxYFBljRb9xEurg7Y/k4W5i RM2J2+e3q+CvNtP6f9OsYGKPfAawivnaHE48xqDCdM8HnkXP99VVjWvxAv9a/fRlguqq Ih6pMEVh42maOMFlxIvPim7KqUKOY3h32I2LNq4S1TbJimLV7FM89S+i8XAm57d8w72l 3+mxHWAaZoHnHcEPAsbqrzG24LQCRiBb38UQJxxUcASNQdfFSVLytIWA1UW2Jmzfj9T3 r+6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729562358; x=1730167158; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zwUiyMUd8hSbAOwVDn06T0GWpMaINHNufJwGBjiF7oM=; b=Nq5wU3uzU260/rv+hHy7m4VbTYaFZBm6UEjqTRDCe+tnxjTzKlOLAjV53asx4IUwHb wJXX0ML4kAg1rldD6sW1viOnO4Q32DC+3W3Vo7QwIFirBl3+kHDvzamLm7DW9QtomicD nj22F8gDq10UJ9iB3qaWmQS9lqtr5BOuDfa1Lroqz2fxURz0GnQj6VVwaIPT6Ci+x4Wz JvCinRuVBC6gp0MAuJlC48jv72vI0f4AHpgdnXqczkCBovhAifbPFcMR+eMBMLdiAous XUan7V/0QEskLMgAgAOA3UzhjTlmdC7uo8YVdHDYf/PQdx8VOxC09IG+pN+JuN9AOnjH /XOg== X-Forwarded-Encrypted: i=1; AJvYcCVCmlG6nLMHd1wr8zZIUqmPY/kUX2iTb95itHlpNtjzn3yKzQW3mBXCgnB36iDncq8FnNYi0sVMRA==@kvack.org X-Gm-Message-State: AOJu0YxxGIl6fqaj4HGa7h5YlGq23QPBIlJ7ch4mG6/hmXy+AmUtfLjb pzIdjalQSHCfzNIV+BEXV66AH5RXp4BFceKnNuD7eur5kYob2W9IAq64KWzaKVE= X-Google-Smtp-Source: AGHT+IF/kNxKO+HoCV5OxccF94G79KMrSvpY4AWhKUS70q2xmcQQgKjPTjZVS3p5yxthRrvUotX1BA== X-Received: by 2002:a05:6a00:3d08:b0:71e:1314:899a with SMTP id d2e1a72fcca58-71ea31e4c76mr18906065b3a.20.1729562358073; Mon, 21 Oct 2024 18:59:18 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71ec132ffdcsm3600710b3a.46.2024.10.21.18.59.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 18:59:17 -0700 (PDT) From: Samuel Holland To: Palmer Dabbelt , linux-riscv@lists.infradead.org, Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , kasan-dev@googlegroups.com Cc: llvm@lists.linux.dev, Catalin Marinas , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexandre Ghiti , Will Deacon , Evgenii Stepanov , Andrew Morton , linux-arm-kernel@lists.infradead.org, Samuel Holland Subject: [PATCH v2 1/9] kasan: sw_tags: Use arithmetic shift for shadow computation Date: Mon, 21 Oct 2024 18:57:09 -0700 Message-ID: <20241022015913.3524425-2-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241022015913.3524425-1-samuel.holland@sifive.com> References: <20241022015913.3524425-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: B6C871C0020 X-Stat-Signature: kru8w35tntkrstwmnn3fzi6ctsmmfa9n X-HE-Tag: 1729562340-471372 X-HE-Meta: U2FsdGVkX1/FoqWsJfn0A8V7R4WWJP2fhUmCWZAFl1igfg0gL+TKPOrCz09WAyAsg2Oy3R5r5raKgFAKBlldwBZ3TtkzW+sQB03I/Q1vqffQLMThnNYCocISt8sUavd9+n7Cu82xQ7ghmbjYmufKkaz9Q1c/eKJIIULP9hz6fKoHS209h0RNw+0p6BBJ9d0dtkqvzUBWuQ5Jxq3JGKf0QyQYoJyvCQoakKd7kCWdX45cDXvK22OFjQtpzNgF3yQo4PGP0kBx1Djwiyg/jhMAbDCi33H/STHDpQ+xMWZifL9cd7ZVBhb+r8XfreS+ckctQShwPys5fBytF94mL8xKGfrm9Zcy6cgqmjn2tZmXnXqIdxW3Brhw4kH2WSkX8vZ1AOtJqQ48xbgJuCNFzvlT6SvvtMVDT8eiCLt8mKVe3xiBqrWyJgPGjjnjRLYMmOjnoUcVzm+azY5qb64kOjBUJ7VzPLasdfbKrN34sni3M/rClqA1Cs0gaspm/SI3lLjVFo9kRLq+gCxHNPjecPsKLEhKFQN4wweoxC7QwSct7VQpLSGffO33otrXvtC1AwArD+PLP+xvSMYleTXQ905xzFHoWjLLLrcLCG3+HsAGDZ2nWX+WsovG/1BQT9HpuRGYfGUQmfEPRCyAIRY94In/OTrmPIZIWcWCKLFYgPXHnlA0wsLUtO5PaGR1kQrmEqaUvJ87Oq0tm3+w0Pr0h26DdM6N7D/sRBDxOkBfpjfWjb+X47ZiJwG7u80g33ZPNxp5/7a9Iqyb2eTPgcAK6gW6DB57vwwR5somkGpPIH/IxSVn0JYHe4ZZVFx8ZhLYM64EPmnhi4cqTbck5W3WPGgbg71nabV2ozhWiScK5m91cWLQvFS9Ne66MebXzqQUMLfRQ4Zc0DDn5wDvfytZ4OUgJ7ZMi266317C2tACYi3HjX9cBZRyLYh3BtpnnWSSLYH+g+cddwQivMt55mSncjQ dUAZnV2H p+G3KKMrClcD36NEM/8ApjGuy/FhuRhXv0SQ4ZE80TwZU3VQF4zKllWUquzhJlyIs6DRqYpdvgiypl+okiP4MCmnQ8TwS3j843YhuWg1eagJR3dQvny0KgplhjWm5S1jvMOtMrk5TJ+G40QOzoBbNIP7A60kjRMnghEMOJFWJLm8ZYcurrNHkWLiRisRD+wiQpJseSMWxJf15zyGRhxAGDaNSaGmUy59328FG3TrPtCRIgrPGTHnHswhP5vG7ELqP3Jpf0rRZHBx3gJ8gVuF6jBJKpiMJJRlZtHhP1Tbgyl/QYnHNvymmRlB5ghrfrsTwVgpib6Jbu2M35HTI8Q6fedFGo76187wJgXwc/EklKXNxihNDBupGmq01jwAh08LcfkVvgtmkCjB7vTCVQrTXli+JfMvxkNXHzr/eXVEiN3ftL7nmBpN1ali+njlbYR0hifI4FKdBeSUXfALFecA8XwdTKA== 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: Currently, kasan_mem_to_shadow() uses a logical right shift, which turns canonical kernel addresses into non-canonical addresses by clearing the high KASAN_SHADOW_SCALE_SHIFT bits. The value of KASAN_SHADOW_OFFSET is then chosen so that the addition results in a canonical address for the shadow memory. For KASAN_GENERIC, this shift/add combination is ABI with the compiler, because KASAN_SHADOW_OFFSET is used in compiler-generated inline tag checks[1], which must only attempt to dereference canonical addresses. However, for KASAN_SW_TAGS we have some freedom to change the algorithm without breaking the ABI. Because TBI is enabled for kernel addresses, the top bits of shadow memory addresses computed during tag checks are irrelevant, and so likewise are the top bits of KASAN_SHADOW_OFFSET. This is demonstrated by the fact that LLVM uses a logical right shift in the tag check fast path[2] but a sbfx (signed bitfield extract) instruction in the slow path[3] without causing any issues. Using an arithmetic shift in kasan_mem_to_shadow() provides a number of benefits: 1) The memory layout is easier to understand. KASAN_SHADOW_OFFSET becomes a canonical memory address, and the shifted pointer becomes a negative offset, so KASAN_SHADOW_OFFSET == KASAN_SHADOW_END regardless of the shift amount or the size of the virtual address space. 2) KASAN_SHADOW_OFFSET becomes a simpler constant, requiring only one instruction to load instead of two. Since it must be loaded in each function with a tag check, this decreases kernel text size by 0.5%. 3) This shift and the sign extension from kasan_reset_tag() can be combined into a single sbfx instruction. When this same algorithm change is applied to the compiler, it removes an instruction from each inline tag check, further reducing kernel text size by an additional 4.6%. These benefits extend to other architectures as well. On RISC-V, where the baseline ISA does not shifted addition or have an equivalent to the sbfx instruction, loading KASAN_SHADOW_OFFSET is reduced from 3 to 2 instructions, and kasan_mem_to_shadow(kasan_reset_tag(addr)) similarly combines two consecutive right shifts. Link: https://github.com/llvm/llvm-project/blob/llvmorg-20-init/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp#L1316 [1] Link: https://github.com/llvm/llvm-project/blob/llvmorg-20-init/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp#L895 [2] Link: https://github.com/llvm/llvm-project/blob/llvmorg-20-init/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp#L669 [3] Signed-off-by: Samuel Holland --- Changes in v2: - Improve the explanation for how KASAN_SHADOW_END is derived - Update the range check in kasan_non_canonical_hook() arch/arm64/Kconfig | 10 +++++----- arch/arm64/include/asm/memory.h | 17 +++++++++++++++-- arch/arm64/mm/kasan_init.c | 7 +++++-- include/linux/kasan.h | 10 ++++++++-- mm/kasan/report.c | 22 ++++++++++++++++++---- scripts/gdb/linux/mm.py | 5 +++-- 6 files changed, 54 insertions(+), 17 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index fd9df6dcc593..6a326908c941 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -418,11 +418,11 @@ config KASAN_SHADOW_OFFSET default 0xdffffe0000000000 if ARM64_VA_BITS_42 && !KASAN_SW_TAGS default 0xdfffffc000000000 if ARM64_VA_BITS_39 && !KASAN_SW_TAGS default 0xdffffff800000000 if ARM64_VA_BITS_36 && !KASAN_SW_TAGS - default 0xefff800000000000 if (ARM64_VA_BITS_48 || (ARM64_VA_BITS_52 && !ARM64_16K_PAGES)) && KASAN_SW_TAGS - default 0xefffc00000000000 if (ARM64_VA_BITS_47 || ARM64_VA_BITS_52) && ARM64_16K_PAGES && KASAN_SW_TAGS - default 0xeffffe0000000000 if ARM64_VA_BITS_42 && KASAN_SW_TAGS - default 0xefffffc000000000 if ARM64_VA_BITS_39 && KASAN_SW_TAGS - default 0xeffffff800000000 if ARM64_VA_BITS_36 && KASAN_SW_TAGS + default 0xffff800000000000 if (ARM64_VA_BITS_48 || (ARM64_VA_BITS_52 && !ARM64_16K_PAGES)) && KASAN_SW_TAGS + default 0xffffc00000000000 if (ARM64_VA_BITS_47 || ARM64_VA_BITS_52) && ARM64_16K_PAGES && KASAN_SW_TAGS + default 0xfffffe0000000000 if ARM64_VA_BITS_42 && KASAN_SW_TAGS + default 0xffffffc000000000 if ARM64_VA_BITS_39 && KASAN_SW_TAGS + default 0xfffffff800000000 if ARM64_VA_BITS_36 && KASAN_SW_TAGS default 0xffffffffffffffff config UNWIND_TABLES diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index 0480c61dbb4f..a93fc9dc16f3 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -80,7 +80,8 @@ * 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. + * the shadow memory region, since not all possible addresses have shadow + * memory allocated for them. * * Based on this mapping, we define two constants: * @@ -89,7 +90,15 @@ * * 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. + * according to the mapping formula. For Generic KASAN, the address in the + * mapping formula is treated as unsigned (part of the compiler's ABI), so the + * end of the shadow memory region is at a large positive offset from + * KASAN_SHADOW_OFFSET. For Software Tag-Based KASAN, the address in the + * formula is treated as signed. Since all kernel addresses are negative, they + * map to shadow memory below KASAN_SHADOW_OFFSET, making KASAN_SHADOW_OFFSET + * itself the end of the shadow memory region. (User pointers are positive and + * would map to shadow memory above KASAN_SHADOW_OFFSET, but shadow memory is + * not allocated for them.) * * 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 @@ -100,7 +109,11 @@ */ #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) #define KASAN_SHADOW_OFFSET _AC(CONFIG_KASAN_SHADOW_OFFSET, UL) +#ifdef CONFIG_KASAN_GENERIC #define KASAN_SHADOW_END ((UL(1) << (64 - KASAN_SHADOW_SCALE_SHIFT)) + KASAN_SHADOW_OFFSET) +#else +#define KASAN_SHADOW_END KASAN_SHADOW_OFFSET +#endif #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 diff --git a/arch/arm64/mm/kasan_init.c b/arch/arm64/mm/kasan_init.c index b65a29440a0c..6836e571555c 100644 --- a/arch/arm64/mm/kasan_init.c +++ b/arch/arm64/mm/kasan_init.c @@ -198,8 +198,11 @@ static bool __init root_level_aligned(u64 addr) /* The early shadow maps everything to a single page of zeroes */ asmlinkage void __init kasan_early_init(void) { - BUILD_BUG_ON(KASAN_SHADOW_OFFSET != - KASAN_SHADOW_END - (1UL << (64 - KASAN_SHADOW_SCALE_SHIFT))); + if (IS_ENABLED(CONFIG_KASAN_GENERIC)) + BUILD_BUG_ON(KASAN_SHADOW_OFFSET != + KASAN_SHADOW_END - (1UL << (64 - KASAN_SHADOW_SCALE_SHIFT))); + else + BUILD_BUG_ON(KASAN_SHADOW_OFFSET != KASAN_SHADOW_END); BUILD_BUG_ON(!IS_ALIGNED(_KASAN_SHADOW_START(VA_BITS), SHADOW_ALIGN)); BUILD_BUG_ON(!IS_ALIGNED(_KASAN_SHADOW_START(VA_BITS_MIN), SHADOW_ALIGN)); BUILD_BUG_ON(!IS_ALIGNED(KASAN_SHADOW_END, SHADOW_ALIGN)); diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 00a3bf7c0d8f..03b440658817 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -58,8 +58,14 @@ int kasan_populate_early_shadow(const void *shadow_start, #ifndef kasan_mem_to_shadow static inline void *kasan_mem_to_shadow(const void *addr) { - return (void *)((unsigned long)addr >> KASAN_SHADOW_SCALE_SHIFT) - + KASAN_SHADOW_OFFSET; + void *scaled; + + if (IS_ENABLED(CONFIG_KASAN_GENERIC)) + scaled = (void *)((unsigned long)addr >> KASAN_SHADOW_SCALE_SHIFT); + else + scaled = (void *)((long)addr >> KASAN_SHADOW_SCALE_SHIFT); + + return KASAN_SHADOW_OFFSET + scaled; } #endif diff --git a/mm/kasan/report.c b/mm/kasan/report.c index b48c768acc84..c08097715686 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -644,15 +644,29 @@ void kasan_report_async(void) */ void kasan_non_canonical_hook(unsigned long addr) { + unsigned long max_shadow_size = BIT(BITS_PER_LONG - KASAN_SHADOW_SCALE_SHIFT); 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. + * With the default kasan_mem_to_shadow() algorithm, all addresses + * returned by the memory-to-shadow mapping (even for bogus pointers) + * must be within a certain displacement from KASAN_SHADOW_OFFSET. + * + * For Generic KASAN, the displacement is unsigned, so + * KASAN_SHADOW_OFFSET is the smallest possible shadow address. For + * Software Tag-Based KASAN, the displacement is signed, so + * KASAN_SHADOW_OFFSET is the center of the range. */ - if (addr < KASAN_SHADOW_OFFSET) - return; + if (IS_ENABLED(CONFIG_KASAN_GENERIC)) { + if (addr < KASAN_SHADOW_OFFSET || + addr >= KASAN_SHADOW_OFFSET + max_shadow_size) + return; + } else { + if (addr < KASAN_SHADOW_OFFSET - max_shadow_size / 2 || + addr >= KASAN_SHADOW_OFFSET + max_shadow_size / 2) + return; + } orig_addr = (unsigned long)kasan_shadow_to_mem((void *)addr); diff --git a/scripts/gdb/linux/mm.py b/scripts/gdb/linux/mm.py index 7571aebbe650..2e63f3dedd53 100644 --- a/scripts/gdb/linux/mm.py +++ b/scripts/gdb/linux/mm.py @@ -110,12 +110,13 @@ class aarch64_page_ops(): self.KERNEL_END = gdb.parse_and_eval("_end") if constants.LX_CONFIG_KASAN_GENERIC or constants.LX_CONFIG_KASAN_SW_TAGS: + self.KASAN_SHADOW_OFFSET = constants.LX_CONFIG_KASAN_SHADOW_OFFSET if constants.LX_CONFIG_KASAN_GENERIC: self.KASAN_SHADOW_SCALE_SHIFT = 3 + self.KASAN_SHADOW_END = (1 << (64 - self.KASAN_SHADOW_SCALE_SHIFT)) + self.KASAN_SHADOW_OFFSET else: self.KASAN_SHADOW_SCALE_SHIFT = 4 - self.KASAN_SHADOW_OFFSET = constants.LX_CONFIG_KASAN_SHADOW_OFFSET - self.KASAN_SHADOW_END = (1 << (64 - self.KASAN_SHADOW_SCALE_SHIFT)) + self.KASAN_SHADOW_OFFSET + self.KASAN_SHADOW_END = self.KASAN_SHADOW_OFFSET self.PAGE_END = self.KASAN_SHADOW_END - (1 << (self.vabits_actual - self.KASAN_SHADOW_SCALE_SHIFT)) else: self.PAGE_END = self._PAGE_END(self.VA_BITS_MIN)