Skip to contentSkip to conversation

selftests/mm/ksm_functional: prevent unmapping undefined address

PATCH Applied JP Kobryn 2 participants 2 messages Jan 5, 2024 – Jan 7, 2024

Subsystems (3)
lore
Share & tools
lore

JP Kobryn

author
#0 lore raw

PATCH 1/1 selftests/mm/ksm_functional: prevent unmapping undefined address

Replace some goto statements with return statements so that unmap() is not called on an undefined address. This change is made so that unmap() can only be reached after mmap() is called (and the address mentioned is defined). Returning MAP_FAILED seems acceptable since client code checks for this value.

Fixes 42096aa24b82 ("selftest/mm: ksm_functional_tests: test in mmap_and_merge_range() if anything got merged")
---
 tools/testing/selftests/mm/ksm_functional_tests.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/mm/ksm_functional_tests.c +2 -2
index fbff0dd09191..d615767e396b 100644
@@ -155,12 +155,12 @@ static char *mmap_and_merge_range(char val, unsigned long size, int prot,
 	/* Stabilize accounting by disabling KSM completely. */
 	if (ksm_unmerge()) {
 		ksft_test_result_fail("Disabling (unmerging) KSM failed\n");
-		goto unmap;
+		return MAP_FAILED;
 	}
 
 	if (get_my_merging_pages() > 0) {
 		ksft_test_result_fail("Still pages merged\n");
-		goto unmap;
+		return MAP_FAILED;
 	}
 
 	map = mmap(NULL, size, PROT_READ|PROT_WRITE,
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 21 lines · JP Kobryn

Replace some goto statements with return statements so that unmap() is not called on an undefined address. This change is made so that unmap() can only be reached after mmap() is called (and the address mentioned is defined). Returning MAP_FAILED seems acceptable since client code checks for this value.

Fixes 42096aa24b82 ("selftest/mm: ksm_functional_tests: test in mmap_and_merge_range() if anything got merged")
---
  tools/testing/selftests/mm/ksm_functional_tests.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/mm/ksm_functional_tests.c +0 -1
index fbff0dd09191..d615767e396b 100644
@@ -155,12 +155,12 @@ static char *mmap_and_merge_range(char val, unsigned long size, int prot,
  	/* Stabilize accounting by disabling KSM completely. */
  	if (ksm_unmerge()) {
  		ksft_test_result_fail("Disabling (unmerging) KSM failed\n");
-		goto unmap;

tools/testing/selftests/mm/ksm_functional_tests.c static char *mmap_and_merge_range(char val, unsigned long size, int prot, · line 166

Quoted 10 lines
tools/testing/selftests/mm/ksm_functional_tests.c +2 -1
+		return MAP_FAILED;
  	}
 
  	if (get_my_merging_pages() > 0) {
  		ksft_test_result_fail("Still pages merged\n");
-		goto unmap;
+		return MAP_FAILED;
  	}
 
  	map = mmap(NULL, size, PROT_READ|PROT_WRITE,

Indeed, thanks.

Signature · 3 lines
Cheers,

David / dhildenb