dump_pagetables.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. /*
  2. * Debug helper to dump the current kernel pagetables of the system
  3. * so that we can see what the various memory ranges are set to.
  4. *
  5. * (C) Copyright 2008 Intel Corporation
  6. *
  7. * Author: Arjan van de Ven <arjan@linux.intel.com>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; version 2
  12. * of the License.
  13. */
  14. #include <linux/debugfs.h>
  15. #include <linux/kasan.h>
  16. #include <linux/mm.h>
  17. #include <linux/init.h>
  18. #include <linux/sched.h>
  19. #include <linux/seq_file.h>
  20. #include <linux/highmem.h>
  21. #include <linux/pci.h>
  22. #include <asm/e820/types.h>
  23. #include <asm/pgtable.h>
  24. /*
  25. * The dumper groups pagetable entries of the same type into one, and for
  26. * that it needs to keep some state when walking, and flush this state
  27. * when a "break" in the continuity is found.
  28. */
  29. struct pg_state {
  30. int level;
  31. pgprot_t current_prot;
  32. pgprotval_t effective_prot;
  33. unsigned long start_address;
  34. unsigned long current_address;
  35. const struct addr_marker *marker;
  36. unsigned long lines;
  37. bool to_dmesg;
  38. bool check_wx;
  39. unsigned long wx_pages;
  40. };
  41. struct addr_marker {
  42. unsigned long start_address;
  43. const char *name;
  44. unsigned long max_lines;
  45. };
  46. /* Address space markers hints */
  47. #ifdef CONFIG_X86_64
  48. enum address_markers_idx {
  49. USER_SPACE_NR = 0,
  50. KERNEL_SPACE_NR,
  51. LOW_KERNEL_NR,
  52. #if defined(CONFIG_MODIFY_LDT_SYSCALL) && defined(CONFIG_X86_5LEVEL)
  53. LDT_NR,
  54. #endif
  55. VMALLOC_START_NR,
  56. VMEMMAP_START_NR,
  57. #ifdef CONFIG_KASAN
  58. KASAN_SHADOW_START_NR,
  59. KASAN_SHADOW_END_NR,
  60. #endif
  61. CPU_ENTRY_AREA_NR,
  62. #if defined(CONFIG_MODIFY_LDT_SYSCALL) && !defined(CONFIG_X86_5LEVEL)
  63. LDT_NR,
  64. #endif
  65. #ifdef CONFIG_X86_ESPFIX64
  66. ESPFIX_START_NR,
  67. #endif
  68. #ifdef CONFIG_EFI
  69. EFI_END_NR,
  70. #endif
  71. HIGH_KERNEL_NR,
  72. MODULES_VADDR_NR,
  73. MODULES_END_NR,
  74. FIXADDR_START_NR,
  75. END_OF_SPACE_NR,
  76. };
  77. static struct addr_marker address_markers[] = {
  78. [USER_SPACE_NR] = { 0, "User Space" },
  79. [KERNEL_SPACE_NR] = { (1UL << 63), "Kernel Space" },
  80. [LOW_KERNEL_NR] = { 0UL, "Low Kernel Mapping" },
  81. [VMALLOC_START_NR] = { 0UL, "vmalloc() Area" },
  82. [VMEMMAP_START_NR] = { 0UL, "Vmemmap" },
  83. #ifdef CONFIG_KASAN
  84. /*
  85. * These fields get initialized with the (dynamic)
  86. * KASAN_SHADOW_{START,END} values in pt_dump_init().
  87. */
  88. [KASAN_SHADOW_START_NR] = { 0UL, "KASAN shadow" },
  89. [KASAN_SHADOW_END_NR] = { 0UL, "KASAN shadow end" },
  90. #endif
  91. #ifdef CONFIG_MODIFY_LDT_SYSCALL
  92. [LDT_NR] = { 0UL, "LDT remap" },
  93. #endif
  94. [CPU_ENTRY_AREA_NR] = { CPU_ENTRY_AREA_BASE,"CPU entry Area" },
  95. #ifdef CONFIG_X86_ESPFIX64
  96. [ESPFIX_START_NR] = { ESPFIX_BASE_ADDR, "ESPfix Area", 16 },
  97. #endif
  98. #ifdef CONFIG_EFI
  99. [EFI_END_NR] = { EFI_VA_END, "EFI Runtime Services" },
  100. #endif
  101. [HIGH_KERNEL_NR] = { __START_KERNEL_map, "High Kernel Mapping" },
  102. [MODULES_VADDR_NR] = { MODULES_VADDR, "Modules" },
  103. [MODULES_END_NR] = { MODULES_END, "End Modules" },
  104. [FIXADDR_START_NR] = { FIXADDR_START, "Fixmap Area" },
  105. [END_OF_SPACE_NR] = { -1, NULL }
  106. };
  107. #define INIT_PGD ((pgd_t *) &init_top_pgt)
  108. #else /* CONFIG_X86_64 */
  109. enum address_markers_idx {
  110. USER_SPACE_NR = 0,
  111. KERNEL_SPACE_NR,
  112. VMALLOC_START_NR,
  113. VMALLOC_END_NR,
  114. #ifdef CONFIG_HIGHMEM
  115. PKMAP_BASE_NR,
  116. #endif
  117. #ifdef CONFIG_MODIFY_LDT_SYSCALL
  118. LDT_NR,
  119. #endif
  120. CPU_ENTRY_AREA_NR,
  121. FIXADDR_START_NR,
  122. END_OF_SPACE_NR,
  123. };
  124. static struct addr_marker address_markers[] = {
  125. [USER_SPACE_NR] = { 0, "User Space" },
  126. [KERNEL_SPACE_NR] = { PAGE_OFFSET, "Kernel Mapping" },
  127. [VMALLOC_START_NR] = { 0UL, "vmalloc() Area" },
  128. [VMALLOC_END_NR] = { 0UL, "vmalloc() End" },
  129. #ifdef CONFIG_HIGHMEM
  130. [PKMAP_BASE_NR] = { 0UL, "Persistent kmap() Area" },
  131. #endif
  132. #ifdef CONFIG_MODIFY_LDT_SYSCALL
  133. [LDT_NR] = { 0UL, "LDT remap" },
  134. #endif
  135. [CPU_ENTRY_AREA_NR] = { 0UL, "CPU entry area" },
  136. [FIXADDR_START_NR] = { 0UL, "Fixmap area" },
  137. [END_OF_SPACE_NR] = { -1, NULL }
  138. };
  139. #define INIT_PGD (swapper_pg_dir)
  140. #endif /* !CONFIG_X86_64 */
  141. /* Multipliers for offsets within the PTEs */
  142. #define PTE_LEVEL_MULT (PAGE_SIZE)
  143. #define PMD_LEVEL_MULT (PTRS_PER_PTE * PTE_LEVEL_MULT)
  144. #define PUD_LEVEL_MULT (PTRS_PER_PMD * PMD_LEVEL_MULT)
  145. #define P4D_LEVEL_MULT (PTRS_PER_PUD * PUD_LEVEL_MULT)
  146. #define PGD_LEVEL_MULT (PTRS_PER_P4D * P4D_LEVEL_MULT)
  147. #define pt_dump_seq_printf(m, to_dmesg, fmt, args...) \
  148. ({ \
  149. if (to_dmesg) \
  150. printk(KERN_INFO fmt, ##args); \
  151. else \
  152. if (m) \
  153. seq_printf(m, fmt, ##args); \
  154. })
  155. #define pt_dump_cont_printf(m, to_dmesg, fmt, args...) \
  156. ({ \
  157. if (to_dmesg) \
  158. printk(KERN_CONT fmt, ##args); \
  159. else \
  160. if (m) \
  161. seq_printf(m, fmt, ##args); \
  162. })
  163. /*
  164. * Print a readable form of a pgprot_t to the seq_file
  165. */
  166. static void printk_prot(struct seq_file *m, pgprot_t prot, int level, bool dmsg)
  167. {
  168. pgprotval_t pr = pgprot_val(prot);
  169. static const char * const level_name[] =
  170. { "cr3", "pgd", "p4d", "pud", "pmd", "pte" };
  171. if (!(pr & _PAGE_PRESENT)) {
  172. /* Not present */
  173. pt_dump_cont_printf(m, dmsg, " ");
  174. } else {
  175. if (pr & _PAGE_USER)
  176. pt_dump_cont_printf(m, dmsg, "USR ");
  177. else
  178. pt_dump_cont_printf(m, dmsg, " ");
  179. if (pr & _PAGE_RW)
  180. pt_dump_cont_printf(m, dmsg, "RW ");
  181. else
  182. pt_dump_cont_printf(m, dmsg, "ro ");
  183. if (pr & _PAGE_PWT)
  184. pt_dump_cont_printf(m, dmsg, "PWT ");
  185. else
  186. pt_dump_cont_printf(m, dmsg, " ");
  187. if (pr & _PAGE_PCD)
  188. pt_dump_cont_printf(m, dmsg, "PCD ");
  189. else
  190. pt_dump_cont_printf(m, dmsg, " ");
  191. /* Bit 7 has a different meaning on level 3 vs 4 */
  192. if (level <= 4 && pr & _PAGE_PSE)
  193. pt_dump_cont_printf(m, dmsg, "PSE ");
  194. else
  195. pt_dump_cont_printf(m, dmsg, " ");
  196. if ((level == 5 && pr & _PAGE_PAT) ||
  197. ((level == 4 || level == 3) && pr & _PAGE_PAT_LARGE))
  198. pt_dump_cont_printf(m, dmsg, "PAT ");
  199. else
  200. pt_dump_cont_printf(m, dmsg, " ");
  201. if (pr & _PAGE_GLOBAL)
  202. pt_dump_cont_printf(m, dmsg, "GLB ");
  203. else
  204. pt_dump_cont_printf(m, dmsg, " ");
  205. if (pr & _PAGE_NX)
  206. pt_dump_cont_printf(m, dmsg, "NX ");
  207. else
  208. pt_dump_cont_printf(m, dmsg, "x ");
  209. }
  210. pt_dump_cont_printf(m, dmsg, "%s\n", level_name[level]);
  211. }
  212. /*
  213. * On 64 bits, sign-extend the 48 bit address to 64 bit
  214. */
  215. static unsigned long normalize_addr(unsigned long u)
  216. {
  217. int shift;
  218. if (!IS_ENABLED(CONFIG_X86_64))
  219. return u;
  220. shift = 64 - (__VIRTUAL_MASK_SHIFT + 1);
  221. return (signed long)(u << shift) >> shift;
  222. }
  223. static void note_wx(struct pg_state *st)
  224. {
  225. unsigned long npages;
  226. npages = (st->current_address - st->start_address) / PAGE_SIZE;
  227. #ifdef CONFIG_PCI_BIOS
  228. /*
  229. * If PCI BIOS is enabled, the PCI BIOS area is forced to WX.
  230. * Inform about it, but avoid the warning.
  231. */
  232. if (pcibios_enabled && st->start_address >= PAGE_OFFSET + BIOS_BEGIN &&
  233. st->current_address <= PAGE_OFFSET + BIOS_END) {
  234. pr_warn_once("x86/mm: PCI BIOS W+X mapping %lu pages\n", npages);
  235. return;
  236. }
  237. #endif
  238. /* Account the WX pages */
  239. st->wx_pages += npages;
  240. WARN_ONCE(1, "x86/mm: Found insecure W+X mapping at address %pS\n",
  241. (void *)st->start_address);
  242. }
  243. /*
  244. * This function gets called on a break in a continuous series
  245. * of PTE entries; the next one is different so we need to
  246. * print what we collected so far.
  247. */
  248. static void note_page(struct seq_file *m, struct pg_state *st,
  249. pgprot_t new_prot, pgprotval_t new_eff, int level)
  250. {
  251. pgprotval_t prot, cur, eff;
  252. static const char units[] = "BKMGTPE";
  253. /*
  254. * If we have a "break" in the series, we need to flush the state that
  255. * we have now. "break" is either changing perms, levels or
  256. * address space marker.
  257. */
  258. prot = pgprot_val(new_prot);
  259. cur = pgprot_val(st->current_prot);
  260. eff = st->effective_prot;
  261. if (!st->level) {
  262. /* First entry */
  263. st->current_prot = new_prot;
  264. st->effective_prot = new_eff;
  265. st->level = level;
  266. st->marker = address_markers;
  267. st->lines = 0;
  268. pt_dump_seq_printf(m, st->to_dmesg, "---[ %s ]---\n",
  269. st->marker->name);
  270. } else if (prot != cur || new_eff != eff || level != st->level ||
  271. st->current_address >= st->marker[1].start_address) {
  272. const char *unit = units;
  273. unsigned long delta;
  274. int width = sizeof(unsigned long) * 2;
  275. if (st->check_wx && (eff & _PAGE_RW) && !(eff & _PAGE_NX))
  276. note_wx(st);
  277. /*
  278. * Now print the actual finished series
  279. */
  280. if (!st->marker->max_lines ||
  281. st->lines < st->marker->max_lines) {
  282. pt_dump_seq_printf(m, st->to_dmesg,
  283. "0x%0*lx-0x%0*lx ",
  284. width, st->start_address,
  285. width, st->current_address);
  286. delta = st->current_address - st->start_address;
  287. while (!(delta & 1023) && unit[1]) {
  288. delta >>= 10;
  289. unit++;
  290. }
  291. pt_dump_cont_printf(m, st->to_dmesg, "%9lu%c ",
  292. delta, *unit);
  293. printk_prot(m, st->current_prot, st->level,
  294. st->to_dmesg);
  295. }
  296. st->lines++;
  297. /*
  298. * We print markers for special areas of address space,
  299. * such as the start of vmalloc space etc.
  300. * This helps in the interpretation.
  301. */
  302. if (st->current_address >= st->marker[1].start_address) {
  303. if (st->marker->max_lines &&
  304. st->lines > st->marker->max_lines) {
  305. unsigned long nskip =
  306. st->lines - st->marker->max_lines;
  307. pt_dump_seq_printf(m, st->to_dmesg,
  308. "... %lu entr%s skipped ... \n",
  309. nskip,
  310. nskip == 1 ? "y" : "ies");
  311. }
  312. st->marker++;
  313. st->lines = 0;
  314. pt_dump_seq_printf(m, st->to_dmesg, "---[ %s ]---\n",
  315. st->marker->name);
  316. }
  317. st->start_address = st->current_address;
  318. st->current_prot = new_prot;
  319. st->effective_prot = new_eff;
  320. st->level = level;
  321. }
  322. }
  323. static inline pgprotval_t effective_prot(pgprotval_t prot1, pgprotval_t prot2)
  324. {
  325. return (prot1 & prot2 & (_PAGE_USER | _PAGE_RW)) |
  326. ((prot1 | prot2) & _PAGE_NX);
  327. }
  328. static void walk_pte_level(struct seq_file *m, struct pg_state *st, pmd_t addr,
  329. pgprotval_t eff_in, unsigned long P)
  330. {
  331. int i;
  332. pte_t *pte;
  333. pgprotval_t prot, eff;
  334. for (i = 0; i < PTRS_PER_PTE; i++) {
  335. st->current_address = normalize_addr(P + i * PTE_LEVEL_MULT);
  336. pte = pte_offset_map(&addr, st->current_address);
  337. prot = pte_flags(*pte);
  338. eff = effective_prot(eff_in, prot);
  339. note_page(m, st, __pgprot(prot), eff, 5);
  340. pte_unmap(pte);
  341. }
  342. }
  343. #ifdef CONFIG_KASAN
  344. /*
  345. * This is an optimization for KASAN=y case. Since all kasan page tables
  346. * eventually point to the kasan_zero_page we could call note_page()
  347. * right away without walking through lower level page tables. This saves
  348. * us dozens of seconds (minutes for 5-level config) while checking for
  349. * W+X mapping or reading kernel_page_tables debugfs file.
  350. */
  351. static inline bool kasan_page_table(struct seq_file *m, struct pg_state *st,
  352. void *pt)
  353. {
  354. if (__pa(pt) == __pa(kasan_zero_pmd) ||
  355. (pgtable_l5_enabled() && __pa(pt) == __pa(kasan_zero_p4d)) ||
  356. __pa(pt) == __pa(kasan_zero_pud)) {
  357. pgprotval_t prot = pte_flags(kasan_zero_pte[0]);
  358. note_page(m, st, __pgprot(prot), 0, 5);
  359. return true;
  360. }
  361. return false;
  362. }
  363. #else
  364. static inline bool kasan_page_table(struct seq_file *m, struct pg_state *st,
  365. void *pt)
  366. {
  367. return false;
  368. }
  369. #endif
  370. #if PTRS_PER_PMD > 1
  371. static void walk_pmd_level(struct seq_file *m, struct pg_state *st, pud_t addr,
  372. pgprotval_t eff_in, unsigned long P)
  373. {
  374. int i;
  375. pmd_t *start, *pmd_start;
  376. pgprotval_t prot, eff;
  377. pmd_start = start = (pmd_t *)pud_page_vaddr(addr);
  378. for (i = 0; i < PTRS_PER_PMD; i++) {
  379. st->current_address = normalize_addr(P + i * PMD_LEVEL_MULT);
  380. if (!pmd_none(*start)) {
  381. prot = pmd_flags(*start);
  382. eff = effective_prot(eff_in, prot);
  383. if (pmd_large(*start) || !pmd_present(*start)) {
  384. note_page(m, st, __pgprot(prot), eff, 4);
  385. } else if (!kasan_page_table(m, st, pmd_start)) {
  386. walk_pte_level(m, st, *start, eff,
  387. P + i * PMD_LEVEL_MULT);
  388. }
  389. } else
  390. note_page(m, st, __pgprot(0), 0, 4);
  391. start++;
  392. }
  393. }
  394. #else
  395. #define walk_pmd_level(m,s,a,e,p) walk_pte_level(m,s,__pmd(pud_val(a)),e,p)
  396. #define pud_large(a) pmd_large(__pmd(pud_val(a)))
  397. #define pud_none(a) pmd_none(__pmd(pud_val(a)))
  398. #endif
  399. #if PTRS_PER_PUD > 1
  400. static void walk_pud_level(struct seq_file *m, struct pg_state *st, p4d_t addr,
  401. pgprotval_t eff_in, unsigned long P)
  402. {
  403. int i;
  404. pud_t *start, *pud_start;
  405. pgprotval_t prot, eff;
  406. pud_t *prev_pud = NULL;
  407. pud_start = start = (pud_t *)p4d_page_vaddr(addr);
  408. for (i = 0; i < PTRS_PER_PUD; i++) {
  409. st->current_address = normalize_addr(P + i * PUD_LEVEL_MULT);
  410. if (!pud_none(*start)) {
  411. prot = pud_flags(*start);
  412. eff = effective_prot(eff_in, prot);
  413. if (pud_large(*start) || !pud_present(*start)) {
  414. note_page(m, st, __pgprot(prot), eff, 3);
  415. } else if (!kasan_page_table(m, st, pud_start)) {
  416. walk_pmd_level(m, st, *start, eff,
  417. P + i * PUD_LEVEL_MULT);
  418. }
  419. } else
  420. note_page(m, st, __pgprot(0), 0, 3);
  421. prev_pud = start;
  422. start++;
  423. }
  424. }
  425. #else
  426. #define walk_pud_level(m,s,a,e,p) walk_pmd_level(m,s,__pud(p4d_val(a)),e,p)
  427. #define p4d_large(a) pud_large(__pud(p4d_val(a)))
  428. #define p4d_none(a) pud_none(__pud(p4d_val(a)))
  429. #endif
  430. static void walk_p4d_level(struct seq_file *m, struct pg_state *st, pgd_t addr,
  431. pgprotval_t eff_in, unsigned long P)
  432. {
  433. int i;
  434. p4d_t *start, *p4d_start;
  435. pgprotval_t prot, eff;
  436. if (PTRS_PER_P4D == 1)
  437. return walk_pud_level(m, st, __p4d(pgd_val(addr)), eff_in, P);
  438. p4d_start = start = (p4d_t *)pgd_page_vaddr(addr);
  439. for (i = 0; i < PTRS_PER_P4D; i++) {
  440. st->current_address = normalize_addr(P + i * P4D_LEVEL_MULT);
  441. if (!p4d_none(*start)) {
  442. prot = p4d_flags(*start);
  443. eff = effective_prot(eff_in, prot);
  444. if (p4d_large(*start) || !p4d_present(*start)) {
  445. note_page(m, st, __pgprot(prot), eff, 2);
  446. } else if (!kasan_page_table(m, st, p4d_start)) {
  447. walk_pud_level(m, st, *start, eff,
  448. P + i * P4D_LEVEL_MULT);
  449. }
  450. } else
  451. note_page(m, st, __pgprot(0), 0, 2);
  452. start++;
  453. }
  454. }
  455. #define pgd_large(a) (pgtable_l5_enabled() ? pgd_large(a) : p4d_large(__p4d(pgd_val(a))))
  456. #define pgd_none(a) (pgtable_l5_enabled() ? pgd_none(a) : p4d_none(__p4d(pgd_val(a))))
  457. static inline bool is_hypervisor_range(int idx)
  458. {
  459. #ifdef CONFIG_X86_64
  460. /*
  461. * ffff800000000000 - ffff87ffffffffff is reserved for
  462. * the hypervisor.
  463. */
  464. return (idx >= pgd_index(__PAGE_OFFSET) - 16) &&
  465. (idx < pgd_index(__PAGE_OFFSET));
  466. #else
  467. return false;
  468. #endif
  469. }
  470. static void ptdump_walk_pgd_level_core(struct seq_file *m, pgd_t *pgd,
  471. bool checkwx, bool dmesg)
  472. {
  473. pgd_t *start = INIT_PGD;
  474. pgprotval_t prot, eff;
  475. int i;
  476. struct pg_state st = {};
  477. if (pgd) {
  478. start = pgd;
  479. st.to_dmesg = dmesg;
  480. }
  481. st.check_wx = checkwx;
  482. if (checkwx)
  483. st.wx_pages = 0;
  484. for (i = 0; i < PTRS_PER_PGD; i++) {
  485. st.current_address = normalize_addr(i * PGD_LEVEL_MULT);
  486. if (!pgd_none(*start) && !is_hypervisor_range(i)) {
  487. prot = pgd_flags(*start);
  488. #ifdef CONFIG_X86_PAE
  489. eff = _PAGE_USER | _PAGE_RW;
  490. #else
  491. eff = prot;
  492. #endif
  493. if (pgd_large(*start) || !pgd_present(*start)) {
  494. note_page(m, &st, __pgprot(prot), eff, 1);
  495. } else {
  496. walk_p4d_level(m, &st, *start, eff,
  497. i * PGD_LEVEL_MULT);
  498. }
  499. } else
  500. note_page(m, &st, __pgprot(0), 0, 1);
  501. cond_resched();
  502. start++;
  503. }
  504. /* Flush out the last page */
  505. st.current_address = normalize_addr(PTRS_PER_PGD*PGD_LEVEL_MULT);
  506. note_page(m, &st, __pgprot(0), 0, 0);
  507. if (!checkwx)
  508. return;
  509. if (st.wx_pages)
  510. pr_info("x86/mm: Checked W+X mappings: FAILED, %lu W+X pages found.\n",
  511. st.wx_pages);
  512. else
  513. pr_info("x86/mm: Checked W+X mappings: passed, no W+X pages found.\n");
  514. }
  515. void ptdump_walk_pgd_level(struct seq_file *m, pgd_t *pgd)
  516. {
  517. ptdump_walk_pgd_level_core(m, pgd, false, true);
  518. }
  519. void ptdump_walk_pgd_level_debugfs(struct seq_file *m, pgd_t *pgd, bool user)
  520. {
  521. #ifdef CONFIG_PAGE_TABLE_ISOLATION
  522. if (user && static_cpu_has(X86_FEATURE_PTI))
  523. pgd = kernel_to_user_pgdp(pgd);
  524. #endif
  525. ptdump_walk_pgd_level_core(m, pgd, false, false);
  526. }
  527. EXPORT_SYMBOL_GPL(ptdump_walk_pgd_level_debugfs);
  528. void ptdump_walk_user_pgd_level_checkwx(void)
  529. {
  530. #ifdef CONFIG_PAGE_TABLE_ISOLATION
  531. pgd_t *pgd = INIT_PGD;
  532. if (!(__supported_pte_mask & _PAGE_NX) ||
  533. !static_cpu_has(X86_FEATURE_PTI))
  534. return;
  535. pr_info("x86/mm: Checking user space page tables\n");
  536. pgd = kernel_to_user_pgdp(pgd);
  537. ptdump_walk_pgd_level_core(NULL, pgd, true, false);
  538. #endif
  539. }
  540. void ptdump_walk_pgd_level_checkwx(void)
  541. {
  542. ptdump_walk_pgd_level_core(NULL, NULL, true, false);
  543. }
  544. static int __init pt_dump_init(void)
  545. {
  546. /*
  547. * Various markers are not compile-time constants, so assign them
  548. * here.
  549. */
  550. #ifdef CONFIG_X86_64
  551. address_markers[LOW_KERNEL_NR].start_address = PAGE_OFFSET;
  552. address_markers[VMALLOC_START_NR].start_address = VMALLOC_START;
  553. address_markers[VMEMMAP_START_NR].start_address = VMEMMAP_START;
  554. #ifdef CONFIG_MODIFY_LDT_SYSCALL
  555. address_markers[LDT_NR].start_address = LDT_BASE_ADDR;
  556. #endif
  557. #ifdef CONFIG_KASAN
  558. address_markers[KASAN_SHADOW_START_NR].start_address = KASAN_SHADOW_START;
  559. address_markers[KASAN_SHADOW_END_NR].start_address = KASAN_SHADOW_END;
  560. #endif
  561. #endif
  562. #ifdef CONFIG_X86_32
  563. address_markers[VMALLOC_START_NR].start_address = VMALLOC_START;
  564. address_markers[VMALLOC_END_NR].start_address = VMALLOC_END;
  565. # ifdef CONFIG_HIGHMEM
  566. address_markers[PKMAP_BASE_NR].start_address = PKMAP_BASE;
  567. # endif
  568. address_markers[FIXADDR_START_NR].start_address = FIXADDR_START;
  569. address_markers[CPU_ENTRY_AREA_NR].start_address = CPU_ENTRY_AREA_BASE;
  570. # ifdef CONFIG_MODIFY_LDT_SYSCALL
  571. address_markers[LDT_NR].start_address = LDT_BASE_ADDR;
  572. # endif
  573. #endif
  574. return 0;
  575. }
  576. __initcall(pt_dump_init);