From nobody Wed Oct 8 18:16:58 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 13D6E2609E4; Wed, 25 Jun 2025 12:51:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750855887; cv=none; b=AkXhxPC1dTqfBS/T6FO4rkpmcAj29YDr8ac0jrACSPzSntP7GliQ75O2MtWHjxHg3HXIfEoANp5av7li8vkmzUb3FfP6B0AD4/wBpQu8Ugt/pX9ES1LelVdFRezkzkc4UiSZ0S5OgGpM25D15/4CyWDM4NYBQNLSDJqBs75W7zc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750855887; c=relaxed/simple; bh=gSrgyF7nkaMy9jgn9VB3Vel47cqINKRy4i1jm+eFhC4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=McOK46IKF+Sfc8pwjlmc3zl/Ta4Su/HEA4QFon2H3mFScStwqFbpLgOjKeZ92QB2QZIu2YWVth9OahcTPl0FC5xnzNummZP9Gun2h6j4JOOcVokhX+aQpthmxe2ZIe+Nu4ZGeLMFsza1RHNPwWeXZaPngRYrh9bRJSUCmQCLySc= 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=Ml0vmaU5; arc=none smtp.client-ip=192.198.163.14 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="Ml0vmaU5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750855885; x=1782391885; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gSrgyF7nkaMy9jgn9VB3Vel47cqINKRy4i1jm+eFhC4=; b=Ml0vmaU5IZEAgS6fxoSeZBMN8zyzAZCNhV1xft2ysOddqe+R6IUj+2Yp CVAVs++xPxqMBv+yEGGtAetGNW14HRBcbjEh6Cu3ktHh5FXvHm7a3b/o2 BntImFKrMR3+hUtkwlz0zgm+5AVMBmVk8M6C124arDgsiCiaHRDxdF8Ig bkjRUbR31z2wBXK0ZvjYMUq6rNTe8lxc4YgZZHHLYQw4sbNwmq2p+PGEu saeguRVnii/t9zwhrWbnjjgghRyGpNPpinPh/dUS+EryUJZLb2i5x3/Dt ipuV3S+3pZv1kkC8K2JzCxwSGkhlQUeaOzBPgJKv55VsbAvqxS00FtZ7/ g==; X-CSE-ConnectionGUID: jQVPtH0RT0O2Mpf4k3YKTA== X-CSE-MsgGUID: v81Lh9nuRRe1t0o3D9xqBQ== X-IronPort-AV: E=McAfee;i="6800,10657,11474"; a="53189452" X-IronPort-AV: E=Sophos;i="6.16,264,1744095600"; d="scan'208";a="53189452" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2025 05:51:24 -0700 X-CSE-ConnectionGUID: nHpb/gW4TziBMGpfqvgHYg== X-CSE-MsgGUID: JoVvoqxOQjKiSdbdHOpAow== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,264,1744095600"; d="scan'208";a="151830926" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa007.fm.intel.com with ESMTP; 25 Jun 2025 05:51:13 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 65B4627C; Wed, 25 Jun 2025 15:51:12 +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: [PATCH] x86/vsyscall: Do not require X86_PF_INSTR to emulate vsyscall Date: Wed, 25 Jun 2025 15:50:54 +0300 Message-ID: <20250625125112.3943745-3-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250625125112.3943745-1-kirill.shutemov@linux.intel.com> References: <20250625125112.3943745-1-kirill.shutemov@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" emulate_vsyscall() expects to see X86_PF_INSTR in PFEC on a vsyscall page fault, but the CPU does not report X86_PF_INSTR if neither X86_FEATURE_NX nor X86_FEATURE_SMEP are enabled. X86_FEATURE_NX should be enabled on nearly all 64-bit CPUs, except for early P4 processors that did not support this feature. Instead of explicitly checking for X86_PF_INSTR, compare the fault address to RIP. On machines with X86_FEATURE_NX enabled, issue a warning if RIP is equal to fault address but X86_PF_INSTR is absent. Originally-by: Dave Hansen Link: https://lore.kernel.org/all/bd81a98b-f8d4-4304-ac55-d4151a1a77ab@inte= l.com Signed-off-by: Kirill A. Shutemov Reported-by: Andrew Cooper Reviewed-by: Andrew Cooper --- arch/x86/entry/vsyscall/vsyscall_64.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/arch/x86/entry/vsyscall/vsyscall_64.c b/arch/x86/entry/vsyscal= l/vsyscall_64.c index c9103a6fa06e..0b0e0283994f 100644 --- a/arch/x86/entry/vsyscall/vsyscall_64.c +++ b/arch/x86/entry/vsyscall/vsyscall_64.c @@ -124,7 +124,8 @@ bool emulate_vsyscall(unsigned long error_code, if ((error_code & (X86_PF_WRITE | X86_PF_USER)) !=3D X86_PF_USER) return false; =20 - if (!(error_code & X86_PF_INSTR)) { + /* Avoid emulation unless userspace was executing from vsyscall page: */ + if (address !=3D regs->ip) { /* Failed vsyscall read */ if (vsyscall_mode =3D=3D EMULATE) return false; @@ -136,13 +137,16 @@ bool emulate_vsyscall(unsigned long error_code, return false; } =20 + + /* X86_PF_INSTR is only set when NX is supported: */ + if (cpu_feature_enabled(X86_FEATURE_NX)) + WARN_ON_ONCE(!(error_code & X86_PF_INSTR)); + /* * No point in checking CS -- the only way to get here is a user mode * trap to a high address, which means that we're in 64-bit user code. */ =20 - WARN_ON_ONCE(address !=3D regs->ip); - if (vsyscall_mode =3D=3D NONE) { warn_bad_vsyscall(KERN_INFO, regs, "vsyscall attempted with vsyscall=3Dnone"); --=20 2.47.2