[CRIU] [PATCH] kdat: lazy-thp: split error paths cleanups to two cases

Mike Rapoport rppt at linux.vnet.ibm.com
Mon Aug 14 11:47:06 MSK 2017


When an error occurs we need to close a file descriptor and unmap a region.
Use a separate label for each cleanup.

Fix CID 182644 (#1-2 of 2): Use after close (USE_AFTER_FREE)8. pass_closed_arg:
Passing closed handle f.fd as an argument to bclose

Signed-off-by: Mike Rapoport <rppt at linux.vnet.ibm.com>
---
 criu/kerndat.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/criu/kerndat.c b/criu/kerndat.c
index e107883..80977a3 100644
--- a/criu/kerndat.c
+++ b/criu/kerndat.c
@@ -965,21 +965,21 @@ int kerndat_has_thp_disable(void)
 	f.fd = open("/proc/self/smaps", O_RDONLY);
 	if (f.fd < 0) {
 		pr_perror("Can't open /proc/self/smaps");
-		goto out;
+		goto out_unmap;
 	}
 	if (bfdopenr(&f))
-		goto out;
+		goto out_unmap;
 
 	while ((str = breadline(&f)) != NULL) {
 		if (IS_ERR(str))
-			goto out;
+			goto out_close;
 
 		if (is_vma_range_fmt(str)) {
 			unsigned long vma_addr;
 
 			if (sscanf(str, "%lx-", &vma_addr) != 1) {
 				pr_err("Can't parse: %s\n", str);
-				goto out;
+				goto out_close;
 			}
 
 			if (vma_addr == (unsigned long)addr)
@@ -999,8 +999,9 @@ int kerndat_has_thp_disable(void)
 
 	ret = 0;
 
-out:
+out_close:
 	bclose(&f);
+out_unmap:
 	munmap(addr, PAGE_SIZE);
 
 	return ret;
-- 
2.7.4



More information about the CRIU mailing list