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: <20200919062228.GA438957@kroah.com>
Date:   Sat, 19 Sep 2020 08:22:28 +0200
From:   Greg Kroah-Hartman <gregkh@...uxfoundation.org>
To:     Joe Perches <joe@...ches.com>
Cc:     "Rafael J . Wysocki" <rafael@...nel.org>,
        Mike Kravetz <mike.kravetz@...cle.com>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Denis Efremov <efremov@...ux.com>,
        Julia Lawall <julia.lawall@...ia.fr>,
        Alex Dewar <alex.dewar90@...il.com>,
        linux-kernel@...r.kernel.org, linux-mm@...ck.org
Subject: Re: [PATCH V3 6/8] mm: and drivers core: Convert
 hugetlb_report_node_meminfo to sysfs_emit

On Wed, Sep 16, 2020 at 01:40:43PM -0700, Joe Perches wrote:
> Convert the unbound sprintf in hugetlb_report_node_meminfo to use
> sysfs_emit_at so that no possible overrun of a PAGE_SIZE buf can occur.
> 
> Signed-off-by: Joe Perches <joe@...ches.com>
> ---
>  drivers/base/node.c     |  2 +-
>  include/linux/hugetlb.h |  4 ++--
>  mm/hugetlb.c            | 18 ++++++++++--------
>  3 files changed, 13 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/base/node.c b/drivers/base/node.c
> index b33526a9fcfc..dafe03e82e7c 100644
> --- a/drivers/base/node.c
> +++ b/drivers/base/node.c
> @@ -473,7 +473,7 @@ static ssize_t node_read_meminfo(struct device *dev,
>  				    HPAGE_PMD_NR)
>  #endif
>  			    );
> -	len += hugetlb_report_node_meminfo(nid, buf + len);
> +	len += hugetlb_report_node_meminfo(buf, len, nid);
>  	return len;
>  }
>  
> diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
> index d5cc5f802dd4..ebca2ef02212 100644
> --- a/include/linux/hugetlb.h
> +++ b/include/linux/hugetlb.h
> @@ -129,7 +129,7 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
>  				unsigned long start, unsigned long end,
>  				struct page *ref_page);
>  void hugetlb_report_meminfo(struct seq_file *);
> -int hugetlb_report_node_meminfo(int, char *);
> +int hugetlb_report_node_meminfo(char *buf, int len, int nid);
>  void hugetlb_show_meminfo(void);
>  unsigned long hugetlb_total_pages(void);
>  vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
> @@ -245,7 +245,7 @@ static inline void hugetlb_report_meminfo(struct seq_file *m)
>  {
>  }
>  
> -static inline int hugetlb_report_node_meminfo(int nid, char *buf)
> +static inline int hugetlb_report_node_meminfo(char *buf, int len, int nid)
>  {
>  	return 0;
>  }
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 61469fd3ad92..fe76f8fd5a73 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -3571,18 +3571,20 @@ void hugetlb_report_meminfo(struct seq_file *m)
>  	seq_printf(m, "Hugetlb:        %8lu kB\n", total / 1024);
>  }
>  
> -int hugetlb_report_node_meminfo(int nid, char *buf)
> +int hugetlb_report_node_meminfo(char *buf, int len, int nid)
>  {
>  	struct hstate *h = &default_hstate;
> +
>  	if (!hugepages_supported())
>  		return 0;
> -	return sprintf(buf,
> -		"Node %d HugePages_Total: %5u\n"
> -		"Node %d HugePages_Free:  %5u\n"
> -		"Node %d HugePages_Surp:  %5u\n",
> -		nid, h->nr_huge_pages_node[nid],
> -		nid, h->free_huge_pages_node[nid],
> -		nid, h->surplus_huge_pages_node[nid]);
> +
> +	return sysfs_emit_at(buf, len,
> +			     "Node %d HugePages_Total: %5u\n"
> +			     "Node %d HugePages_Free:  %5u\n"
> +			     "Node %d HugePages_Surp:  %5u\n",
> +			     nid, h->nr_huge_pages_node[nid],
> +			     nid, h->free_huge_pages_node[nid],
> +			     nid, h->surplus_huge_pages_node[nid]);
>  }

That is NOT one-value-per-file, which is required for sysfs files.  This
should be 3 different sysfs files.

Ugh.

But that's separate from this series, thanks for redoing this.  I'll
take a look at it on Monday...

thanks,

greg k-h

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ