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: 13845041 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A1A0DD1715D for ; Tue, 22 Oct 2024 03:15:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=FpfVj+cCklKKT0meu9E3X+82meKkLqCR+uZsOKWdYis=; b=TioWmHQZwxjpnehVYc1a8imGRk aXyddsFjuFWGXDC/QFxRHfDj7v5/vfkAu4xOgv+zX0Qs962/W9YVMdOD2zZwbWTdSMeEDPm8ds0tt zoxER9C/OWsOWY/E8nJHjftqNKHu4kXubONCJdfD/AtPYibI7nra09bJPpSpBDcsCQOjkjVF2+o+U 5zlejs7Vv8nb8QwyWWmhHpd+9CnD3ohMU1JnKih21J5KU6x+wt+dmgDg35cCTjH6Q/01+iuIy7Amk Pq5ua2w1CyXhiXJhO84H8t6UJ2jnaZI7ejlDPVNQMPy8Gy6ziXfG2X/hkch25PL2RIZFCm38A5aqo sgviPMmQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t35Mt-00000009Oyn-1txn; Tue, 22 Oct 2024 03:15:35 +0000 Received: from mail-ot1-x334.google.com ([2607:f8b0:4864:20::334]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t34BC-00000009Fpk-2115 for linux-arm-kernel@lists.infradead.org; Tue, 22 Oct 2024 01:59:30 +0000 Received: by mail-ot1-x334.google.com with SMTP id 46e09a7af769-7180f2f5fb0so2532618a34.1 for ; Mon, 21 Oct 2024 18:59:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1729562365; x=1730167165; darn=lists.infradead.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=jCEEWbD+pBmj/uOGMfuv0a8K+j5ICzpIS/uqQ4INYdwT0THATDzH7LS5pxNOjUQ56N IQ6T5Bt+YHECRommxvBNb4LDuG0/MZf41725nhVzjLYYUQkTO/StNcRGeo7NkVhJpa0+ O7KWdhWuF6C+Ny9apF3XliwXeqgyE/alSPu/kAYPbv2B1YrJV+GOt26a/NLVy/xT9R1v 4DiylQKiKV7dR+HqwPfbfc74RvkztHQAXm6Cnfptmv10ywShAqtzxWAFcv6JypRuM3VK 4jaAw95CvOAMAHka9KqevNcu9mIpFIUHY+fEU0+Jk8jw4rUxLFIEXrkhsPD7mAQvK6xu LP6A== 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=b/DNCbuwt0MHeIWl+MRUB+lWkJOW0CPa4ffusOrHxe4AXGo9ydngGU6BJs1A3wl5rU ULg+jv/yZG2b3itoA+9qpdf+k794aYyVfjY2BCzIVu/AdaPsOZaWJNP5hhzcCRiTqXTR 63G3MVcy+NEe/b3Wwgk5icQIJVUpBHvDnKlnsa9Rxi68lAipQgCL7RUG7KjYnmNLBrNf Qt25u9ck04Udu3LGoN7hKC0+56+ozptehhMdfDO/ScL4FEevWPjvtzIcr8//QXuHZvUT iY5AVtwggeYbCu5l4kfz4sLgY2z/o9ZW12AAyTdpQ6WvAHEr4i/hORKCQVt1haUWciS9 s88Q== X-Forwarded-Encrypted: i=1; AJvYcCUuE6oM2niODd0Q0SpVmzj5Kaw5/uFtva0JfeUmE9NqTBvuGXdWQUzQZYKLn9p5THTx8KtIjOc527Kf5f695Rh5@lists.infradead.org X-Gm-Message-State: AOJu0YxG6RVMltxDTtl8BQsT+iVRk5f4Df/mLkqhK9qjCy52G/jz/r+x PZxW9cAgN2mMyXI9gjOzwTrkChH7W869LSs6ZWHF9sd19rNPzXqk9UN1A6vsABw= 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241021_185926_696561_7361D192 X-CRM114-Status: GOOD ( 13.36 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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);