lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YI5HOad9T+752CBg@kernel.org>
Date:   Sun, 2 May 2021 09:31:21 +0300
From:   Mike Rapoport <rppt@...nel.org>
To:     David Hildenbrand <david@...hat.com>
Cc:     linux-kernel@...r.kernel.org,
        Andrew Morton <akpm@...ux-foundation.org>,
        "Michael S. Tsirkin" <mst@...hat.com>,
        Jason Wang <jasowang@...hat.com>,
        Alexey Dobriyan <adobriyan@...il.com>,
        "Matthew Wilcox (Oracle)" <willy@...radead.org>,
        Oscar Salvador <osalvador@...e.de>,
        Michal Hocko <mhocko@...e.com>, Roman Gushchin <guro@...com>,
        Alex Shi <alex.shi@...ux.alibaba.com>,
        Steven Price <steven.price@....com>,
        Mike Kravetz <mike.kravetz@...cle.com>,
        Aili Yao <yaoaili@...gsoft.com>, Jiri Bohac <jbohac@...e.cz>,
        "K. Y. Srinivasan" <kys@...rosoft.com>,
        Haiyang Zhang <haiyangz@...rosoft.com>,
        Stephen Hemminger <sthemmin@...rosoft.com>,
        Wei Liu <wei.liu@...nel.org>,
        Naoya Horiguchi <naoya.horiguchi@....com>,
        linux-hyperv@...r.kernel.org,
        virtualization@...ts.linux-foundation.org,
        linux-fsdevel@...r.kernel.org, linux-mm@...ck.org
Subject: Re: [PATCH v1 2/7] fs/proc/kcore: pfn_is_ram check only applies to
 KCORE_RAM

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@...hat.com>

Reviewed-by: Mike Rapoport <rppt@...ux.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
> 

-- 
Sincerely yours,
Mike.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ