etmem : fix page_ref count leak and head missing useing problem
chenrenhui (1): etmem : fix page_ref count leak and head missing useing problem
fs/proc/etmem_swap.c | 2 ++ mm/vmscan.c | 17 ++++++----------- 2 files changed, 8 insertions(+), 11 deletions(-)
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: 8a655676e636 ("memig: add memig-swap feature to openEuler") Signed-off-by: chenrenhui chenrenhui1@huawei.com --- fs/proc/etmem_swap.c | 2 ++ mm/vmscan.c | 17 ++++++----------- 2 files changed, 8 insertions(+), 11 deletions(-)
diff --git a/fs/proc/etmem_swap.c b/fs/proc/etmem_swap.c index 86f5cf8c90a1..becc7f7c2fa8 100644 --- a/fs/proc/etmem_swap.c +++ b/fs/proc/etmem_swap.c @@ -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)) diff --git a/mm/vmscan.c b/mm/vmscan.c index 7cb214d44417..08213f1c18ee 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -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);
反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://gitee.com/openeuler/kernel/pulls/14060 邮件列表地址:https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/A...
FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://gitee.com/openeuler/kernel/pulls/14060 Mailing list address: https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/A...