Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

lib/test_min_heap: use inline min heap variants to reduce attack vector

To address concerns about increasing the attack vector, remove the select
MIN_HEAP dependency from TEST_MIN_HEAP in Kconfig.debug.

Additionally, all min heap test function calls in lib/test_min_heap.c are
replaced with their inline variants. By exclusively using inline
variants, we eliminate the need to enable CONFIG_MIN_HEAP for testing
purposes.

Link: https://lore.kernel.org/lkml/CAMuHMdVO5DPuD9HYWBFqKDHphx7+0BEhreUxtVC40A=8p6VAhQ@mail.gmail.com
Link: https://lkml.kernel.org/r/20241129181222.646855-3-visitorckw@gmail.com
Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Suggested-by: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Ching-Chun (Jim) Huang <jserv@ccns.ncku.edu.tw>
Cc: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Kuan-Wei Chiu and committed by
Andrew Morton
93aa1b5c ec01e9d0

+15 -16
-1
lib/Kconfig.debug
··· 2269 2269 config TEST_MIN_HEAP 2270 2270 tristate "Min heap test" 2271 2271 depends on DEBUG_KERNEL || m 2272 - select MIN_HEAP 2273 2272 help 2274 2273 Enable this to turn on min heap function tests. This test is 2275 2274 executed only once during system boot (so affects only boot time),
+15 -15
lib/test_min_heap.c
··· 32 32 int last; 33 33 34 34 last = values[0]; 35 - min_heap_pop(heap, funcs, NULL); 35 + min_heap_pop_inline(heap, funcs, NULL); 36 36 while (heap->nr > 0) { 37 37 if (min_heap) { 38 38 if (last > values[0]) { ··· 48 48 } 49 49 } 50 50 last = values[0]; 51 - min_heap_pop(heap, funcs, NULL); 51 + min_heap_pop_inline(heap, funcs, NULL); 52 52 } 53 53 return err; 54 54 } ··· 69 69 int i, err; 70 70 71 71 /* Test with known set of values. */ 72 - min_heapify_all(&heap, &funcs, NULL); 72 + min_heapify_all_inline(&heap, &funcs, NULL); 73 73 err = pop_verify_heap(min_heap, &heap, &funcs); 74 74 75 75 ··· 78 78 for (i = 0; i < heap.nr; i++) 79 79 values[i] = get_random_u32(); 80 80 81 - min_heapify_all(&heap, &funcs, NULL); 81 + min_heapify_all_inline(&heap, &funcs, NULL); 82 82 err += pop_verify_heap(min_heap, &heap, &funcs); 83 83 84 84 return err; ··· 102 102 103 103 /* Test with known set of values copied from data. */ 104 104 for (i = 0; i < ARRAY_SIZE(data); i++) 105 - min_heap_push(&heap, &data[i], &funcs, NULL); 105 + min_heap_push_inline(&heap, &data[i], &funcs, NULL); 106 106 107 107 err = pop_verify_heap(min_heap, &heap, &funcs); 108 108 109 109 /* Test with randomly generated values. */ 110 110 while (heap.nr < heap.size) { 111 111 temp = get_random_u32(); 112 - min_heap_push(&heap, &temp, &funcs, NULL); 112 + min_heap_push_inline(&heap, &temp, &funcs, NULL); 113 113 } 114 114 err += pop_verify_heap(min_heap, &heap, &funcs); 115 115 ··· 135 135 /* Fill values with data to pop and replace. */ 136 136 temp = min_heap ? 0x80000000 : 0x7FFFFFFF; 137 137 for (i = 0; i < ARRAY_SIZE(data); i++) 138 - min_heap_push(&heap, &temp, &funcs, NULL); 138 + min_heap_push_inline(&heap, &temp, &funcs, NULL); 139 139 140 140 /* Test with known set of values copied from data. */ 141 141 for (i = 0; i < ARRAY_SIZE(data); i++) 142 - min_heap_pop_push(&heap, &data[i], &funcs, NULL); 142 + min_heap_pop_push_inline(&heap, &data[i], &funcs, NULL); 143 143 144 144 err = pop_verify_heap(min_heap, &heap, &funcs); 145 145 146 146 heap.nr = 0; 147 147 for (i = 0; i < ARRAY_SIZE(data); i++) 148 - min_heap_push(&heap, &temp, &funcs, NULL); 148 + min_heap_push_inline(&heap, &temp, &funcs, NULL); 149 149 150 150 /* Test with randomly generated values. */ 151 151 for (i = 0; i < ARRAY_SIZE(data); i++) { 152 152 temp = get_random_u32(); 153 - min_heap_pop_push(&heap, &temp, &funcs, NULL); 153 + min_heap_pop_push_inline(&heap, &temp, &funcs, NULL); 154 154 } 155 155 err += pop_verify_heap(min_heap, &heap, &funcs); 156 156 ··· 163 163 -3, -1, -2, -4, 0x8000000, 0x7FFFFFF }; 164 164 struct min_heap_test heap; 165 165 166 - min_heap_init(&heap, values, ARRAY_SIZE(values)); 166 + min_heap_init_inline(&heap, values, ARRAY_SIZE(values)); 167 167 heap.nr = ARRAY_SIZE(values); 168 168 struct min_heap_callbacks funcs = { 169 169 .less = min_heap ? less_than : greater_than, ··· 172 172 int i, err; 173 173 174 174 /* Test with known set of values. */ 175 - min_heapify_all(&heap, &funcs, NULL); 175 + min_heapify_all_inline(&heap, &funcs, NULL); 176 176 for (i = 0; i < ARRAY_SIZE(values) / 2; i++) 177 - min_heap_del(&heap, get_random_u32() % heap.nr, &funcs, NULL); 177 + min_heap_del_inline(&heap, get_random_u32() % heap.nr, &funcs, NULL); 178 178 err = pop_verify_heap(min_heap, &heap, &funcs); 179 179 180 180 ··· 182 182 heap.nr = ARRAY_SIZE(values); 183 183 for (i = 0; i < heap.nr; i++) 184 184 values[i] = get_random_u32(); 185 - min_heapify_all(&heap, &funcs, NULL); 185 + min_heapify_all_inline(&heap, &funcs, NULL); 186 186 187 187 for (i = 0; i < ARRAY_SIZE(values) / 2; i++) 188 - min_heap_del(&heap, get_random_u32() % heap.nr, &funcs, NULL); 188 + min_heap_del_inline(&heap, get_random_u32() % heap.nr, &funcs, NULL); 189 189 err += pop_verify_heap(min_heap, &heap, &funcs); 190 190 191 191 return err;