Re: [PATCH v2][next] x86/mm/pgtable: Fix -Wstringop-overflow warnings
From: Kees Cook
Date: Wed May 11 2022 - 14:41:35 EST
On Tue, May 10, 2022 at 09:12:02AM -0500, Gustavo A. R. Silva wrote:
> It doesn't seem to work... however, the following piece of code implies
> that pmds and u_pmds should be first preallocated through preallocate_pmds(),
> which cannot happen if (MAX_PREALLOCATED_PMDS != 0 && MAX_PREALLOCATED_USER_PMDS != 0)
This works, weirdly:
diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
index 3481b35cb4ec..937a87b404c3 100644
--- a/arch/x86/mm/pgtable.c
+++ b/arch/x86/mm/pgtable.c
@@ -424,8 +424,8 @@ static inline void _pgd_free(pgd_t *pgd)
pgd_t *pgd_alloc(struct mm_struct *mm)
{
pgd_t *pgd;
- pmd_t *u_pmds[MAX_PREALLOCATED_USER_PMDS];
- pmd_t *pmds[MAX_PREALLOCATED_PMDS];
+ pmd_t *u_pmds[MAX_PREALLOCATED_USER_PMDS + 1];
+ pmd_t *pmds[MAX_PREALLOCATED_PMDS + 1];
pgd = _pgd_alloc();
--
Kees Cook