Skip to contentSkip to conversation

Fix misplaced kfree from xlated_setup_gnttab_pages

PATCH Dave Jones 2 participants 3 messages Jan 24, 2014 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Dave Jones

author
#1 lore raw

Passing a freed 'pages' to free_xenballooned_pages will end badly on kernels with slub debug enabled.

This looks out of place between the rc assign and the check, and was likely a cut-and-paste error.

arch/x86/xen/grant-table.c +1 -2
index 103c93f874b2..28990cc97304 100644
@@ -161,12 +161,11 @@ static int __init xlated_setup_gnttab_pages(void)
 
 	rc = arch_gnttab_map_shared(pfns, nr_grant_frames, nr_grant_frames,
 				    &xen_auto_xlat_grant_frames.vaddr);
-
-	kfree(pages);
 	if (rc) {
 		pr_warn("%s Couldn't map %ld pfns rc:%d\n", __func__,
 			nr_grant_frames, rc);
 		free_xenballooned_pages(nr_grant_frames, pages);
+		kfree(pages);
 		kfree(pfns);
 		return rc;
 	}
#2 lore raw
Quoted 2 lines · Dave Jones

Passing a freed 'pages' to free_xenballooned_pages will end badly on kernels with slub debug enabled.

Ouch.

Quoted 14 lines

This looks out of place between the rc assign and the check, and was likely a cut-and-paste error.

arch/x86/xen/grant-table.c +0 -0
index 103c93f874b2..28990cc97304 100644
@@ -161,12 +161,11 @@ static int __init xlated_setup_gnttab_pages(void)
 
 	rc = arch_gnttab_map_shared(pfns, nr_grant_frames, nr_grant_frames,
 				    &xen_auto_xlat_grant_frames.vaddr);

arch/x86/xen/grant-table.c static int __init xlated_setup_gnttab_pages(void) · line 171

Quoted 10 lines
arch/x86/xen/grant-table.c +1 -2
-
-	kfree(pages);
 	if (rc) {
 		pr_warn("%s Couldn't map %ld pfns rc:%d\n", __func__,
 			nr_grant_frames, rc);
 		free_xenballooned_pages(nr_grant_frames, pages);
+		kfree(pages);
 		kfree(pfns);
 		return rc;
 	}

Actually it should also be freed on the success path, as so:

I can squash it in, if you are OK with that?

arch/x86/xen/grant-table.c +2 -1
index 103c93f..c985835 100644
@@ -162,14 +162,15 @@ static int __init xlated_setup_gnttab_pages(void)
 	rc = arch_gnttab_map_shared(pfns, nr_grant_frames, nr_grant_frames,
 				    &xen_auto_xlat_grant_frames.vaddr);
 
-	kfree(pages);
 	if (rc) {
 		pr_warn("%s Couldn't map %ld pfns rc:%d\n", __func__,
 			nr_grant_frames, rc);
 		free_xenballooned_pages(nr_grant_frames, pages);
+		kfree(pages);
 		kfree(pfns);
 		return rc;
 	}
+	kfree(pages);
 
 	xen_auto_xlat_grant_frames.pfn = pfns;
 	xen_auto_xlat_grant_frames.count = nr_grant_frames;
author
#3 lore raw
Quoted 3 lines · Konrad Rzeszutek Wilk

Actually it should also be freed on the success path, as so:

I can squash it in, if you are OK with that?

Looks good to me.

thanks,

Dave

Quoted 21 lines
arch/x86/xen/grant-table.c +2 -1
index 103c93f..c985835 100644
@@ -162,14 +162,15 @@ static int __init xlated_setup_gnttab_pages(void)
 	rc = arch_gnttab_map_shared(pfns, nr_grant_frames, nr_grant_frames,
 				    &xen_auto_xlat_grant_frames.vaddr);
 
-	kfree(pages);
 	if (rc) {
 		pr_warn("%s Couldn't map %ld pfns rc:%d\n", __func__,
 			nr_grant_frames, rc);
 		free_xenballooned_pages(nr_grant_frames, pages);
+		kfree(pages);
 		kfree(pfns);
 		return rc;
 	}
+	kfree(pages);
 
 	xen_auto_xlat_grant_frames.pfn = pfns;
 	xen_auto_xlat_grant_frames.count = nr_grant_frames;