From patchwork Fri Jun 20 13:53:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 898763 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EFE9929C355; Fri, 20 Jun 2025 13:53:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750427634; cv=none; b=by43QezNyehFcuWbUW1paQhgzoQJcFT1AXkUS9nY/MofTQlXSGEYWGB47uEaBnUgqRxdLTQLWguk6PbKwX+daQ//ivzSdiYPJ9ahPdfgV35jWz8WBRQn9NDY1LZL+Ns7oDYipJWduADqmpYS/KOZd0vchTnS2dhk/ZrAo3bqRg4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750427634; c=relaxed/simple; bh=I7i22QprD2S6ZvpY/RhEAEk5UwJ5gH0iWa60cJAUZjY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WFgnL9lL22IqBakiorD1JqoqYkQLE1ydt+cCDEHbUZz+kLO2LfFPaZ7cuRle1FcYv+y1qPZWBBFLl3tEcFCU5gGURNVHUZArZ8hEicKcwAjZWGJ6tgwzfmLmEMXIckPO2iq8VOBgpZP+HMXIcXVswvE3evwpi3y6P3J9N/P4i+o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.helo=mgamail.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=OxSYJdL2; arc=none smtp.client-ip=192.198.163.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.helo=mgamail.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="OxSYJdL2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750427633; x=1781963633; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=I7i22QprD2S6ZvpY/RhEAEk5UwJ5gH0iWa60cJAUZjY=; b=OxSYJdL2jQh2+2NIPlris3TcpbzB0u7/UB7CCrsarHJZC2f0Tnek1TgV bXH3fCo55q3/bhAxhOJ5bMW8uFXPqW8H409Ixhc7vnJ5eGor5VhrdcaY5 FW3knX5oL2tCgg4MTfL/TJlUpEGC/AQVLxSW/V79kEJJBn3nR4t4l4O+G mGLwoFQ0jkAeJHltcIbxNnexKHucVKdIaHwl7u9fpOtjaLLS6kA6t8RFu 5KUshTU9b8k0WhwdYOgYw9yWpfIUC20HXuhOvHUBvLskQWnh3KHPOXwIv rZHpJHA+qtoeCA3BLNjrByvx9F1dEDMDwqVISMvnaO156IqwKhCUI+uKC w==; X-CSE-ConnectionGUID: Q/QHHfLzTUqPuSZTJohP8w== X-CSE-MsgGUID: 4xH/UVI8TBS/kLGiowFEgA== X-IronPort-AV: E=McAfee;i="6800,10657,11469"; a="51919407" X-IronPort-AV: E=Sophos;i="6.16,251,1744095600"; d="scan'208";a="51919407" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jun 2025 06:53:52 -0700 X-CSE-ConnectionGUID: IAg8+FfHRNy5reypztF2eg== X-CSE-MsgGUID: zpMboRTARBqsEL98AB0TsQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,251,1744095600"; d="scan'208";a="155292156" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa003.jf.intel.com with ESMTP; 20 Jun 2025 06:53:37 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 09CC974E; Fri, 20 Jun 2025 16:53:29 +0300 (EEST) From: "Kirill A. Shutemov" To: Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Peter Zijlstra , Ard Biesheuvel , "Paul E. McKenney" , Josh Poimboeuf , Xiongwei Song , Xin Li , "Mike Rapoport (IBM)" , Brijesh Singh , Michael Roth , Tony Luck , Alexey Kardashevskiy , Alexander Shishkin Cc: Jonathan Corbet , Sohil Mehta , Ingo Molnar , Pawan Gupta , Daniel Sneddon , Kai Huang , Sandipan Das , Breno Leitao , Rick Edgecombe , Alexei Starovoitov , Hou Tao , Juergen Gross , Vegard Nossum , Kees Cook , Eric Biggers , Jason Gunthorpe , "Masami Hiramatsu (Google)" , Andrew Morton , Luis Chamberlain , Yuntao Wang , Rasmus Villemoes , Christophe Leroy , Tejun Heo , Changbin Du , Huang Shijie , Geert Uytterhoeven , Namhyung Kim , Arnaldo Carvalho de Melo , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, linux-mm@kvack.org, "Kirill A. Shutemov" Subject: [PATCHv6 12/16] x86/traps: Communicate a LASS violation in #GP message Date: Fri, 20 Jun 2025 16:53:20 +0300 Message-ID: <20250620135325.3300848-13-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250620135325.3300848-1-kirill.shutemov@linux.intel.com> References: <20250620135325.3300848-1-kirill.shutemov@linux.intel.com> Precedence: bulk X-Mailing-List: linux-efi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Alexander Shishkin Provide a more helpful message on #GP when a kernel side LASS violation is detected. A NULL pointer dereference is reported if a LASS violation occurs due to accessing the first page frame. Signed-off-by: Alexander Shishkin Signed-off-by: Kirill A. Shutemov --- arch/x86/kernel/traps.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index 333c45df80fc..0f558d3369a3 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -636,7 +636,16 @@ DEFINE_IDTENTRY(exc_bounds) enum kernel_gp_hint { GP_NO_HINT, GP_NON_CANONICAL, - GP_CANONICAL + GP_CANONICAL, + GP_LASS_VIOLATION, + GP_NULL_POINTER, +}; + +static const char *kernel_gp_hint_help[] = { + [GP_NON_CANONICAL] = "probably for non-canonical address", + [GP_CANONICAL] = "maybe for address", + [GP_LASS_VIOLATION] = "LASS prevented access to address", + [GP_NULL_POINTER] = "kernel NULL pointer dereference", }; /* @@ -672,6 +681,12 @@ static enum kernel_gp_hint get_kernel_gp_address(struct pt_regs *regs, if (*addr < ~__VIRTUAL_MASK && *addr + insn.opnd_bytes - 1 > __VIRTUAL_MASK) return GP_NON_CANONICAL; + else if (*addr < ~__VIRTUAL_MASK && + cpu_feature_enabled(X86_FEATURE_LASS)) { + if (*addr < PAGE_SIZE) + return GP_NULL_POINTER; + return GP_LASS_VIOLATION; + } #endif return GP_CANONICAL; @@ -833,11 +848,10 @@ DEFINE_IDTENTRY_ERRORCODE(exc_general_protection) else hint = get_kernel_gp_address(regs, &gp_addr); - if (hint != GP_NO_HINT) + if (hint != GP_NO_HINT) { snprintf(desc, sizeof(desc), GPFSTR ", %s 0x%lx", - (hint == GP_NON_CANONICAL) ? "probably for non-canonical address" - : "maybe for address", - gp_addr); + kernel_gp_hint_help[hint], gp_addr); + } /* * KASAN is interested only in the non-canonical case, clear it