From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-175.mta1.migadu.com (out-175.mta1.migadu.com [95.215.58.175]) (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 5147A3D5246 for ; Thu, 6 Aug 2026 07:26:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786001211; cv=none; b=E7idOprFv+GY0VYXEyFVhfi/XTtWKrRbrVrQkqd9REgbE5994y3mISFbLKoHz0y181T8O4KnDBXwGOUTSvlUSAV+YzXOHpL5PEY5G21ioPS7m2+waaECUraiGVyqHfFwD1tixHz72cqQ1WUfIkIG8Oe4e9uQAT5QKfwAJEpkZhk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786001211; c=relaxed/simple; bh=xG9GYeCMJiuVoHht7+CmRXfSYtFoSVYQxUu+y64UrdM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=QGvsG6dvfAVC+o+G56ItqCDpGGYhqfiuSWVCDbNXiLTudDAA7HMSlV+S9cdgk/IhDg8H7uuHHSOdcZZUPwMfKGvYUkctDLUjzLqh7lLDdvQnOIBTlNP/Ae7z5xtJBQPslz3Npojz3cEni/JunVe+gzdl91wop+BwkjHV9dUaL54= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=XBQ6/81A; arc=none smtp.client-ip=95.215.58.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="XBQ6/81A" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1786001204; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=/DD5DA621C/0Ih8TsfFf2vNqxg/fjZV4K9NIF6AaZHo=; b=XBQ6/81AiZXo1QIAp05nmsdm2EvbUSm6Ckx+Dmj2q8oRpMVj8SZ+lto5cBKEn780EUITBS iIR41tjT9J9olr7oCfoWUUZ8k282m7n00uwL/SUzaJTbylFMOD5VO4qrUTQm+rmyEr21uh EPu3wPSWIng9kt95zocF7l+dKGjvUCE= From: Thorsten Blum To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Ard Biesheuvel , Yeoreum Yun , Andreas Larsson , Andrew Morton , Kevin Brodsky , "Ahmed S. Darwish" , Tom Lendacky Cc: Thorsten Blum , "Ritesh Harjani (IBM)" , Ingo Molnar , linux-kernel@vger.kernel.org Subject: [PATCH] x86/boot: Fix off-by-one error in sme_clear_pgd() Date: Thu, 6 Aug 2026 09:25:57 +0200 Message-ID: <20260806072558.218173-2-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1214; i=thorsten.blum@linux.dev; h=from:subject; bh=xG9GYeCMJiuVoHht7+CmRXfSYtFoSVYQxUu+y64UrdM=; b=owGbwMvMwCUWt7pQ4caZUj3G02pJDFkl5mxJDz6VZ53uuf7KOOv442O7txyL7RQ5Wno9bt33b OmJncv5OkpZGMS4GGTFFFkezPoxw7e0pnKTScROmDmsTCBDGLg4BWAip08x/PfL7X9WxsXXHXTr 7yr2FwpJycUFWWnnnrK5GCebyroviWf4p3W0+dPLS6cOF6+eU3vn+fWvB3cYMD1yFZ06Z8mrhi0 mQgwA X-Developer-Key: i=thorsten.blum@linux.dev; a=openpgp; fpr=1D60735E8AEF3BE473B69D84733678FD8DFEEAD4 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT The mapping helpers __sme_map_range_pmd() and __sme_map_range_pte(), and therefore sme_encrypt_kernel(), use exclusive end addresses and stop before vaddr reaches vaddr_end. However, sme_clear_pgd() treats vaddr_end as inclusive when calculating the last PGD entry to clear. If vaddr_end is PGD-aligned, the first PGD entry outside the range is cleared too. Use vaddr_end - 1 to calculate the last PGD entry within the range. Fixes: 6ebcb060713f ("x86/mm: Add support to encrypt the kernel in-place") Signed-off-by: Thorsten Blum --- Found by inspection and compile-tested only. --- arch/x86/boot/startup/sme.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/boot/startup/sme.c b/arch/x86/boot/startup/sme.c index c07a2c381ed1..2d5cb3f7eee6 100644 --- a/arch/x86/boot/startup/sme.c +++ b/arch/x86/boot/startup/sme.c @@ -99,7 +99,7 @@ static void __init sme_clear_pgd(struct sme_populate_pgd_data *ppd) pgd_t *pgd_p; pgd_start = ppd->vaddr & PGDIR_MASK; - pgd_end = ppd->vaddr_end & PGDIR_MASK; + pgd_end = (ppd->vaddr_end - 1) & PGDIR_MASK; pgd_size = (((pgd_end - pgd_start) / PGDIR_SIZE) + 1) * sizeof(pgd_t);