提交 495e6e31 编写于 作者: J Joe Perches 提交者: Yongqiang Liu

mm: and drivers core: Convert hugetlb_report_node_meminfo to sysfs_emit

mainline inclusion
from mainline-v5.10-rc1
commit 7981593b
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/I5C32F
CVE: CVE-2022-20166

--------------------------------------------------

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: NJoe Perches <joe@perches.com>
Acked-by: NMike Kravetz <mike.kravetz@oracle.com>
Link: https://lore.kernel.org/r/894b351b82da6013cde7f36ff4b5493cd0ec30d0.1600285923.git.joe@perches.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>

Conflicts:
	drivers/base/node.c
	include/linux/hugetlb.h
Signed-off-by: NGuo Mengqi <guomengqi3@huawei.com>
Reviewed-by: NWeilong Chen <chenweilong@huawei.com>
Reviewed-by: NXiu Jianfeng <xiujianfeng@huawei.com>
Signed-off-by: NYongqiang Liu <liuyongqiang13@huawei.com>
上级 10ac5402
...@@ -453,7 +453,7 @@ static ssize_t node_read_meminfo(struct device *dev, ...@@ -453,7 +453,7 @@ static ssize_t node_read_meminfo(struct device *dev,
#else #else
nid, K(node_page_state(pgdat, NR_SLAB_UNRECLAIMABLE))); nid, K(node_page_state(pgdat, NR_SLAB_UNRECLAIMABLE)));
#endif #endif
len += hugetlb_report_node_meminfo(nid, buf + len); len += hugetlb_report_node_meminfo(buf, len, nid);
return len; return len;
} }
......
...@@ -102,7 +102,7 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma, ...@@ -102,7 +102,7 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
unsigned long start, unsigned long end, unsigned long start, unsigned long end,
struct page *ref_page); struct page *ref_page);
void hugetlb_report_meminfo(struct seq_file *); 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); void hugetlb_show_meminfo(void);
unsigned long hugetlb_total_pages(void); unsigned long hugetlb_total_pages(void);
vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
...@@ -188,7 +188,7 @@ static inline void adjust_range_if_pmd_sharing_possible( ...@@ -188,7 +188,7 @@ static inline void adjust_range_if_pmd_sharing_possible(
static inline void hugetlb_report_meminfo(struct seq_file *m) static inline void hugetlb_report_meminfo(struct seq_file *m)
{ {
} }
#define hugetlb_report_node_meminfo(n, buf) 0 #define hugetlb_report_node_meminfo(buf, len, nid) 0
static inline void hugetlb_show_meminfo(void) static inline void hugetlb_show_meminfo(void)
{ {
} }
......
...@@ -3417,18 +3417,20 @@ void hugetlb_report_meminfo(struct seq_file *m) ...@@ -3417,18 +3417,20 @@ void hugetlb_report_meminfo(struct seq_file *m)
seq_printf(m, "Hugetlb: %8lu kB\n", total / 1024); 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; struct hstate *h = &default_hstate;
if (!hugepages_supported()) if (!hugepages_supported())
return 0; return 0;
return sprintf(buf,
"Node %d HugePages_Total: %5u\n" return sysfs_emit_at(buf, len,
"Node %d HugePages_Free: %5u\n" "Node %d HugePages_Total: %5u\n"
"Node %d HugePages_Surp: %5u\n", "Node %d HugePages_Free: %5u\n"
nid, h->nr_huge_pages_node[nid], "Node %d HugePages_Surp: %5u\n",
nid, h->free_huge_pages_node[nid], nid, h->nr_huge_pages_node[nid],
nid, h->surplus_huge_pages_node[nid]); nid, h->free_huge_pages_node[nid],
nid, h->surplus_huge_pages_node[nid]);
} }
void hugetlb_show_meminfo(void) void hugetlb_show_meminfo(void)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册