From patchwork Tue Oct 22 01:57:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13844967 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 6160ED17157 for ; Tue, 22 Oct 2024 01:59:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7CA726B009F; Mon, 21 Oct 2024 21:59:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 752396B00A0; Mon, 21 Oct 2024 21:59:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 57D346B00A1; Mon, 21 Oct 2024 21:59:28 -0400 (EDT) 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 356C76B009F for ; Mon, 21 Oct 2024 21:59:28 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 97381121BA6 for ; Tue, 22 Oct 2024 01:59:13 +0000 (UTC) X-FDA: 82699580460.03.0BC2349 Received: from mail-oa1-f41.google.com (mail-oa1-f41.google.com [209.85.160.41]) by imf13.hostedemail.com (Postfix) with ESMTP id 3AB2320008 for ; Tue, 22 Oct 2024 01:59:10 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=S1vnYrfA; spf=pass (imf13.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.160.41 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=1729562290; 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=FpfVj+cCklKKT0meu9E3X+82meKkLqCR+uZsOKWdYis=; b=P9InAUmR1iLEvhObcoPcRirnKAyHoy02U06EW8nl1P3mEoyRZwbtgPC3xqcbAYyPoko25V sJ1mNkSPfGDWeuHhg8xnkO5zyNwRXT5/VRY9BRhbHLw2pm4xeLwa9+IfUPf7yIeTUQUb7m gENjb2F0vQmoEBg/6rdCBUDJCIiSPnU= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=S1vnYrfA; spf=pass (imf13.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.160.41 as permitted sender) smtp.mailfrom=samuel.holland@sifive.com; dmarc=pass (policy=reject) header.from=sifive.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729562290; a=rsa-sha256; cv=none; b=bwYI43IEKWR+SdqMSN9eeLb92QfQidT0SdIWtkTLHOGqj4HxvZBV+szF87H6tU52wDqeaR 4dlnNuPPBI9taKzGcmYw6SjzZf9tHkeLQk17S8wRALsaP1Bpc90seVcETDXlBAKotyD+pS 5R1eD6NDakjbUsWmU9aSujW/oyKPX8c= Received: by mail-oa1-f41.google.com with SMTP id 586e51a60fabf-288916b7fceso2547311fac.3 for ; Mon, 21 Oct 2024 18:59:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1729562365; x=1730167165; 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=FpfVj+cCklKKT0meu9E3X+82meKkLqCR+uZsOKWdYis=; b=S1vnYrfARDeNYFf/9CRpB4yJYBsfY7ciKMR0v6LlMxNxHTep+4UrLFWM74cSPj4JEc hKgY4a+mNrV1gsMCggxyVMFOKVYidx18mj55ITaI1sMYZk8Y/Y51sPysX5x4ToP3xQ0k 86jjPvGWd+bUQ2JZr/o1PrRQpV1qMfuDZIMCJRS1N9kifWtKh10r9CZ9j/nvd8/4JICD 4rPobfrwX2gkPln+mJhrQcSjKJc2B3qVWTNAu/TgPv4fr1+JU48yjC7V1NKKVmco01Em DOPJ6PubmjWKgtmXVHHksZUSMh5thT/3BpFjmFlEwkCyD6ycwuAU90KQ8DzQ42cRdsjY vcXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729562365; x=1730167165; 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=FpfVj+cCklKKT0meu9E3X+82meKkLqCR+uZsOKWdYis=; b=lifWsz9gkQ1GYmkcBw7zJ2osXDP73EhrhlLOhOrn+I55V4ScAurDNk70MgajugyVhg huGMWhZUyPa94bxVrvmp9dyNN9042frtXlEcCCh8r2s1vR/iZEjT6vAzcsUx73IMMw6w IRRPAM234NnB68PPSCAVsKpa6Y3005pbWdxPVpC44fYQECEzo7O2b/gdR3e95aCJirQn KfT90oUCPutiL+p46I8FATc1gREZ14GR3xpceMZUvKp0fQjAHZJHmv2cNnjSMlx78wnD h3jaqu/40Ksc5JBUZXGnLgkpx2xD1tDA6dBc5lsbAwuHUpzOuaVZnvqjwUfQwSCyzOvT yTIA== X-Forwarded-Encrypted: i=1; AJvYcCXIeeWF9WGufATA3Z1EJNPafyBb8KjHuTgsPBshqqoxbVLS6RHwHpO20zlQOHwd4/Ax5x5f7o5taA==@kvack.org X-Gm-Message-State: AOJu0YxTaiIwdb595vFo/EDF8jqkx7YclFS2LzAzOT9trfPKHD0OBTS3 weV9eBbSgqtRm4ciN1RaOVG8bg4GO6Z5rFXBY1iqjyWI4a4bAJ2XB5bFTmCk1v4= X-Google-Smtp-Source: AGHT+IF8mODh9IAJs797PRe4iXy3b/dNIvInfpWpmRrPkiuy4gHecBRUAsqzv6T0/gnC7v7yNiNl4Q== X-Received: by 2002:a05:6870:148f:b0:27b:61df:2160 with SMTP id 586e51a60fabf-28cb010575fmr1017968fac.31.1729562365145; Mon, 21 Oct 2024 18:59:25 -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.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 18:59:24 -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 5/9] riscv: mm: Log potential KASAN shadow alias Date: Mon, 21 Oct 2024 18:57:13 -0700 Message-ID: <20241022015913.3524425-6-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-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 3AB2320008 X-Stat-Signature: tw8hcnmofckjg5jq9p3x6rrzon69tyju X-HE-Tag: 1729562350-832841 X-HE-Meta: U2FsdGVkX19+PS4OlFderCQ4DVhamHg/t9CM20JjIhzTLeZy24VQ/e/OXHWbASOQTGRAKpnlwuPKEwshOHynHfCSFsDvPzWDGL9145hHrdUuwKv+ztjKsenRJNPylPy1VLvTpiiXfm0u73+GXcqDyPiSfaoo/lMnUh6HgmAm69VInlvFoMRiRlrc1zrIWj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EAJyuNNJ3QaIy9iYMzwtqNUFZ5CWKSQYWFvTOfemZDuZqkzxiF/V6aFz1tV5mjiMd9e50vzBKDe85fAQ/U5A1/Uo5f8eDI+0N6OmdIGVsDpnmRtjx6ItJMTSO6hYolRmLqNokIX1sKdhoIr56eOicrqXjV+ig+ScPDgURAw== 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: When KASAN is enabled, shadow memory is allocated and mapped for all legitimate kernel addresses, but not for the entire address space. As a result, the kernel can fault when accessing a shadow address computed from a bogus pointer. This can be confusing, because the shadow address computed for (e.g.) NULL looks nothing like a NULL pointer. To assist debugging, if the faulting address might be the result of a KASAN shadow memory address computation, report the range of original memory addresses that would map to the faulting address. Signed-off-by: Samuel Holland Reviewed-by: Alexandre Ghiti --- Changes in v2: - New patch for v2 arch/riscv/mm/fault.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/riscv/mm/fault.c b/arch/riscv/mm/fault.c index a9f2b4af8f3f..dae1131221b7 100644 --- a/arch/riscv/mm/fault.c +++ b/arch/riscv/mm/fault.c @@ -8,6 +8,7 @@ #include +#include #include #include #include @@ -30,6 +31,8 @@ static void die_kernel_fault(const char *msg, unsigned long addr, pr_alert("Unable to handle kernel %s at virtual address " REG_FMT "\n", msg, addr); + kasan_non_canonical_hook(addr); + bust_spinlocks(0); die(regs, "Oops"); make_task_dead(SIGKILL);