From nobody Mon Nov 25 12:18:23 2024 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (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 D4BCC1DE2DC; Mon, 28 Oct 2024 16:10:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730131816; cv=none; b=H5MYVfiEDe4u3l32s++yxh04ChW1wX5EAx6TvTgv42PpOiL3qvYKcySGXgCJQtRQJwvXRDycXTFLkGQpCJtJpzreYqWzHbpNqt97lN03PQXbJ9X3AAN/LV6c0Uq7w4ORjOYQ/eu5QdQOMbyn5YS/2YcduUa1N84I1SwO32P1xs0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730131816; c=relaxed/simple; bh=tpZwbxuOtwKafq/ZWaEeClRFkKfw3zvYc+VQ2J4o/A4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZLHKCtIxuH4SCgb2v6sk2MfH8ppSlgD+lULfC4XYKA4bPp8qnTp3unYah81pxhou8ynhmoIpeYcTl2r6djoNqbT2w8nOItwP9226uY6KYAQnqlzIEcMhdNV7mQUBmbftBur6MvT11IzpQ8JipWmzT3uTYZT3vXJlePHd//o/6T4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=FxkXF/7L; arc=none smtp.client-ip=192.198.163.13 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.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="FxkXF/7L" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730131815; x=1761667815; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tpZwbxuOtwKafq/ZWaEeClRFkKfw3zvYc+VQ2J4o/A4=; b=FxkXF/7LJNbVVFCLISRl8LFTejH9b8kadZ8CSBiTImrdED5t9WXgs6Cs AhBHFFvS3sf8Z62BBQ/VBfVp4t/3vFVNY1WfGVWXnpI1xQhJeLB+dUuMU Pzj0+sKHWigUOPLjuOIw+/DRdr4iuB1k1itSBsb9DV6OfW0Kxk2tFR4ck DD4rJi3EDoNfDVvvIQcwT7/6HNjj38AqlfcYnj6ZTWj4OpIZy0/igRc1N eiOVJ3O1rl6PN/msMD5ZV+UIT510vMbLsW+///ekm5qpMl22v76NM6oKY e+WICvH4SGjQ+xf/1PaqO905sIRPbWgQHAR2xeWWu1xKmjB0Gj7KXnvnd A==; X-CSE-ConnectionGUID: Jyj7dEKcRnu+RPe55TL+1A== X-CSE-MsgGUID: Lg1y3D3oQXql4y29tjyMXw== X-IronPort-AV: E=McAfee;i="6700,10204,11239"; a="32593778" X-IronPort-AV: E=Sophos;i="6.11,239,1725346800"; d="scan'208";a="32593778" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Oct 2024 09:10:14 -0700 X-CSE-ConnectionGUID: b+9lEyH3TAafKzlKi/QHOQ== X-CSE-MsgGUID: 67Ww5h8MSAG9oupM/LPE2Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,239,1725346800"; d="scan'208";a="112477913" Received: from black.fi.intel.com (HELO black.fi.intel.com.) ([10.237.72.28]) by orviesa002.jf.intel.com with ESMTP; 28 Oct 2024 09:10:03 -0700 From: Alexander Shishkin 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 , "Kirill A. Shutemov" , Alexey Kardashevskiy Cc: Jonathan Corbet , Alexander Shishkin , 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 Subject: [PATCH v5 03/16] x86/alternatives: Disable LASS when patching kernel alternatives Date: Mon, 28 Oct 2024 18:07:51 +0200 Message-ID: <20241028160917.1380714-4-alexander.shishkin@linux.intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241028160917.1380714-1-alexander.shishkin@linux.intel.com> References: <20241028160917.1380714-1-alexander.shishkin@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" From: Sohil Mehta For patching, the kernel initializes a temporary mm area in the lower half of the address range. See commit 4fc19708b165 ("x86/alternatives: Initialize temporary mm for patching"). Disable LASS enforcement during patching using the stac()/clac() instructions to avoid triggering a #GP fault. The objtool warns due to a call to a non-allowed function that exists outside of the stac/clac guard, or references to any function with a dynamic function pointer inside the guard. See the Objtool warnings section #9 in the document tools/objtool/Documentation/objtool.txt. Considering that patching is usually small, replace the memcpy and memset functions in the text poking functions with their inline versions respectively. Signed-off-by: Sohil Mehta Signed-off-by: Alexander Shishkin --- arch/x86/kernel/alternative.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index d17518ca19b8..2dc097014c2d 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -1841,16 +1841,24 @@ static inline void unuse_temporary_mm(temp_mm_state= _t prev_state) __ro_after_init struct mm_struct *poking_mm; __ro_after_init unsigned long poking_addr; =20 +/* + * poking_init() initializes the text poking address from the lower half o= f the + * address space. Relax LASS enforcement when accessing the poking address. + */ static void text_poke_memcpy(void *dst, const void *src, size_t len) { - memcpy(dst, src, len); + lass_stac(); + __inline_memcpy(dst, src, len); + lass_clac(); } =20 static void text_poke_memset(void *dst, const void *src, size_t len) { int c =3D *(const int *)src; =20 - memset(dst, c, len); + lass_stac(); + __inline_memset(dst, c, len); + lass_clac(); } =20 typedef void text_poke_f(void *dst, const void *src, size_t len); --=20 2.45.2