The patch titled Subject: fs/proc/kcore: pfn_is_ram check only applies to KCORE_RAM has been added to the -mm tree. Its filename is fs-proc-kcore-pfn_is_ram-check-only-applies-to-kcore_ram.patch This patch should soon appear at https://ozlabs.org/~akpm/mmots/broken-out/fs-proc-kcore-pfn_is_ram-check-only-applies-to-kcore_ram.patch and later at https://ozlabs.org/~akpm/mmotm/broken-out/fs-proc-kcore-pfn_is_ram-check-only-applies-to-kcore_ram.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: David Hildenbrand <david@xxxxxxxxxx> Subject: fs/proc/kcore: pfn_is_ram check only applies to KCORE_RAM Let's resturcture the code, using switch-case, and checking pfn_is_ram() only when we are dealing with KCORE_RAM. Link: https://lkml.kernel.org/r/20210526093041.8800-3-david@xxxxxxxxxx Signed-off-by: David Hildenbrand <david@xxxxxxxxxx> Reviewed-by: Mike Rapoport <rppt@xxxxxxxxxxxxx> Cc: Aili Yao <yaoaili@xxxxxxxxxxxx> Cc: Alexey Dobriyan <adobriyan@xxxxxxxxx> Cc: Alex Shi <alex.shi@xxxxxxxxxxxxxxxxx> Cc: Haiyang Zhang <haiyangz@xxxxxxxxxxxxx> Cc: Jason Wang <jasowang@xxxxxxxxxx> Cc: Jiri Bohac <jbohac@xxxxxxx> Cc: "K. Y. Srinivasan" <kys@xxxxxxxxxxxxx> Cc: "Matthew Wilcox (Oracle)" <willy@xxxxxxxxxxxxx> Cc: "Michael S. Tsirkin" <mst@xxxxxxxxxx> Cc: Michal Hocko <mhocko@xxxxxxxx> Cc: Mike Kravetz <mike.kravetz@xxxxxxxxxx> Cc: Naoya Horiguchi <naoya.horiguchi@xxxxxxx> Cc: Oscar Salvador <osalvador@xxxxxxx> Cc: Roman Gushchin <guro@xxxxxx> Cc: Stephen Hemminger <sthemmin@xxxxxxxxxxxxx> Cc: Steven Price <steven.price@xxxxxxx> Cc: Wei Liu <wei.liu@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- fs/proc/kcore.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) --- a/fs/proc/kcore.c~fs-proc-kcore-pfn_is_ram-check-only-applies-to-kcore_ram +++ a/fs/proc/kcore.c @@ -483,25 +483,36 @@ read_kcore(struct file *file, char __use goto out; } m = NULL; /* skip the list anchor */ - } else if (!pfn_is_ram(__pa(start) >> PAGE_SHIFT)) { - if (clear_user(buffer, tsz)) { - ret = -EFAULT; - goto out; - } - } else if (m->type == KCORE_VMALLOC) { + goto skip; + } + + switch (m->type) { + case KCORE_VMALLOC: vread(buf, (char *)start, tsz); /* we have to zero-fill user buffer even if no read */ if (copy_to_user(buffer, buf, tsz)) { ret = -EFAULT; goto out; } - } else if (m->type == KCORE_USER) { + break; + case KCORE_USER: /* User page is handled prior to normal kernel page: */ if (copy_to_user(buffer, (char *)start, tsz)) { ret = -EFAULT; goto out; } - } else { + break; + case KCORE_RAM: + if (!pfn_is_ram(__pa(start) >> PAGE_SHIFT)) { + if (clear_user(buffer, tsz)) { + ret = -EFAULT; + goto out; + } + break; + } + fallthrough; + case KCORE_VMEMMAP: + case KCORE_TEXT: if (kern_addr_valid(start)) { /* * Using bounce buffer to bypass the @@ -525,7 +536,15 @@ read_kcore(struct file *file, char __use goto out; } } + break; + default: + pr_warn_once("Unhandled KCORE type: %d\n", m->type); + if (clear_user(buffer, tsz)) { + ret = -EFAULT; + goto out; + } } +skip: buflen -= tsz; *fpos += tsz; buffer += tsz; _ Patches currently in -mm which might be from david@xxxxxxxxxx are perf-map_executable-does-not-indicate-vm_mayexec.patch binfmt-remove-in-tree-usage-of-map_executable.patch mm-ignore-map_executable-in-ksys_mmap_pgoff.patch fs-proc-kcore-drop-kcore_remap-and-kcore_other.patch fs-proc-kcore-pfn_is_ram-check-only-applies-to-kcore_ram.patch fs-proc-kcore-dont-read-offline-sections-logically-offline-pages-and-hwpoisoned-pages.patch mm-introduce-page_offline_beginendfreezethaw-to-synchronize-setting-pageoffline.patch virtio-mem-use-page_offline_startend-when-setting-pageoffline.patch fs-proc-kcore-use-page_offline_freezethaw.patch mm-make-variable-names-for-populate_vma_page_range-consistent.patch mm-madvise-introduce-madv_populate_readwrite-to-prefault-page-tables.patch maintainers-add-tools-testing-selftests-vm-to-memory-management.patch selftests-vm-add-protection_keys_32-protection_keys_64-to-gitignore.patch selftests-vm-add-test-for-madv_populate_readwrite.patch memory-hotplugrst-complete-admin-guide-overhaul.patch