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@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>
This commit is contained in:
Родитель
3c36b419b1
Коммит
2711032c64
|
@ -483,25 +483,36 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
m = NULL; /* skip the list anchor */
|
m = NULL; /* skip the list anchor */
|
||||||
} else if (!pfn_is_ram(__pa(start) >> PAGE_SHIFT)) {
|
goto skip;
|
||||||
if (clear_user(buffer, tsz)) {
|
}
|
||||||
ret = -EFAULT;
|
|
||||||
goto out;
|
switch (m->type) {
|
||||||
}
|
case KCORE_VMALLOC:
|
||||||
} else if (m->type == KCORE_VMALLOC) {
|
|
||||||
vread(buf, (char *)start, tsz);
|
vread(buf, (char *)start, tsz);
|
||||||
/* we have to zero-fill user buffer even if no read */
|
/* we have to zero-fill user buffer even if no read */
|
||||||
if (copy_to_user(buffer, buf, tsz)) {
|
if (copy_to_user(buffer, buf, tsz)) {
|
||||||
ret = -EFAULT;
|
ret = -EFAULT;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
} else if (m->type == KCORE_USER) {
|
break;
|
||||||
|
case KCORE_USER:
|
||||||
/* User page is handled prior to normal kernel page: */
|
/* User page is handled prior to normal kernel page: */
|
||||||
if (copy_to_user(buffer, (char *)start, tsz)) {
|
if (copy_to_user(buffer, (char *)start, tsz)) {
|
||||||
ret = -EFAULT;
|
ret = -EFAULT;
|
||||||
goto out;
|
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)) {
|
if (kern_addr_valid(start)) {
|
||||||
/*
|
/*
|
||||||
* Using bounce buffer to bypass the
|
* 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;
|
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;
|
buflen -= tsz;
|
||||||
*fpos += tsz;
|
*fpos += tsz;
|
||||||
buffer += tsz;
|
buffer += tsz;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче