]> git.baikalelectronics.ru Git - kernel.git/commitdiff
fs/proc/kcore: pfn_is_ram check only applies to KCORE_RAM
authorDavid Hildenbrand <david@redhat.com>
Thu, 1 Jul 2021 01:50:07 +0000 (18:50 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 1 Jul 2021 03:47:28 +0000 (20:47 -0700)
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@redhat.com
Signed-off-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Mike Rapoport <rppt@linux.ibm.com>
Cc: Aili Yao <yaoaili@kingsoft.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Alex Shi <alex.shi@linux.alibaba.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Cc: Jason Wang <jasowang@redhat.com>
Cc: Jiri Bohac <jbohac@suse.cz>
Cc: "K. Y. Srinivasan" <kys@microsoft.com>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Naoya Horiguchi <naoya.horiguchi@nec.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Roman Gushchin <guro@fb.com>
Cc: Stephen Hemminger <sthemmin@microsoft.com>
Cc: Steven Price <steven.price@arm.com>
Cc: Wei Liu <wei.liu@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/proc/kcore.c

index 09f77d3c6e159d330d577d639aac38c965dbd3a9..ed6fbb3bd50cae09c29106b3127261a5fb4e202e 100644 (file)
@@ -483,25 +483,36 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
                                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 __user *buffer, size_t buflen, loff_t *fpos)
                                        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;