Re: [PATCH v1 2/7] fs/proc/kcore: pfn_is_ram check only applies to KCORE_RAM

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>

Reviewed-by: Mike Rapoport <rppt@xxxxxxxxxxxxx>

> ---
>  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
> 

-- 
Sincerely yours,
Mike.




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux