Commit de98c7af authored by chenrenhui's avatar chenrenhui
Browse files

etmem : fix page_ref count leak and head missing useing problem

euleros inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IAXJCE


CVE: NA

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

In the etmem swap process, use get_page_from_vaddr to obtain
the page and add the page reference counting.

If a page does not meet the recycling criteria,
release the reference counting of the page.

In the add_page_for_swap process, if the input page is the
middle page of a compound page, head and page cannot be
used together.

Instead, head must be used as the input parameter.

Fixes: 8a655676 ("memig: add memig-swap feature to openEuler")
Signed-off-by: default avatarchenrenhui <chenrenhui1@huawei.com>
parent b61a367a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -70,6 +70,8 @@ static ssize_t swap_pages_write(struct file *file, const char __user *buf,
			continue;

		add_page_for_swap(page, &pagelist);
		/* release the ref count we get from the get_page_from_vaddr interface */
		put_page(page);
	}

	if (!list_empty(&pagelist))
+6 −11
Original line number Diff line number Diff line
@@ -4623,7 +4623,6 @@ EXPORT_SYMBOL_GPL(check_move_unevictable_pages);
#ifdef CONFIG_ETMEM
int add_page_for_swap(struct page *page, struct list_head *pagelist)
{
	int err = -EBUSY;
	struct page *head;

	/* If the page is mapped by more than one process, do not swap it */
@@ -4634,19 +4633,15 @@ int add_page_for_swap(struct page *page, struct list_head *pagelist)
		return -EACCES;

	head = compound_head(page);
	err = isolate_lru_page(head);
	if (err) {
		put_page(page);
		return err;
	}
	put_page(page);
	if (PageUnevictable(page))
		putback_lru_page(page);
	if (isolate_lru_page(head))
		return -EBUSY;

	if (PageUnevictable(head))
		putback_lru_page(head);
	else
		list_add_tail(&head->lru, pagelist);

	err = 0;
	return err;
	return 0;
}
EXPORT_SYMBOL_GPL(add_page_for_swap);