[PATCH 07/11] x86/mm: comment _PAGE_GLOBAL mystery
From: Dave HansenI was mystified as to where the _PAGE_GLOBAL in the kernel page tables for kernel text came from. I audited all the places I could find, but I missed one: head_64.S. The page tables that we create in here live for a long time, and they also have _PAGE_GLOBAL set, despite whether the processor supports it or not. It's harmless, and we got *lucky* that the pageattr code accidentally clears it when we wipe it out of __supported_pte_mask and then later try to mark kernel text read-only. Comment some of these properties to make it easier to find and understand in the future. Signed-off-by: Dave Hansen Cc: Andrea Arcangeli Cc: Andy Lutomirski Cc: Linus Torvalds Cc: Kees Cook Cc: Hugh Dickins Cc: Juergen Gross Cc: x...@kernel.org Cc: Nadav Amit --- b/arch/x86/kernel/head_64.S | 11 ++- 1 file changed, 10 insertions(+), 1 deletion(-) diff -puN arch/x86/kernel/head_64.S~comment-global-page arch/x86/kernel/head_64.S --- a/arch/x86/kernel/head_64.S~comment-global-page 2018-04-06 10:47:57.176796121 -0700 +++ b/arch/x86/kernel/head_64.S 2018-04-06 10:47:57.179796121 -0700 @@ -399,8 +399,13 @@ NEXT_PAGE(level3_ident_pgt) .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE_NOENC .fill 511, 8, 0 NEXT_PAGE(level2_ident_pgt) - /* Since I easily can, map the first 1G. + /* +* Since I easily can, map the first 1G. * Don't set NX because code runs from these pages. +* +* Note: This sets _PAGE_GLOBAL despite whether +* the CPU supports it or it is enabled. But, +* the CPU should ignore the bit. */ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD) #else @@ -431,6 +436,10 @@ NEXT_PAGE(level2_kernel_pgt) * (NOTE: at +512MB starts the module area, see MODULES_VADDR. * If you want to increase this then increase MODULES_VADDR * too.) +* +* This table is eventually used by the kernel during normal +* runtime. Care must be taken to clear out undesired bits +* later, like _PAGE_RW or _PAGE_GLOBAL in some cases. */ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE) _
[PATCH 07/11] x86/mm: comment _PAGE_GLOBAL mystery
From: Dave Hansen I was mystified as to where the _PAGE_GLOBAL in the kernel page tables for kernel text came from. I audited all the places I could find, but I missed one: head_64.S. The page tables that we create in here live for a long time, and they also have _PAGE_GLOBAL set, despite whether the processor supports it or not. It's harmless, and we got *lucky* that the pageattr code accidentally clears it when we wipe it out of __supported_pte_mask and then later try to mark kernel text read-only. Comment some of these properties to make it easier to find and understand in the future. Signed-off-by: Dave Hansen Cc: Andrea Arcangeli Cc: Andy Lutomirski Cc: Linus Torvalds Cc: Kees Cook Cc: Hugh Dickins Cc: Juergen Gross Cc: x...@kernel.org Cc: Nadav Amit --- b/arch/x86/kernel/head_64.S | 11 ++- 1 file changed, 10 insertions(+), 1 deletion(-) diff -puN arch/x86/kernel/head_64.S~comment-global-page arch/x86/kernel/head_64.S --- a/arch/x86/kernel/head_64.S~comment-global-page 2018-04-06 10:47:57.176796121 -0700 +++ b/arch/x86/kernel/head_64.S 2018-04-06 10:47:57.179796121 -0700 @@ -399,8 +399,13 @@ NEXT_PAGE(level3_ident_pgt) .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE_NOENC .fill 511, 8, 0 NEXT_PAGE(level2_ident_pgt) - /* Since I easily can, map the first 1G. + /* +* Since I easily can, map the first 1G. * Don't set NX because code runs from these pages. +* +* Note: This sets _PAGE_GLOBAL despite whether +* the CPU supports it or it is enabled. But, +* the CPU should ignore the bit. */ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD) #else @@ -431,6 +436,10 @@ NEXT_PAGE(level2_kernel_pgt) * (NOTE: at +512MB starts the module area, see MODULES_VADDR. * If you want to increase this then increase MODULES_VADDR * too.) +* +* This table is eventually used by the kernel during normal +* runtime. Care must be taken to clear out undesired bits +* later, like _PAGE_RW or _PAGE_GLOBAL in some cases. */ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE) _
[PATCH 07/11] x86/mm: comment _PAGE_GLOBAL mystery
From: Dave HansenI was mystified as to where the _PAGE_GLOBAL in the kernel page tables for kernel text came from. I audited all the places I could find, but I missed one: head_64.S. The page tables that we create in here live for a long time, and they also have _PAGE_GLOBAL set, despite whether the processor supports it or not. It's harmless, and we got *lucky* that the pageattr code accidentally clears it when we wipe it out of __supported_pte_mask and then later try to mark kernel text read-only. Comment some of these properties to make it easier to find and understand in the future. Signed-off-by: Dave Hansen Cc: Andrea Arcangeli Cc: Andy Lutomirski Cc: Linus Torvalds Cc: Kees Cook Cc: Hugh Dickins Cc: Juergen Gross Cc: x...@kernel.org Cc: Nadav Amit --- b/arch/x86/kernel/head_64.S | 11 ++- 1 file changed, 10 insertions(+), 1 deletion(-) diff -puN arch/x86/kernel/head_64.S~comment-global-page arch/x86/kernel/head_64.S --- a/arch/x86/kernel/head_64.S~comment-global-page 2018-04-02 16:41:16.085605170 -0700 +++ b/arch/x86/kernel/head_64.S 2018-04-02 16:41:16.088605170 -0700 @@ -399,8 +399,13 @@ NEXT_PAGE(level3_ident_pgt) .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE_NOENC .fill 511, 8, 0 NEXT_PAGE(level2_ident_pgt) - /* Since I easily can, map the first 1G. + /* +* Since I easily can, map the first 1G. * Don't set NX because code runs from these pages. +* +* Note: This sets _PAGE_GLOBAL despite whether +* the CPU supports it or it is enabled. But, +* the CPU should ignore the bit. */ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD) #else @@ -431,6 +436,10 @@ NEXT_PAGE(level2_kernel_pgt) * (NOTE: at +512MB starts the module area, see MODULES_VADDR. * If you want to increase this then increase MODULES_VADDR * too.) +* +* This table is eventually used by the kernel during normal +* runtime. Care must be taken to clear out undesired bits +* later, like _PAGE_RW or _PAGE_GLOBAL in some cases. */ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE) _
[PATCH 07/11] x86/mm: comment _PAGE_GLOBAL mystery
From: Dave Hansen I was mystified as to where the _PAGE_GLOBAL in the kernel page tables for kernel text came from. I audited all the places I could find, but I missed one: head_64.S. The page tables that we create in here live for a long time, and they also have _PAGE_GLOBAL set, despite whether the processor supports it or not. It's harmless, and we got *lucky* that the pageattr code accidentally clears it when we wipe it out of __supported_pte_mask and then later try to mark kernel text read-only. Comment some of these properties to make it easier to find and understand in the future. Signed-off-by: Dave Hansen Cc: Andrea Arcangeli Cc: Andy Lutomirski Cc: Linus Torvalds Cc: Kees Cook Cc: Hugh Dickins Cc: Juergen Gross Cc: x...@kernel.org Cc: Nadav Amit --- b/arch/x86/kernel/head_64.S | 11 ++- 1 file changed, 10 insertions(+), 1 deletion(-) diff -puN arch/x86/kernel/head_64.S~comment-global-page arch/x86/kernel/head_64.S --- a/arch/x86/kernel/head_64.S~comment-global-page 2018-04-02 16:41:16.085605170 -0700 +++ b/arch/x86/kernel/head_64.S 2018-04-02 16:41:16.088605170 -0700 @@ -399,8 +399,13 @@ NEXT_PAGE(level3_ident_pgt) .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE_NOENC .fill 511, 8, 0 NEXT_PAGE(level2_ident_pgt) - /* Since I easily can, map the first 1G. + /* +* Since I easily can, map the first 1G. * Don't set NX because code runs from these pages. +* +* Note: This sets _PAGE_GLOBAL despite whether +* the CPU supports it or it is enabled. But, +* the CPU should ignore the bit. */ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD) #else @@ -431,6 +436,10 @@ NEXT_PAGE(level2_kernel_pgt) * (NOTE: at +512MB starts the module area, see MODULES_VADDR. * If you want to increase this then increase MODULES_VADDR * too.) +* +* This table is eventually used by the kernel during normal +* runtime. Care must be taken to clear out undesired bits +* later, like _PAGE_RW or _PAGE_GLOBAL in some cases. */ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE) _
[PATCH 07/11] x86/mm: comment _PAGE_GLOBAL mystery
From: Dave HansenI was mystified as to where the _PAGE_GLOBAL in the kernel page tables for kernel text came from. I audited all the places I could find, but I missed one: head_64.S. The page tables that we create in here live for a long time, and they also have _PAGE_GLOBAL set, despite whether the processor supports it or not. It's harmless, and we got *lucky* that the pageattr code accidentally clears it when we wipe it out of __supported_pte_mask and then later try to mark kernel text read-only. Comment some of these properties to make it easier to find and understand in the future. Signed-off-by: Dave Hansen Cc: Andrea Arcangeli Cc: Andy Lutomirski Cc: Linus Torvalds Cc: Kees Cook Cc: Hugh Dickins Cc: Juergen Gross Cc: x...@kernel.org Cc: Nadav Amit --- b/arch/x86/kernel/head_64.S | 11 ++- 1 file changed, 10 insertions(+), 1 deletion(-) diff -puN arch/x86/kernel/head_64.S~comment-global-page arch/x86/kernel/head_64.S --- a/arch/x86/kernel/head_64.S~comment-global-page 2018-04-02 10:26:46.113661210 -0700 +++ b/arch/x86/kernel/head_64.S 2018-04-02 10:26:46.116661210 -0700 @@ -399,8 +399,13 @@ NEXT_PAGE(level3_ident_pgt) .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE_NOENC .fill 511, 8, 0 NEXT_PAGE(level2_ident_pgt) - /* Since I easily can, map the first 1G. + /* +* Since I easily can, map the first 1G. * Don't set NX because code runs from these pages. +* +* Note: This sets _PAGE_GLOBAL despite whether +* the CPU supports it or it is enabled. But, +* the CPU should ignore the bit. */ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD) #else @@ -431,6 +436,10 @@ NEXT_PAGE(level2_kernel_pgt) * (NOTE: at +512MB starts the module area, see MODULES_VADDR. * If you want to increase this then increase MODULES_VADDR * too.) +* +* This table is eventually used by the kernel during normal +* runtime. Care must be taken to clear out undesired bits +* later, like _PAGE_RW or _PAGE_GLOBAL in some cases. */ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE) _
[PATCH 07/11] x86/mm: comment _PAGE_GLOBAL mystery
From: Dave Hansen I was mystified as to where the _PAGE_GLOBAL in the kernel page tables for kernel text came from. I audited all the places I could find, but I missed one: head_64.S. The page tables that we create in here live for a long time, and they also have _PAGE_GLOBAL set, despite whether the processor supports it or not. It's harmless, and we got *lucky* that the pageattr code accidentally clears it when we wipe it out of __supported_pte_mask and then later try to mark kernel text read-only. Comment some of these properties to make it easier to find and understand in the future. Signed-off-by: Dave Hansen Cc: Andrea Arcangeli Cc: Andy Lutomirski Cc: Linus Torvalds Cc: Kees Cook Cc: Hugh Dickins Cc: Juergen Gross Cc: x...@kernel.org Cc: Nadav Amit --- b/arch/x86/kernel/head_64.S | 11 ++- 1 file changed, 10 insertions(+), 1 deletion(-) diff -puN arch/x86/kernel/head_64.S~comment-global-page arch/x86/kernel/head_64.S --- a/arch/x86/kernel/head_64.S~comment-global-page 2018-04-02 10:26:46.113661210 -0700 +++ b/arch/x86/kernel/head_64.S 2018-04-02 10:26:46.116661210 -0700 @@ -399,8 +399,13 @@ NEXT_PAGE(level3_ident_pgt) .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE_NOENC .fill 511, 8, 0 NEXT_PAGE(level2_ident_pgt) - /* Since I easily can, map the first 1G. + /* +* Since I easily can, map the first 1G. * Don't set NX because code runs from these pages. +* +* Note: This sets _PAGE_GLOBAL despite whether +* the CPU supports it or it is enabled. But, +* the CPU should ignore the bit. */ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD) #else @@ -431,6 +436,10 @@ NEXT_PAGE(level2_kernel_pgt) * (NOTE: at +512MB starts the module area, see MODULES_VADDR. * If you want to increase this then increase MODULES_VADDR * too.) +* +* This table is eventually used by the kernel during normal +* runtime. Care must be taken to clear out undesired bits +* later, like _PAGE_RW or _PAGE_GLOBAL in some cases. */ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE) _
[PATCH 07/11] x86/mm: comment _PAGE_GLOBAL mystery
From: Dave HansenI was mystified as to where the _PAGE_GLOBAL in the kernel page tables for kernel text came from. I audited all the places I could find, but I missed one: head_64.S. The page tables that we create in here live for a long time, and they also have _PAGE_GLOBAL set, despite whether the processor supports it or not. It's harmless, and we got *lucky* that the pageattr code accidentally clears it when we wipe it out of __supported_pte_mask and then later try to mark kernel text read-only. Comment some of these properties to make it easier to find and understand in the future. Signed-off-by: Dave Hansen Cc: Andrea Arcangeli Cc: Andy Lutomirski Cc: Linus Torvalds Cc: Kees Cook Cc: Hugh Dickins Cc: Juergen Gross Cc: x...@kernel.org Cc: Nadav Amit --- b/arch/x86/kernel/head_64.S | 11 ++- 1 file changed, 10 insertions(+), 1 deletion(-) diff -puN arch/x86/kernel/head_64.S~comment-global-page arch/x86/kernel/head_64.S --- a/arch/x86/kernel/head_64.S~comment-global-page 2018-03-21 16:31:59.729192314 -0700 +++ b/arch/x86/kernel/head_64.S 2018-03-21 16:31:59.733192314 -0700 @@ -401,8 +401,13 @@ NEXT_PAGE(level3_ident_pgt) .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE_NOENC .fill 511, 8, 0 NEXT_PAGE(level2_ident_pgt) - /* Since I easily can, map the first 1G. + /* +* Since I easily can, map the first 1G. * Don't set NX because code runs from these pages. +* +* Note: This sets _PAGE_GLOBAL despite whether +* the CPU supports it or it is enabled. But, +* the CPU should ignore the bit. */ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD) #else @@ -433,6 +438,10 @@ NEXT_PAGE(level2_kernel_pgt) * (NOTE: at +512MB starts the module area, see MODULES_VADDR. * If you want to increase this then increase MODULES_VADDR * too.) +* +* This table is eventually used by the kernel during normal +* runtime. Care must be taken to clear out undesired bits +* later, like _PAGE_RW or _PAGE_GLOBAL in some cases. */ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE) _
[PATCH 07/11] x86/mm: comment _PAGE_GLOBAL mystery
From: Dave Hansen I was mystified as to where the _PAGE_GLOBAL in the kernel page tables for kernel text came from. I audited all the places I could find, but I missed one: head_64.S. The page tables that we create in here live for a long time, and they also have _PAGE_GLOBAL set, despite whether the processor supports it or not. It's harmless, and we got *lucky* that the pageattr code accidentally clears it when we wipe it out of __supported_pte_mask and then later try to mark kernel text read-only. Comment some of these properties to make it easier to find and understand in the future. Signed-off-by: Dave Hansen Cc: Andrea Arcangeli Cc: Andy Lutomirski Cc: Linus Torvalds Cc: Kees Cook Cc: Hugh Dickins Cc: Juergen Gross Cc: x...@kernel.org Cc: Nadav Amit --- b/arch/x86/kernel/head_64.S | 11 ++- 1 file changed, 10 insertions(+), 1 deletion(-) diff -puN arch/x86/kernel/head_64.S~comment-global-page arch/x86/kernel/head_64.S --- a/arch/x86/kernel/head_64.S~comment-global-page 2018-03-21 16:31:59.729192314 -0700 +++ b/arch/x86/kernel/head_64.S 2018-03-21 16:31:59.733192314 -0700 @@ -401,8 +401,13 @@ NEXT_PAGE(level3_ident_pgt) .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE_NOENC .fill 511, 8, 0 NEXT_PAGE(level2_ident_pgt) - /* Since I easily can, map the first 1G. + /* +* Since I easily can, map the first 1G. * Don't set NX because code runs from these pages. +* +* Note: This sets _PAGE_GLOBAL despite whether +* the CPU supports it or it is enabled. But, +* the CPU should ignore the bit. */ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD) #else @@ -433,6 +438,10 @@ NEXT_PAGE(level2_kernel_pgt) * (NOTE: at +512MB starts the module area, see MODULES_VADDR. * If you want to increase this then increase MODULES_VADDR * too.) +* +* This table is eventually used by the kernel during normal +* runtime. Care must be taken to clear out undesired bits +* later, like _PAGE_RW or _PAGE_GLOBAL in some cases. */ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE) _