Re: [PATCH RESEND] x86/boot: Fix off-by-one error in sme_clear_pgd()

From: Thorsten Blum

Date: Wed Nov 04 2026 - 17:14:30 EST


On Fri, Oct 30, 2026 at 06:46:42PM -0700, Andrew Morton wrote:
> On Fri, 18 Sep 2026 16:27:13 +0200 Thorsten Blum <blum@xxxxxxxxxx> wrote:
>
> > 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.
>
> When fixing a bug, please always fully describe the worst-case
> userspace-visible runtime effects of that bug.
>
> I'm guessing "none known, this is from code inspection"?

Correct, this was found by code inspection.