Skip to content

Commit bf7d28c

Browse files
Peng HaoKAGA-KOKO
authored andcommitted
x86/mm/mem_encrypt: Fix erroneous sizeof()
Using sizeof(pointer) for determining the size of a memset() only works when the size of the pointer and the size of type to which it points are the same. For pte_t this is only true for 64bit and 32bit-NONPAE. On 32bit PAE systems this is wrong as the pointer size is 4 byte but the PTE entry is 8 bytes. It's actually not a real world issue as this code depends on 64bit, but it's wrong nevertheless. Use sizeof(*p) for correctness sake. Fixes: aad9839 ("x86/mm/encrypt: Simplify sme_populate_pgd() and sme_populate_pgd_large()") Signed-off-by: Peng Hao <peng.hao2@zte.com.cn> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Tom Lendacky <thomas.lendacky@amd.com> Cc: dave.hansen@linux.intel.com Cc: peterz@infradead.org Cc: luto@kernel.org Link: https://lkml.kernel.org/r/1546065252-97996-1-git-send-email-peng.hao2@zte.com.cn
1 parent e181293 commit bf7d28c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

arch/x86/mm/mem_encrypt_identity.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ static void __init sme_populate_pgd(struct sme_populate_pgd_data *ppd)
158158
pmd = pmd_offset(pud, ppd->vaddr);
159159
if (pmd_none(*pmd)) {
160160
pte = ppd->pgtable_area;
161-
memset(pte, 0, sizeof(pte) * PTRS_PER_PTE);
162-
ppd->pgtable_area += sizeof(pte) * PTRS_PER_PTE;
161+
memset(pte, 0, sizeof(*pte) * PTRS_PER_PTE);
162+
ppd->pgtable_area += sizeof(*pte) * PTRS_PER_PTE;
163163
set_pmd(pmd, __pmd(PMD_FLAGS | __pa(pte)));
164164
}
165165

0 commit comments

Comments
 (0)