Message ID | 20210429122519.15183-3-david@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | fs/proc/kcore: don't read offline sections, logically offline pages and hwpoisoned pages | expand |
On Thu, Apr 29, 2021 at 02:25:14PM +0200, David Hildenbrand wrote: > Let's resturcture the code, using switch-case, and checking pfn_is_ram() > only when we are dealing with KCORE_RAM. > > Signed-off-by: David Hildenbrand <david@redhat.com> Reviewed-by: Mike Rapoport <rppt@linux.ibm.com> > --- > fs/proc/kcore.c | 35 +++++++++++++++++++++++++++-------- > 1 file changed, 27 insertions(+), 8 deletions(-) > > diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c > index 09f77d3c6e15..ed6fbb3bd50c 100644 > --- a/fs/proc/kcore.c > +++ b/fs/proc/kcore.c > @@ -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; > -- > 2.30.2 >
diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c index 09f77d3c6e15..ed6fbb3bd50c 100644 --- a/fs/proc/kcore.c +++ b/fs/proc/kcore.c @@ -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;
Let's resturcture the code, using switch-case, and checking pfn_is_ram() only when we are dealing with KCORE_RAM. Signed-off-by: David Hildenbrand <david@redhat.com> --- fs/proc/kcore.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-)