page-read: fix open_page_read usage

Submitted by Pavel Tikhomirov on June 25, 2016, 8:26 a.m.

Details

Message ID 1466843195-5699-1-git-send-email-ptikhomirov@virtuozzo.com
State Rejected
Series "page-read: fix open_page_read usage"
Headers show

Commit Message

Pavel Tikhomirov June 25, 2016, 8:26 a.m.
1. Fix uninitialized use of pr in cr_dedup_one_pagemap and get_page:
https://github.com/xemul/criu/issues/178
2. If open_page_read ret is >0 pr.close is initialized so there is no
point to test it before use
3. In find_vmas fix pr leak in case of error returned from
collect_uffd_pages

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
---
 criu/cr-dedup.c |  6 ++----
 criu/uffd.c     | 15 +++++++--------
 2 files changed, 9 insertions(+), 12 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/cr-dedup.c b/criu/cr-dedup.c
index 538f650..ca5a930 100644
--- a/criu/cr-dedup.c
+++ b/criu/cr-dedup.c
@@ -66,10 +66,8 @@  static int cr_dedup_one_pagemap(int pid)
 	struct iovec iov;
 
 	ret = open_page_read(pid, &pr, PR_TASK | PR_MOD);
-	if (ret <= 0) {
-		ret = -1;
-		goto exit;
-	}
+	if (ret <= 0)
+		return -1;
 
 	prp = pr.parent;
 	if (!prp)
diff --git a/criu/uffd.c b/criu/uffd.c
index a920ae7..10cc4f2 100644
--- a/criu/uffd.c
+++ b/criu/uffd.c
@@ -333,6 +333,8 @@  static int get_page(struct lazy_pages_info *lpi, unsigned long addr, void *dest)
 
 	ret = open_page_read(lpi->pid, &pr, PR_TASK | PR_MOD);
 	pr_debug("get_page ret %d\n", ret);
+	if (ret <= 0)
+		return ret;
 
 	ret = pr.get_pagemap(&pr, &iov);
 	pr_debug("get_pagemap ret %d\n", ret);
@@ -351,8 +353,7 @@  static int get_page(struct lazy_pages_info *lpi, unsigned long addr, void *dest)
 
 	memcpy(dest, buf, PAGE_SIZE);
 
-	if (pr.close)
-		pr.close(&pr);
+	pr.close(&pr);
 
 	return 1;
 }
@@ -619,20 +620,18 @@  static int find_vmas(struct lazy_pages_info *lpi)
 	 */
 	do {
 		ret = collect_uffd_pages(&pr, lpi);
-		if (ret == -1) {
-			goto out;
-		}
+		if (ret == -1)
+			goto close;
 	} while (ret);
 
-	if (pr.close)
-		pr.close(&pr);
-
 	/* Count detected pages */
 	list_for_each_entry(uffd_pages, &lpi->pages, list)
 	    ret++;
 
 	pr_debug("Found %d pages to be handled by UFFD\n", ret);
 
+close:
+	pr.close(&pr);
 out:
 	return ret;
 }

Comments

Cyrill Gorcunov June 27, 2016, 7:19 p.m.
On Sat, Jun 25, 2016 at 11:26:35AM +0300, Pavel Tikhomirov wrote:
> 1. Fix uninitialized use of pr in cr_dedup_one_pagemap and get_page:
> https://github.com/xemul/criu/issues/178
> 2. If open_page_read ret is >0 pr.close is initialized so there is no
> point to test it before use
> 3. In find_vmas fix pr leak in case of error returned from
> collect_uffd_pages
> 
> Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Reviewed-by: Cyrill Gorcunov <gorcunov@openvz.org>
Pavel Emelianov June 28, 2016, 1:09 p.m.
Would you rebase this patch onto recent criu-dev, please.