blob: cacbbbdef768d056d010ebde123353192f502c50 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Andrey Ryabinin3f158012015-02-13 14:39:53 -08002/*
3 *
4 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
5 * Author: Andrey Ryabinin <a.ryabinin@samsung.com>
Andrey Ryabinin3f158012015-02-13 14:39:53 -08006 */
7
Marco Elver19a33ca2019-07-11 20:53:52 -07008#include <linux/bitops.h>
Greg Thelen0386bf32017-02-24 15:00:08 -08009#include <linux/delay.h>
Marco Elver19a33ca2019-07-11 20:53:52 -070010#include <linux/kasan.h>
Andrey Ryabinin3f158012015-02-13 14:39:53 -080011#include <linux/kernel.h>
Andrey Ryabinineae08dc2016-05-20 16:59:34 -070012#include <linux/mm.h>
Marco Elver19a33ca2019-07-11 20:53:52 -070013#include <linux/mman.h>
14#include <linux/module.h>
Andrey Ryabinin3f158012015-02-13 14:39:53 -080015#include <linux/printk.h>
Andrey Konovalov573a4802021-02-24 12:05:21 -080016#include <linux/random.h>
Andrey Ryabinin3f158012015-02-13 14:39:53 -080017#include <linux/slab.h>
18#include <linux/string.h>
Andrey Ryabinineae08dc2016-05-20 16:59:34 -070019#include <linux/uaccess.h>
Mark Rutlandb92a9532019-09-23 15:34:16 -070020#include <linux/io.h>
Daniel Axtens06513912019-11-30 17:54:53 -080021#include <linux/vmalloc.h>
Mark Rutlandb92a9532019-09-23 15:34:16 -070022
23#include <asm/page.h>
Andrey Ryabinin3f158012015-02-13 14:39:53 -080024
Patricia Alfonso83c4e7a2020-10-13 16:55:02 -070025#include <kunit/test.h>
26
Walter Wuf33a0142020-08-06 23:24:54 -070027#include "../mm/kasan/kasan.h"
28
Andrey Konovalov1f600622020-12-22 12:00:24 -080029#define OOB_TAG_OFF (IS_ENABLED(CONFIG_KASAN_GENERIC) ? 0 : KASAN_GRANULE_SIZE)
Walter Wuf33a0142020-08-06 23:24:54 -070030
Dmitry Vyukov828347f2016-11-30 15:54:16 -080031/*
Andrey Konovalov0fd37922021-02-24 12:05:13 -080032 * Some tests use these global variables to store return values from function
33 * calls that could otherwise be eliminated by the compiler as dead code.
Daniel Axtensadb72ae2020-06-03 15:56:43 -070034 */
Daniel Axtensadb72ae2020-06-03 15:56:43 -070035void *kasan_ptr_result;
Patricia Alfonso83c4e7a2020-10-13 16:55:02 -070036int kasan_int_result;
37
38static struct kunit_resource resource;
39static struct kunit_kasan_expectation fail_data;
40static bool multishot;
41
Andrey Konovalov0fd37922021-02-24 12:05:13 -080042/*
43 * Temporarily enable multi-shot mode. Otherwise, KASAN would only report the
Andrey Konovalovf05842c2021-02-24 12:05:26 -080044 * first detected bug and panic the kernel if panic_on_warn is enabled. For
45 * hardware tag-based KASAN also allow tag checking to be reenabled for each
46 * test, see the comment for KUNIT_EXPECT_KASAN_FAIL().
Andrey Konovalov0fd37922021-02-24 12:05:13 -080047 */
Patricia Alfonso83c4e7a2020-10-13 16:55:02 -070048static int kasan_test_init(struct kunit *test)
49{
Andrey Konovalovd82dc3a2021-02-24 12:06:02 -080050 if (!kasan_enabled()) {
51 kunit_err(test, "can't run KASAN tests with KASAN disabled");
52 return -1;
53 }
54
Patricia Alfonso83c4e7a2020-10-13 16:55:02 -070055 multishot = kasan_save_enable_multi_shot();
Andrey Konovalovf05842c2021-02-24 12:05:26 -080056 kasan_set_tagging_report_once(false);
Andrey Konovalov99734b52021-04-29 23:00:49 -070057 fail_data.report_found = false;
58 fail_data.report_expected = false;
59 kunit_add_named_resource(test, NULL, NULL, &resource,
60 "kasan_data", &fail_data);
Patricia Alfonso83c4e7a2020-10-13 16:55:02 -070061 return 0;
62}
63
64static void kasan_test_exit(struct kunit *test)
65{
Andrey Konovalovf05842c2021-02-24 12:05:26 -080066 kasan_set_tagging_report_once(true);
Patricia Alfonso83c4e7a2020-10-13 16:55:02 -070067 kasan_restore_multi_shot(multishot);
Andrey Konovalov99734b52021-04-29 23:00:49 -070068 KUNIT_EXPECT_FALSE(test, fail_data.report_found);
Patricia Alfonso83c4e7a2020-10-13 16:55:02 -070069}
70
71/**
Andrey Konovalov0fd37922021-02-24 12:05:13 -080072 * KUNIT_EXPECT_KASAN_FAIL() - check that the executed expression produces a
73 * KASAN report; causes a test failure otherwise. This relies on a KUnit
74 * resource named "kasan_data". Do not use this name for KUnit resources
75 * outside of KASAN tests.
Andrey Konovalovf05842c2021-02-24 12:05:26 -080076 *
Andrey Konovalove80a76a2021-03-15 13:20:19 +000077 * For hardware tag-based KASAN in sync mode, when a tag fault happens, tag
78 * checking is auto-disabled. When this happens, this test handler reenables
79 * tag checking. As tag checking can be only disabled or enabled per CPU,
80 * this handler disables migration (preemption).
Andrey Konovalov2e4bde62021-02-24 12:05:34 -080081 *
82 * Since the compiler doesn't see that the expression can change the fail_data
83 * fields, it can reorder or optimize away the accesses to those fields.
84 * Use READ/WRITE_ONCE() for the accesses and compiler barriers around the
85 * expression to prevent that.
Andrey Konovalov99734b52021-04-29 23:00:49 -070086 *
87 * In between KUNIT_EXPECT_KASAN_FAIL checks, fail_data.report_found is kept as
88 * false. This allows detecting KASAN reports that happen outside of the checks
89 * by asserting !fail_data.report_found at the start of KUNIT_EXPECT_KASAN_FAIL
90 * and in kasan_test_exit.
Patricia Alfonso83c4e7a2020-10-13 16:55:02 -070091 */
Andrey Konovalov99734b52021-04-29 23:00:49 -070092#define KUNIT_EXPECT_KASAN_FAIL(test, expression) do { \
93 if (IS_ENABLED(CONFIG_KASAN_HW_TAGS) && \
94 !kasan_async_mode_enabled()) \
95 migrate_disable(); \
96 KUNIT_EXPECT_FALSE(test, READ_ONCE(fail_data.report_found)); \
97 WRITE_ONCE(fail_data.report_expected, true); \
98 barrier(); \
99 expression; \
100 barrier(); \
101 KUNIT_EXPECT_EQ(test, \
102 READ_ONCE(fail_data.report_expected), \
103 READ_ONCE(fail_data.report_found)); \
104 if (IS_ENABLED(CONFIG_KASAN_HW_TAGS)) { \
105 if (READ_ONCE(fail_data.report_found)) \
106 kasan_enable_tagging_sync(); \
107 migrate_enable(); \
108 } \
109 WRITE_ONCE(fail_data.report_found, false); \
110 WRITE_ONCE(fail_data.report_expected, false); \
Patricia Alfonso83c4e7a2020-10-13 16:55:02 -0700111} while (0)
112
Andrey Konovalovda17e372021-02-24 12:05:17 -0800113#define KASAN_TEST_NEEDS_CONFIG_ON(test, config) do { \
114 if (!IS_ENABLED(config)) { \
115 kunit_info((test), "skipping, " #config " required"); \
116 return; \
117 } \
118} while (0)
119
120#define KASAN_TEST_NEEDS_CONFIG_OFF(test, config) do { \
121 if (IS_ENABLED(config)) { \
122 kunit_info((test), "skipping, " #config " enabled"); \
123 return; \
124 } \
125} while (0)
126
Patricia Alfonso73228c72020-10-13 16:55:06 -0700127static void kmalloc_oob_right(struct kunit *test)
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800128{
129 char *ptr;
130 size_t size = 123;
131
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800132 ptr = kmalloc(size, GFP_KERNEL);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700133 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800134
Patricia Alfonso73228c72020-10-13 16:55:06 -0700135 KUNIT_EXPECT_KASAN_FAIL(test, ptr[size + OOB_TAG_OFF] = 'x');
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800136 kfree(ptr);
137}
138
Patricia Alfonso73228c72020-10-13 16:55:06 -0700139static void kmalloc_oob_left(struct kunit *test)
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800140{
141 char *ptr;
142 size_t size = 15;
143
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800144 ptr = kmalloc(size, GFP_KERNEL);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700145 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800146
Patricia Alfonso73228c72020-10-13 16:55:06 -0700147 KUNIT_EXPECT_KASAN_FAIL(test, *ptr = *(ptr - 1));
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800148 kfree(ptr);
149}
150
Patricia Alfonso73228c72020-10-13 16:55:06 -0700151static void kmalloc_node_oob_right(struct kunit *test)
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800152{
153 char *ptr;
154 size_t size = 4096;
155
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800156 ptr = kmalloc_node(size, GFP_KERNEL, 0);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700157 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800158
Patricia Alfonso73228c72020-10-13 16:55:06 -0700159 KUNIT_EXPECT_KASAN_FAIL(test, ptr[size] = 0);
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800160 kfree(ptr);
161}
162
Andrey Konovalov858bdeb2021-02-24 12:05:55 -0800163/*
164 * These kmalloc_pagealloc_* tests try allocating a memory chunk that doesn't
165 * fit into a slab cache and therefore is allocated via the page allocator
166 * fallback. Since this kind of fallback is only implemented for SLUB, these
167 * tests are limited to that allocator.
168 */
Patricia Alfonso73228c72020-10-13 16:55:06 -0700169static void kmalloc_pagealloc_oob_right(struct kunit *test)
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800170{
171 char *ptr;
172 size_t size = KMALLOC_MAX_CACHE_SIZE + 10;
173
Andrey Konovalovda17e372021-02-24 12:05:17 -0800174 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_SLUB);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700175
Alexander Potapenkoe6e83792016-03-25 14:21:56 -0700176 ptr = kmalloc(size, GFP_KERNEL);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700177 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
Alexander Potapenkoe6e83792016-03-25 14:21:56 -0700178
Patricia Alfonso73228c72020-10-13 16:55:06 -0700179 KUNIT_EXPECT_KASAN_FAIL(test, ptr[size + OOB_TAG_OFF] = 0);
Andrey Konovalov858bdeb2021-02-24 12:05:55 -0800180
Alexander Potapenkoe6e83792016-03-25 14:21:56 -0700181 kfree(ptr);
182}
Dmitry Vyukov47adccc2018-02-06 15:36:23 -0800183
Patricia Alfonso73228c72020-10-13 16:55:06 -0700184static void kmalloc_pagealloc_uaf(struct kunit *test)
Dmitry Vyukov47adccc2018-02-06 15:36:23 -0800185{
186 char *ptr;
187 size_t size = KMALLOC_MAX_CACHE_SIZE + 10;
188
Andrey Konovalovda17e372021-02-24 12:05:17 -0800189 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_SLUB);
Dmitry Vyukov47adccc2018-02-06 15:36:23 -0800190
Patricia Alfonso73228c72020-10-13 16:55:06 -0700191 ptr = kmalloc(size, GFP_KERNEL);
192 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
Dmitry Vyukov47adccc2018-02-06 15:36:23 -0800193 kfree(ptr);
Andrey Konovalov858bdeb2021-02-24 12:05:55 -0800194
Patricia Alfonso73228c72020-10-13 16:55:06 -0700195 KUNIT_EXPECT_KASAN_FAIL(test, ptr[0] = 0);
Dmitry Vyukov47adccc2018-02-06 15:36:23 -0800196}
197
Patricia Alfonso73228c72020-10-13 16:55:06 -0700198static void kmalloc_pagealloc_invalid_free(struct kunit *test)
Dmitry Vyukov47adccc2018-02-06 15:36:23 -0800199{
200 char *ptr;
201 size_t size = KMALLOC_MAX_CACHE_SIZE + 10;
202
Andrey Konovalovda17e372021-02-24 12:05:17 -0800203 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_SLUB);
Dmitry Vyukov47adccc2018-02-06 15:36:23 -0800204
Patricia Alfonso73228c72020-10-13 16:55:06 -0700205 ptr = kmalloc(size, GFP_KERNEL);
206 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
Alexander Potapenkoe6e83792016-03-25 14:21:56 -0700207
Patricia Alfonso73228c72020-10-13 16:55:06 -0700208 KUNIT_EXPECT_KASAN_FAIL(test, kfree(ptr + 1));
209}
210
Andrey Konovalov858bdeb2021-02-24 12:05:55 -0800211static void pagealloc_oob_right(struct kunit *test)
212{
213 char *ptr;
214 struct page *pages;
215 size_t order = 4;
216 size_t size = (1UL << (PAGE_SHIFT + order));
217
218 /*
219 * With generic KASAN page allocations have no redzones, thus
220 * out-of-bounds detection is not guaranteed.
221 * See https://bugzilla.kernel.org/show_bug.cgi?id=210503.
222 */
223 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_KASAN_GENERIC);
224
225 pages = alloc_pages(GFP_KERNEL, order);
226 ptr = page_address(pages);
227 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
228
229 KUNIT_EXPECT_KASAN_FAIL(test, ptr[size] = 0);
230 free_pages((unsigned long)ptr, order);
231}
232
233static void pagealloc_uaf(struct kunit *test)
234{
235 char *ptr;
236 struct page *pages;
237 size_t order = 4;
238
239 pages = alloc_pages(GFP_KERNEL, order);
240 ptr = page_address(pages);
241 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
242 free_pages((unsigned long)ptr, order);
243
244 KUNIT_EXPECT_KASAN_FAIL(test, ptr[0] = 0);
245}
246
Patricia Alfonso73228c72020-10-13 16:55:06 -0700247static void kmalloc_large_oob_right(struct kunit *test)
Alexander Potapenkoe6e83792016-03-25 14:21:56 -0700248{
249 char *ptr;
250 size_t size = KMALLOC_MAX_CACHE_SIZE - 256;
Andrey Konovalov0fd37922021-02-24 12:05:13 -0800251
252 /*
253 * Allocate a chunk that is large enough, but still fits into a slab
Alexander Potapenkoe6e83792016-03-25 14:21:56 -0700254 * and does not trigger the page allocator fallback in SLUB.
255 */
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800256 ptr = kmalloc(size, GFP_KERNEL);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700257 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800258
Patricia Alfonso73228c72020-10-13 16:55:06 -0700259 KUNIT_EXPECT_KASAN_FAIL(test, ptr[size] = 0);
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800260 kfree(ptr);
261}
262
Andrey Konovalovb87c28b92021-02-25 17:20:15 -0800263static void krealloc_more_oob_helper(struct kunit *test,
264 size_t size1, size_t size2)
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800265{
266 char *ptr1, *ptr2;
Andrey Konovalovb87c28b92021-02-25 17:20:15 -0800267 size_t middle;
268
269 KUNIT_ASSERT_LT(test, size1, size2);
270 middle = size1 + (size2 - size1) / 2;
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800271
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800272 ptr1 = kmalloc(size1, GFP_KERNEL);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700273 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1);
274
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800275 ptr2 = krealloc(ptr1, size2, GFP_KERNEL);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700276 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr2);
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800277
Andrey Konovalovb87c28b92021-02-25 17:20:15 -0800278 /* All offsets up to size2 must be accessible. */
279 ptr2[size1 - 1] = 'x';
280 ptr2[size1] = 'x';
281 ptr2[middle] = 'x';
282 ptr2[size2 - 1] = 'x';
283
284 /* Generic mode is precise, so unaligned size2 must be inaccessible. */
285 if (IS_ENABLED(CONFIG_KASAN_GENERIC))
286 KUNIT_EXPECT_KASAN_FAIL(test, ptr2[size2] = 'x');
287
288 /* For all modes first aligned offset after size2 must be inaccessible. */
289 KUNIT_EXPECT_KASAN_FAIL(test,
290 ptr2[round_up(size2, KASAN_GRANULE_SIZE)] = 'x');
291
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800292 kfree(ptr2);
293}
294
Andrey Konovalovb87c28b92021-02-25 17:20:15 -0800295static void krealloc_less_oob_helper(struct kunit *test,
296 size_t size1, size_t size2)
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800297{
298 char *ptr1, *ptr2;
Andrey Konovalovb87c28b92021-02-25 17:20:15 -0800299 size_t middle;
300
301 KUNIT_ASSERT_LT(test, size2, size1);
302 middle = size2 + (size1 - size2) / 2;
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800303
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800304 ptr1 = kmalloc(size1, GFP_KERNEL);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700305 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1);
306
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800307 ptr2 = krealloc(ptr1, size2, GFP_KERNEL);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700308 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr2);
Walter Wuf33a0142020-08-06 23:24:54 -0700309
Andrey Konovalovb87c28b92021-02-25 17:20:15 -0800310 /* Must be accessible for all modes. */
311 ptr2[size2 - 1] = 'x';
312
313 /* Generic mode is precise, so unaligned size2 must be inaccessible. */
314 if (IS_ENABLED(CONFIG_KASAN_GENERIC))
315 KUNIT_EXPECT_KASAN_FAIL(test, ptr2[size2] = 'x');
316
317 /* For all modes first aligned offset after size2 must be inaccessible. */
318 KUNIT_EXPECT_KASAN_FAIL(test,
319 ptr2[round_up(size2, KASAN_GRANULE_SIZE)] = 'x');
320
321 /*
322 * For all modes all size2, middle, and size1 should land in separate
323 * granules and thus the latter two offsets should be inaccessible.
324 */
325 KUNIT_EXPECT_LE(test, round_up(size2, KASAN_GRANULE_SIZE),
326 round_down(middle, KASAN_GRANULE_SIZE));
327 KUNIT_EXPECT_LE(test, round_up(middle, KASAN_GRANULE_SIZE),
328 round_down(size1, KASAN_GRANULE_SIZE));
329 KUNIT_EXPECT_KASAN_FAIL(test, ptr2[middle] = 'x');
330 KUNIT_EXPECT_KASAN_FAIL(test, ptr2[size1 - 1] = 'x');
331 KUNIT_EXPECT_KASAN_FAIL(test, ptr2[size1] = 'x');
332
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800333 kfree(ptr2);
334}
335
Andrey Konovalovb87c28b92021-02-25 17:20:15 -0800336static void krealloc_more_oob(struct kunit *test)
337{
338 krealloc_more_oob_helper(test, 201, 235);
339}
340
341static void krealloc_less_oob(struct kunit *test)
342{
343 krealloc_less_oob_helper(test, 235, 201);
344}
345
346static void krealloc_pagealloc_more_oob(struct kunit *test)
347{
348 /* page_alloc fallback in only implemented for SLUB. */
349 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_SLUB);
350
351 krealloc_more_oob_helper(test, KMALLOC_MAX_CACHE_SIZE + 201,
352 KMALLOC_MAX_CACHE_SIZE + 235);
353}
354
355static void krealloc_pagealloc_less_oob(struct kunit *test)
356{
357 /* page_alloc fallback in only implemented for SLUB. */
358 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_SLUB);
359
360 krealloc_less_oob_helper(test, KMALLOC_MAX_CACHE_SIZE + 235,
361 KMALLOC_MAX_CACHE_SIZE + 201);
362}
363
Andrey Konovalov26a5ca72021-02-25 17:20:19 -0800364/*
365 * Check that krealloc() detects a use-after-free, returns NULL,
366 * and doesn't unpoison the freed object.
367 */
368static void krealloc_uaf(struct kunit *test)
369{
370 char *ptr1, *ptr2;
371 int size1 = 201;
372 int size2 = 235;
373
374 ptr1 = kmalloc(size1, GFP_KERNEL);
375 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1);
376 kfree(ptr1);
377
378 KUNIT_EXPECT_KASAN_FAIL(test, ptr2 = krealloc(ptr1, size2, GFP_KERNEL));
379 KUNIT_ASSERT_PTR_EQ(test, (void *)ptr2, NULL);
380 KUNIT_EXPECT_KASAN_FAIL(test, *(volatile char *)ptr1);
381}
382
Patricia Alfonso73228c72020-10-13 16:55:06 -0700383static void kmalloc_oob_16(struct kunit *test)
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800384{
385 struct {
386 u64 words[2];
387 } *ptr1, *ptr2;
388
Andrey Konovalov58b999d2020-11-01 17:07:37 -0800389 /* This test is specifically crafted for the generic mode. */
Andrey Konovalovda17e372021-02-24 12:05:17 -0800390 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_GENERIC);
Andrey Konovalov58b999d2020-11-01 17:07:37 -0800391
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800392 ptr1 = kmalloc(sizeof(*ptr1) - 3, GFP_KERNEL);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700393 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1);
394
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800395 ptr2 = kmalloc(sizeof(*ptr2), GFP_KERNEL);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700396 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr2);
397
398 KUNIT_EXPECT_KASAN_FAIL(test, *ptr1 = *ptr2);
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800399 kfree(ptr1);
400 kfree(ptr2);
401}
402
Andrey Konovalov58b999d2020-11-01 17:07:37 -0800403static void kmalloc_uaf_16(struct kunit *test)
404{
405 struct {
406 u64 words[2];
407 } *ptr1, *ptr2;
408
409 ptr1 = kmalloc(sizeof(*ptr1), GFP_KERNEL);
410 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1);
411
412 ptr2 = kmalloc(sizeof(*ptr2), GFP_KERNEL);
413 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr2);
414 kfree(ptr2);
415
416 KUNIT_EXPECT_KASAN_FAIL(test, *ptr1 = *ptr2);
417 kfree(ptr1);
418}
419
Patricia Alfonso73228c72020-10-13 16:55:06 -0700420static void kmalloc_oob_memset_2(struct kunit *test)
Wang Longf523e732015-11-05 18:51:15 -0800421{
422 char *ptr;
423 size_t size = 8;
424
Wang Longf523e732015-11-05 18:51:15 -0800425 ptr = kmalloc(size, GFP_KERNEL);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700426 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
Wang Longf523e732015-11-05 18:51:15 -0800427
Patricia Alfonso73228c72020-10-13 16:55:06 -0700428 KUNIT_EXPECT_KASAN_FAIL(test, memset(ptr + 7 + OOB_TAG_OFF, 0, 2));
Wang Longf523e732015-11-05 18:51:15 -0800429 kfree(ptr);
430}
431
Patricia Alfonso73228c72020-10-13 16:55:06 -0700432static void kmalloc_oob_memset_4(struct kunit *test)
Wang Longf523e732015-11-05 18:51:15 -0800433{
434 char *ptr;
435 size_t size = 8;
436
Wang Longf523e732015-11-05 18:51:15 -0800437 ptr = kmalloc(size, GFP_KERNEL);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700438 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
Wang Longf523e732015-11-05 18:51:15 -0800439
Patricia Alfonso73228c72020-10-13 16:55:06 -0700440 KUNIT_EXPECT_KASAN_FAIL(test, memset(ptr + 5 + OOB_TAG_OFF, 0, 4));
Wang Longf523e732015-11-05 18:51:15 -0800441 kfree(ptr);
442}
443
444
Patricia Alfonso73228c72020-10-13 16:55:06 -0700445static void kmalloc_oob_memset_8(struct kunit *test)
Wang Longf523e732015-11-05 18:51:15 -0800446{
447 char *ptr;
448 size_t size = 8;
449
Wang Longf523e732015-11-05 18:51:15 -0800450 ptr = kmalloc(size, GFP_KERNEL);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700451 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
Wang Longf523e732015-11-05 18:51:15 -0800452
Patricia Alfonso73228c72020-10-13 16:55:06 -0700453 KUNIT_EXPECT_KASAN_FAIL(test, memset(ptr + 1 + OOB_TAG_OFF, 0, 8));
Wang Longf523e732015-11-05 18:51:15 -0800454 kfree(ptr);
455}
456
Patricia Alfonso73228c72020-10-13 16:55:06 -0700457static void kmalloc_oob_memset_16(struct kunit *test)
Wang Longf523e732015-11-05 18:51:15 -0800458{
459 char *ptr;
460 size_t size = 16;
461
Wang Longf523e732015-11-05 18:51:15 -0800462 ptr = kmalloc(size, GFP_KERNEL);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700463 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
Wang Longf523e732015-11-05 18:51:15 -0800464
Patricia Alfonso73228c72020-10-13 16:55:06 -0700465 KUNIT_EXPECT_KASAN_FAIL(test, memset(ptr + 1 + OOB_TAG_OFF, 0, 16));
Wang Longf523e732015-11-05 18:51:15 -0800466 kfree(ptr);
467}
468
Patricia Alfonso73228c72020-10-13 16:55:06 -0700469static void kmalloc_oob_in_memset(struct kunit *test)
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800470{
471 char *ptr;
472 size_t size = 666;
473
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800474 ptr = kmalloc(size, GFP_KERNEL);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700475 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800476
Patricia Alfonso73228c72020-10-13 16:55:06 -0700477 KUNIT_EXPECT_KASAN_FAIL(test, memset(ptr, 0, size + 5 + OOB_TAG_OFF));
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800478 kfree(ptr);
479}
480
Patricia Alfonso73228c72020-10-13 16:55:06 -0700481static void kmalloc_memmove_invalid_size(struct kunit *test)
Walter Wu98f3b562020-04-01 21:09:40 -0700482{
483 char *ptr;
484 size_t size = 64;
485 volatile size_t invalid_size = -2;
486
Walter Wu98f3b562020-04-01 21:09:40 -0700487 ptr = kmalloc(size, GFP_KERNEL);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700488 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
Walter Wu98f3b562020-04-01 21:09:40 -0700489
490 memset((char *)ptr, 0, 64);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700491
492 KUNIT_EXPECT_KASAN_FAIL(test,
493 memmove((char *)ptr, (char *)ptr + 4, invalid_size));
Walter Wu98f3b562020-04-01 21:09:40 -0700494 kfree(ptr);
495}
496
Patricia Alfonso73228c72020-10-13 16:55:06 -0700497static void kmalloc_uaf(struct kunit *test)
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800498{
499 char *ptr;
500 size_t size = 10;
501
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800502 ptr = kmalloc(size, GFP_KERNEL);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700503 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800504
505 kfree(ptr);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700506 KUNIT_EXPECT_KASAN_FAIL(test, *(ptr + 8) = 'x');
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800507}
508
Patricia Alfonso73228c72020-10-13 16:55:06 -0700509static void kmalloc_uaf_memset(struct kunit *test)
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800510{
511 char *ptr;
512 size_t size = 33;
513
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800514 ptr = kmalloc(size, GFP_KERNEL);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700515 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800516
517 kfree(ptr);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700518 KUNIT_EXPECT_KASAN_FAIL(test, memset(ptr, 0, size));
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800519}
520
Patricia Alfonso73228c72020-10-13 16:55:06 -0700521static void kmalloc_uaf2(struct kunit *test)
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800522{
523 char *ptr1, *ptr2;
524 size_t size = 43;
Andrey Konovalov1b1df4c2021-02-24 12:05:38 -0800525 int counter = 0;
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800526
Andrey Konovalov1b1df4c2021-02-24 12:05:38 -0800527again:
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800528 ptr1 = kmalloc(size, GFP_KERNEL);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700529 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1);
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800530
531 kfree(ptr1);
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800532
Patricia Alfonso73228c72020-10-13 16:55:06 -0700533 ptr2 = kmalloc(size, GFP_KERNEL);
534 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr2);
535
Andrey Konovalov1b1df4c2021-02-24 12:05:38 -0800536 /*
537 * For tag-based KASAN ptr1 and ptr2 tags might happen to be the same.
538 * Allow up to 16 attempts at generating different tags.
539 */
540 if (!IS_ENABLED(CONFIG_KASAN_GENERIC) && ptr1 == ptr2 && counter++ < 16) {
541 kfree(ptr2);
542 goto again;
543 }
544
Patricia Alfonso73228c72020-10-13 16:55:06 -0700545 KUNIT_EXPECT_KASAN_FAIL(test, ptr1[40] = 'x');
546 KUNIT_EXPECT_PTR_NE(test, ptr1, ptr2);
547
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800548 kfree(ptr2);
549}
550
Patricia Alfonso73228c72020-10-13 16:55:06 -0700551static void kfree_via_page(struct kunit *test)
Mark Rutlandb92a9532019-09-23 15:34:16 -0700552{
553 char *ptr;
554 size_t size = 8;
555 struct page *page;
556 unsigned long offset;
557
Mark Rutlandb92a9532019-09-23 15:34:16 -0700558 ptr = kmalloc(size, GFP_KERNEL);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700559 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
Mark Rutlandb92a9532019-09-23 15:34:16 -0700560
561 page = virt_to_page(ptr);
562 offset = offset_in_page(ptr);
563 kfree(page_address(page) + offset);
564}
565
Patricia Alfonso73228c72020-10-13 16:55:06 -0700566static void kfree_via_phys(struct kunit *test)
Mark Rutlandb92a9532019-09-23 15:34:16 -0700567{
568 char *ptr;
569 size_t size = 8;
570 phys_addr_t phys;
571
Mark Rutlandb92a9532019-09-23 15:34:16 -0700572 ptr = kmalloc(size, GFP_KERNEL);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700573 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
Mark Rutlandb92a9532019-09-23 15:34:16 -0700574
575 phys = virt_to_phys(ptr);
576 kfree(phys_to_virt(phys));
577}
578
Patricia Alfonso73228c72020-10-13 16:55:06 -0700579static void kmem_cache_oob(struct kunit *test)
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800580{
581 char *p;
582 size_t size = 200;
Andrey Konovalov11516132021-02-24 12:05:59 -0800583 struct kmem_cache *cache;
584
585 cache = kmem_cache_create("test_cache", size, 0, 0, NULL);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700586 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache);
Andrey Konovalov11516132021-02-24 12:05:59 -0800587
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800588 p = kmem_cache_alloc(cache, GFP_KERNEL);
589 if (!p) {
Patricia Alfonso73228c72020-10-13 16:55:06 -0700590 kunit_err(test, "Allocation failed: %s\n", __func__);
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800591 kmem_cache_destroy(cache);
592 return;
593 }
594
Patricia Alfonso73228c72020-10-13 16:55:06 -0700595 KUNIT_EXPECT_KASAN_FAIL(test, *p = p[size + OOB_TAG_OFF]);
Andrey Konovalov11516132021-02-24 12:05:59 -0800596
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800597 kmem_cache_free(cache, p);
598 kmem_cache_destroy(cache);
599}
600
Andrey Konovalov11516132021-02-24 12:05:59 -0800601static void kmem_cache_accounted(struct kunit *test)
Greg Thelen0386bf32017-02-24 15:00:08 -0800602{
603 int i;
604 char *p;
605 size_t size = 200;
606 struct kmem_cache *cache;
607
608 cache = kmem_cache_create("test_cache", size, 0, SLAB_ACCOUNT, NULL);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700609 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache);
Greg Thelen0386bf32017-02-24 15:00:08 -0800610
Greg Thelen0386bf32017-02-24 15:00:08 -0800611 /*
612 * Several allocations with a delay to allow for lazy per memcg kmem
613 * cache creation.
614 */
615 for (i = 0; i < 5; i++) {
616 p = kmem_cache_alloc(cache, GFP_KERNEL);
Markus Elfringdc2bf0002017-11-17 15:28:00 -0800617 if (!p)
Greg Thelen0386bf32017-02-24 15:00:08 -0800618 goto free_cache;
Markus Elfringdc2bf0002017-11-17 15:28:00 -0800619
Greg Thelen0386bf32017-02-24 15:00:08 -0800620 kmem_cache_free(cache, p);
621 msleep(100);
622 }
623
624free_cache:
625 kmem_cache_destroy(cache);
626}
627
Andrey Konovalov11516132021-02-24 12:05:59 -0800628static void kmem_cache_bulk(struct kunit *test)
629{
630 struct kmem_cache *cache;
631 size_t size = 200;
632 char *p[10];
633 bool ret;
634 int i;
635
636 cache = kmem_cache_create("test_cache", size, 0, 0, NULL);
637 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache);
638
639 ret = kmem_cache_alloc_bulk(cache, GFP_KERNEL, ARRAY_SIZE(p), (void **)&p);
640 if (!ret) {
641 kunit_err(test, "Allocation failed: %s\n", __func__);
642 kmem_cache_destroy(cache);
643 return;
644 }
645
646 for (i = 0; i < ARRAY_SIZE(p); i++)
647 p[i][0] = p[i][size - 1] = 42;
648
649 kmem_cache_free_bulk(cache, ARRAY_SIZE(p), (void **)&p);
650 kmem_cache_destroy(cache);
651}
652
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800653static char global_array[10];
654
Patricia Alfonso73228c72020-10-13 16:55:06 -0700655static void kasan_global_oob(struct kunit *test)
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800656{
Peter Collingbournef649dc02021-05-14 17:27:27 -0700657 /*
658 * Deliberate out-of-bounds access. To prevent CONFIG_UBSAN_LOCAL_BOUNDS
659 * from failing here and panicing the kernel, access the array via a
660 * volatile pointer, which will prevent the compiler from being able to
661 * determine the array bounds.
662 *
663 * This access uses a volatile pointer to char (char *volatile) rather
664 * than the more conventional pointer to volatile char (volatile char *)
665 * because we want to prevent the compiler from making inferences about
666 * the pointer itself (i.e. its array bounds), not the data that it
667 * refers to.
668 */
669 char *volatile array = global_array;
670 char *p = &array[ARRAY_SIZE(global_array) + 3];
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800671
Andrey Konovalov58b999d2020-11-01 17:07:37 -0800672 /* Only generic mode instruments globals. */
Andrey Konovalovda17e372021-02-24 12:05:17 -0800673 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_GENERIC);
Andrey Konovalov58b999d2020-11-01 17:07:37 -0800674
Patricia Alfonso73228c72020-10-13 16:55:06 -0700675 KUNIT_EXPECT_KASAN_FAIL(test, *(volatile char *)p);
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800676}
677
Andrey Konovalov611806b2021-02-24 12:05:50 -0800678/* Check that ksize() makes the whole object accessible. */
Patricia Alfonso73228c72020-10-13 16:55:06 -0700679static void ksize_unpoisons_memory(struct kunit *test)
680{
681 char *ptr;
682 size_t size = 123, real_size;
683
684 ptr = kmalloc(size, GFP_KERNEL);
685 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
686 real_size = ksize(ptr);
Andrey Konovalov0fd37922021-02-24 12:05:13 -0800687
688 /* This access shouldn't trigger a KASAN report. */
Patricia Alfonso73228c72020-10-13 16:55:06 -0700689 ptr[size] = 'x';
Andrey Konovalov0fd37922021-02-24 12:05:13 -0800690
691 /* This one must. */
Patricia Alfonso73228c72020-10-13 16:55:06 -0700692 KUNIT_EXPECT_KASAN_FAIL(test, ptr[real_size] = 'y');
Andrey Konovalov0fd37922021-02-24 12:05:13 -0800693
Patricia Alfonso73228c72020-10-13 16:55:06 -0700694 kfree(ptr);
695}
696
Andrey Konovalov611806b2021-02-24 12:05:50 -0800697/*
698 * Check that a use-after-free is detected by ksize() and via normal accesses
699 * after it.
700 */
701static void ksize_uaf(struct kunit *test)
702{
703 char *ptr;
704 int size = 128 - KASAN_GRANULE_SIZE;
705
706 ptr = kmalloc(size, GFP_KERNEL);
707 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
708 kfree(ptr);
709
710 KUNIT_EXPECT_KASAN_FAIL(test, ksize(ptr));
711 KUNIT_EXPECT_KASAN_FAIL(test, kasan_int_result = *ptr);
712 KUNIT_EXPECT_KASAN_FAIL(test, kasan_int_result = *(ptr + size));
713}
714
Patricia Alfonso73228c72020-10-13 16:55:06 -0700715static void kasan_stack_oob(struct kunit *test)
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800716{
717 char stack_array[10];
Peter Collingbournef649dc02021-05-14 17:27:27 -0700718 /* See comment in kasan_global_oob. */
719 char *volatile array = stack_array;
720 char *p = &array[ARRAY_SIZE(stack_array) + OOB_TAG_OFF];
Andrey Ryabinin3f158012015-02-13 14:39:53 -0800721
Andrey Konovalovda17e372021-02-24 12:05:17 -0800722 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_STACK);
Andrey Ryabinineae08dc2016-05-20 16:59:34 -0700723
Patricia Alfonso73228c72020-10-13 16:55:06 -0700724 KUNIT_EXPECT_KASAN_FAIL(test, *(volatile char *)p);
Andrey Ryabinineae08dc2016-05-20 16:59:34 -0700725}
726
Patricia Alfonso73228c72020-10-13 16:55:06 -0700727static void kasan_alloca_oob_left(struct kunit *test)
Paul Lawrence00a14292018-02-06 15:36:16 -0800728{
729 volatile int i = 10;
730 char alloca_array[i];
Peter Collingbournef649dc02021-05-14 17:27:27 -0700731 /* See comment in kasan_global_oob. */
732 char *volatile array = alloca_array;
733 char *p = array - 1;
Paul Lawrence00a14292018-02-06 15:36:16 -0800734
Andrey Konovalov58b999d2020-11-01 17:07:37 -0800735 /* Only generic mode instruments dynamic allocas. */
Andrey Konovalovda17e372021-02-24 12:05:17 -0800736 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_GENERIC);
737 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_STACK);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700738
739 KUNIT_EXPECT_KASAN_FAIL(test, *(volatile char *)p);
Paul Lawrence00a14292018-02-06 15:36:16 -0800740}
741
Patricia Alfonso73228c72020-10-13 16:55:06 -0700742static void kasan_alloca_oob_right(struct kunit *test)
Paul Lawrence00a14292018-02-06 15:36:16 -0800743{
744 volatile int i = 10;
745 char alloca_array[i];
Peter Collingbournef649dc02021-05-14 17:27:27 -0700746 /* See comment in kasan_global_oob. */
747 char *volatile array = alloca_array;
748 char *p = array + i;
Paul Lawrence00a14292018-02-06 15:36:16 -0800749
Andrey Konovalov58b999d2020-11-01 17:07:37 -0800750 /* Only generic mode instruments dynamic allocas. */
Andrey Konovalovda17e372021-02-24 12:05:17 -0800751 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_GENERIC);
752 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_STACK);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700753
754 KUNIT_EXPECT_KASAN_FAIL(test, *(volatile char *)p);
Paul Lawrence00a14292018-02-06 15:36:16 -0800755}
756
Patricia Alfonso73228c72020-10-13 16:55:06 -0700757static void kmem_cache_double_free(struct kunit *test)
Dmitry Vyukovb1d57282018-02-06 15:36:37 -0800758{
759 char *p;
760 size_t size = 200;
761 struct kmem_cache *cache;
762
763 cache = kmem_cache_create("test_cache", size, 0, 0, NULL);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700764 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache);
765
Dmitry Vyukovb1d57282018-02-06 15:36:37 -0800766 p = kmem_cache_alloc(cache, GFP_KERNEL);
767 if (!p) {
Patricia Alfonso73228c72020-10-13 16:55:06 -0700768 kunit_err(test, "Allocation failed: %s\n", __func__);
Dmitry Vyukovb1d57282018-02-06 15:36:37 -0800769 kmem_cache_destroy(cache);
770 return;
771 }
772
773 kmem_cache_free(cache, p);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700774 KUNIT_EXPECT_KASAN_FAIL(test, kmem_cache_free(cache, p));
Dmitry Vyukovb1d57282018-02-06 15:36:37 -0800775 kmem_cache_destroy(cache);
776}
777
Patricia Alfonso73228c72020-10-13 16:55:06 -0700778static void kmem_cache_invalid_free(struct kunit *test)
Dmitry Vyukovb1d57282018-02-06 15:36:37 -0800779{
780 char *p;
781 size_t size = 200;
782 struct kmem_cache *cache;
783
784 cache = kmem_cache_create("test_cache", size, 0, SLAB_TYPESAFE_BY_RCU,
785 NULL);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700786 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache);
787
Dmitry Vyukovb1d57282018-02-06 15:36:37 -0800788 p = kmem_cache_alloc(cache, GFP_KERNEL);
789 if (!p) {
Patricia Alfonso73228c72020-10-13 16:55:06 -0700790 kunit_err(test, "Allocation failed: %s\n", __func__);
Dmitry Vyukovb1d57282018-02-06 15:36:37 -0800791 kmem_cache_destroy(cache);
792 return;
793 }
794
Andrey Konovalov0fd37922021-02-24 12:05:13 -0800795 /* Trigger invalid free, the object doesn't get freed. */
Patricia Alfonso73228c72020-10-13 16:55:06 -0700796 KUNIT_EXPECT_KASAN_FAIL(test, kmem_cache_free(cache, p + 1));
Andrey Konovalov91c93ed2018-04-10 16:30:35 -0700797
798 /*
799 * Properly free the object to prevent the "Objects remaining in
800 * test_cache on __kmem_cache_shutdown" BUG failure.
801 */
802 kmem_cache_free(cache, p);
803
Dmitry Vyukovb1d57282018-02-06 15:36:37 -0800804 kmem_cache_destroy(cache);
805}
806
Patricia Alfonso73228c72020-10-13 16:55:06 -0700807static void kasan_memchr(struct kunit *test)
Andrey Ryabinin0c963502018-10-26 15:02:34 -0700808{
809 char *ptr;
810 size_t size = 24;
811
Andrey Konovalov0fd37922021-02-24 12:05:13 -0800812 /*
813 * str* functions are not instrumented with CONFIG_AMD_MEM_ENCRYPT.
814 * See https://bugzilla.kernel.org/show_bug.cgi?id=206337 for details.
815 */
Andrey Konovalovda17e372021-02-24 12:05:17 -0800816 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_AMD_MEM_ENCRYPT);
Andrey Ryabinin0c963502018-10-26 15:02:34 -0700817
Andrey Konovalov58b999d2020-11-01 17:07:37 -0800818 if (OOB_TAG_OFF)
819 size = round_up(size, OOB_TAG_OFF);
820
Patricia Alfonso73228c72020-10-13 16:55:06 -0700821 ptr = kmalloc(size, GFP_KERNEL | __GFP_ZERO);
822 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
823
824 KUNIT_EXPECT_KASAN_FAIL(test,
825 kasan_ptr_result = memchr(ptr, '1', size + 1));
826
Andrey Ryabinin0c963502018-10-26 15:02:34 -0700827 kfree(ptr);
828}
829
Patricia Alfonso73228c72020-10-13 16:55:06 -0700830static void kasan_memcmp(struct kunit *test)
Andrey Ryabinin0c963502018-10-26 15:02:34 -0700831{
832 char *ptr;
833 size_t size = 24;
834 int arr[9];
835
Andrey Konovalov0fd37922021-02-24 12:05:13 -0800836 /*
837 * str* functions are not instrumented with CONFIG_AMD_MEM_ENCRYPT.
838 * See https://bugzilla.kernel.org/show_bug.cgi?id=206337 for details.
839 */
Andrey Konovalovda17e372021-02-24 12:05:17 -0800840 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_AMD_MEM_ENCRYPT);
Andrey Ryabinin0c963502018-10-26 15:02:34 -0700841
Andrey Konovalov58b999d2020-11-01 17:07:37 -0800842 if (OOB_TAG_OFF)
843 size = round_up(size, OOB_TAG_OFF);
844
Patricia Alfonso73228c72020-10-13 16:55:06 -0700845 ptr = kmalloc(size, GFP_KERNEL | __GFP_ZERO);
846 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
Andrey Ryabinin0c963502018-10-26 15:02:34 -0700847 memset(arr, 0, sizeof(arr));
Patricia Alfonso73228c72020-10-13 16:55:06 -0700848
849 KUNIT_EXPECT_KASAN_FAIL(test,
850 kasan_int_result = memcmp(ptr, arr, size+1));
Andrey Ryabinin0c963502018-10-26 15:02:34 -0700851 kfree(ptr);
852}
853
Patricia Alfonso73228c72020-10-13 16:55:06 -0700854static void kasan_strings(struct kunit *test)
Andrey Ryabinin0c963502018-10-26 15:02:34 -0700855{
856 char *ptr;
857 size_t size = 24;
858
Andrey Konovalov0fd37922021-02-24 12:05:13 -0800859 /*
860 * str* functions are not instrumented with CONFIG_AMD_MEM_ENCRYPT.
861 * See https://bugzilla.kernel.org/show_bug.cgi?id=206337 for details.
862 */
Andrey Konovalovda17e372021-02-24 12:05:17 -0800863 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_AMD_MEM_ENCRYPT);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700864
865 ptr = kmalloc(size, GFP_KERNEL | __GFP_ZERO);
866 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
Andrey Ryabinin0c963502018-10-26 15:02:34 -0700867
868 kfree(ptr);
869
870 /*
871 * Try to cause only 1 invalid access (less spam in dmesg).
872 * For that we need ptr to point to zeroed byte.
873 * Skip metadata that could be stored in freed object so ptr
874 * will likely point to zeroed byte.
875 */
876 ptr += 16;
Patricia Alfonso73228c72020-10-13 16:55:06 -0700877 KUNIT_EXPECT_KASAN_FAIL(test, kasan_ptr_result = strchr(ptr, '1'));
Andrey Ryabinin0c963502018-10-26 15:02:34 -0700878
Patricia Alfonso73228c72020-10-13 16:55:06 -0700879 KUNIT_EXPECT_KASAN_FAIL(test, kasan_ptr_result = strrchr(ptr, '1'));
Andrey Ryabinin0c963502018-10-26 15:02:34 -0700880
Patricia Alfonso73228c72020-10-13 16:55:06 -0700881 KUNIT_EXPECT_KASAN_FAIL(test, kasan_int_result = strcmp(ptr, "2"));
Andrey Ryabinin0c963502018-10-26 15:02:34 -0700882
Patricia Alfonso73228c72020-10-13 16:55:06 -0700883 KUNIT_EXPECT_KASAN_FAIL(test, kasan_int_result = strncmp(ptr, "2", 1));
Andrey Ryabinin0c963502018-10-26 15:02:34 -0700884
Patricia Alfonso73228c72020-10-13 16:55:06 -0700885 KUNIT_EXPECT_KASAN_FAIL(test, kasan_int_result = strlen(ptr));
Andrey Ryabinin0c963502018-10-26 15:02:34 -0700886
Patricia Alfonso73228c72020-10-13 16:55:06 -0700887 KUNIT_EXPECT_KASAN_FAIL(test, kasan_int_result = strnlen(ptr, 1));
Andrey Ryabinin0c963502018-10-26 15:02:34 -0700888}
889
Andrey Konovalov58b999d2020-11-01 17:07:37 -0800890static void kasan_bitops_modify(struct kunit *test, int nr, void *addr)
Marco Elver19a33ca2019-07-11 20:53:52 -0700891{
Andrey Konovalov58b999d2020-11-01 17:07:37 -0800892 KUNIT_EXPECT_KASAN_FAIL(test, set_bit(nr, addr));
893 KUNIT_EXPECT_KASAN_FAIL(test, __set_bit(nr, addr));
894 KUNIT_EXPECT_KASAN_FAIL(test, clear_bit(nr, addr));
895 KUNIT_EXPECT_KASAN_FAIL(test, __clear_bit(nr, addr));
896 KUNIT_EXPECT_KASAN_FAIL(test, clear_bit_unlock(nr, addr));
897 KUNIT_EXPECT_KASAN_FAIL(test, __clear_bit_unlock(nr, addr));
898 KUNIT_EXPECT_KASAN_FAIL(test, change_bit(nr, addr));
899 KUNIT_EXPECT_KASAN_FAIL(test, __change_bit(nr, addr));
900}
901
902static void kasan_bitops_test_and_modify(struct kunit *test, int nr, void *addr)
903{
904 KUNIT_EXPECT_KASAN_FAIL(test, test_and_set_bit(nr, addr));
905 KUNIT_EXPECT_KASAN_FAIL(test, __test_and_set_bit(nr, addr));
906 KUNIT_EXPECT_KASAN_FAIL(test, test_and_set_bit_lock(nr, addr));
907 KUNIT_EXPECT_KASAN_FAIL(test, test_and_clear_bit(nr, addr));
908 KUNIT_EXPECT_KASAN_FAIL(test, __test_and_clear_bit(nr, addr));
909 KUNIT_EXPECT_KASAN_FAIL(test, test_and_change_bit(nr, addr));
910 KUNIT_EXPECT_KASAN_FAIL(test, __test_and_change_bit(nr, addr));
911 KUNIT_EXPECT_KASAN_FAIL(test, kasan_int_result = test_bit(nr, addr));
912
913#if defined(clear_bit_unlock_is_negative_byte)
914 KUNIT_EXPECT_KASAN_FAIL(test, kasan_int_result =
915 clear_bit_unlock_is_negative_byte(nr, addr));
916#endif
917}
918
919static void kasan_bitops_generic(struct kunit *test)
920{
921 long *bits;
922
923 /* This test is specifically crafted for the generic mode. */
Andrey Konovalovda17e372021-02-24 12:05:17 -0800924 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_GENERIC);
Andrey Konovalov58b999d2020-11-01 17:07:37 -0800925
Marco Elver19a33ca2019-07-11 20:53:52 -0700926 /*
Andrey Konovalov0fd37922021-02-24 12:05:13 -0800927 * Allocate 1 more byte, which causes kzalloc to round up to 16 bytes;
Marco Elver19a33ca2019-07-11 20:53:52 -0700928 * this way we do not actually corrupt other memory.
929 */
Andrey Konovalov58b999d2020-11-01 17:07:37 -0800930 bits = kzalloc(sizeof(*bits) + 1, GFP_KERNEL);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700931 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, bits);
Marco Elver19a33ca2019-07-11 20:53:52 -0700932
933 /*
934 * Below calls try to access bit within allocated memory; however, the
935 * below accesses are still out-of-bounds, since bitops are defined to
936 * operate on the whole long the bit is in.
937 */
Andrey Konovalov58b999d2020-11-01 17:07:37 -0800938 kasan_bitops_modify(test, BITS_PER_LONG, bits);
Marco Elver19a33ca2019-07-11 20:53:52 -0700939
940 /*
941 * Below calls try to access bit beyond allocated memory.
942 */
Andrey Konovalov58b999d2020-11-01 17:07:37 -0800943 kasan_bitops_test_and_modify(test, BITS_PER_LONG + BITS_PER_BYTE, bits);
Marco Elver19a33ca2019-07-11 20:53:52 -0700944
Andrey Konovalov58b999d2020-11-01 17:07:37 -0800945 kfree(bits);
946}
Marco Elver19a33ca2019-07-11 20:53:52 -0700947
Andrey Konovalov58b999d2020-11-01 17:07:37 -0800948static void kasan_bitops_tags(struct kunit *test)
949{
950 long *bits;
Marco Elver19a33ca2019-07-11 20:53:52 -0700951
Andrey Konovalovda17e372021-02-24 12:05:17 -0800952 /* This test is specifically crafted for tag-based modes. */
953 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_KASAN_GENERIC);
Marco Elver19a33ca2019-07-11 20:53:52 -0700954
Andrey Konovalove66e1792021-02-24 12:05:42 -0800955 /* kmalloc-64 cache will be used and the last 16 bytes will be the redzone. */
956 bits = kzalloc(48, GFP_KERNEL);
Andrey Konovalov58b999d2020-11-01 17:07:37 -0800957 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, bits);
Marco Elver19a33ca2019-07-11 20:53:52 -0700958
Andrey Konovalove66e1792021-02-24 12:05:42 -0800959 /* Do the accesses past the 48 allocated bytes, but within the redone. */
960 kasan_bitops_modify(test, BITS_PER_LONG, (void *)bits + 48);
961 kasan_bitops_test_and_modify(test, BITS_PER_LONG + BITS_PER_BYTE, (void *)bits + 48);
Marco Elver19a33ca2019-07-11 20:53:52 -0700962
Marco Elver19a33ca2019-07-11 20:53:52 -0700963 kfree(bits);
964}
965
Patricia Alfonso73228c72020-10-13 16:55:06 -0700966static void kmalloc_double_kzfree(struct kunit *test)
Marco Elverbb104ed2019-07-11 20:54:11 -0700967{
968 char *ptr;
969 size_t size = 16;
970
Marco Elverbb104ed2019-07-11 20:54:11 -0700971 ptr = kmalloc(size, GFP_KERNEL);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700972 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
Marco Elverbb104ed2019-07-11 20:54:11 -0700973
Waiman Long453431a2020-08-06 23:18:13 -0700974 kfree_sensitive(ptr);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700975 KUNIT_EXPECT_KASAN_FAIL(test, kfree_sensitive(ptr));
Marco Elverbb104ed2019-07-11 20:54:11 -0700976}
977
Patricia Alfonso73228c72020-10-13 16:55:06 -0700978static void vmalloc_oob(struct kunit *test)
Daniel Axtens06513912019-11-30 17:54:53 -0800979{
980 void *area;
981
Andrey Konovalovda17e372021-02-24 12:05:17 -0800982 KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_VMALLOC);
Daniel Axtens06513912019-11-30 17:54:53 -0800983
984 /*
985 * We have to be careful not to hit the guard page.
986 * The MMU will catch that and crash us.
987 */
988 area = vmalloc(3000);
Patricia Alfonso73228c72020-10-13 16:55:06 -0700989 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, area);
Daniel Axtens06513912019-11-30 17:54:53 -0800990
Patricia Alfonso73228c72020-10-13 16:55:06 -0700991 KUNIT_EXPECT_KASAN_FAIL(test, ((volatile char *)area)[3100]);
Daniel Axtens06513912019-11-30 17:54:53 -0800992 vfree(area);
993}
Daniel Axtens06513912019-11-30 17:54:53 -0800994
Andrey Konovalov573a4802021-02-24 12:05:21 -0800995/*
996 * Check that the assigned pointer tag falls within the [KASAN_TAG_MIN,
997 * KASAN_TAG_KERNEL) range (note: excluding the match-all tag) for tag-based
998 * modes.
999 */
1000static void match_all_not_assigned(struct kunit *test)
1001{
1002 char *ptr;
1003 struct page *pages;
1004 int i, size, order;
1005
1006 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_KASAN_GENERIC);
1007
1008 for (i = 0; i < 256; i++) {
1009 size = (get_random_int() % 1024) + 1;
1010 ptr = kmalloc(size, GFP_KERNEL);
1011 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
1012 KUNIT_EXPECT_GE(test, (u8)get_tag(ptr), (u8)KASAN_TAG_MIN);
1013 KUNIT_EXPECT_LT(test, (u8)get_tag(ptr), (u8)KASAN_TAG_KERNEL);
1014 kfree(ptr);
1015 }
1016
1017 for (i = 0; i < 256; i++) {
1018 order = (get_random_int() % 4) + 1;
1019 pages = alloc_pages(GFP_KERNEL, order);
1020 ptr = page_address(pages);
1021 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
1022 KUNIT_EXPECT_GE(test, (u8)get_tag(ptr), (u8)KASAN_TAG_MIN);
1023 KUNIT_EXPECT_LT(test, (u8)get_tag(ptr), (u8)KASAN_TAG_KERNEL);
1024 free_pages((unsigned long)ptr, order);
1025 }
1026}
1027
1028/* Check that 0xff works as a match-all pointer tag for tag-based modes. */
1029static void match_all_ptr_tag(struct kunit *test)
1030{
1031 char *ptr;
1032 u8 tag;
1033
1034 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_KASAN_GENERIC);
1035
1036 ptr = kmalloc(128, GFP_KERNEL);
1037 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
1038
1039 /* Backup the assigned tag. */
1040 tag = get_tag(ptr);
1041 KUNIT_EXPECT_NE(test, tag, (u8)KASAN_TAG_KERNEL);
1042
1043 /* Reset the tag to 0xff.*/
1044 ptr = set_tag(ptr, KASAN_TAG_KERNEL);
1045
1046 /* This access shouldn't trigger a KASAN report. */
1047 *ptr = 0;
1048
1049 /* Recover the pointer tag and free. */
1050 ptr = set_tag(ptr, tag);
1051 kfree(ptr);
1052}
1053
1054/* Check that there are no match-all memory tags for tag-based modes. */
1055static void match_all_mem_tag(struct kunit *test)
1056{
1057 char *ptr;
1058 int tag;
1059
1060 KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_KASAN_GENERIC);
1061
1062 ptr = kmalloc(128, GFP_KERNEL);
1063 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
1064 KUNIT_EXPECT_NE(test, (u8)get_tag(ptr), (u8)KASAN_TAG_KERNEL);
1065
1066 /* For each possible tag value not matching the pointer tag. */
1067 for (tag = KASAN_TAG_MIN; tag <= KASAN_TAG_KERNEL; tag++) {
1068 if (tag == get_tag(ptr))
1069 continue;
1070
1071 /* Mark the first memory granule with the chosen memory tag. */
Andrey Konovalovaa5c2192021-04-29 22:59:59 -07001072 kasan_poison(ptr, KASAN_GRANULE_SIZE, (u8)tag, false);
Andrey Konovalov573a4802021-02-24 12:05:21 -08001073
1074 /* This access must cause a KASAN report. */
1075 KUNIT_EXPECT_KASAN_FAIL(test, *ptr = 0);
1076 }
1077
1078 /* Recover the memory tag and free. */
Andrey Konovalovaa5c2192021-04-29 22:59:59 -07001079 kasan_poison(ptr, KASAN_GRANULE_SIZE, get_tag(ptr), false);
Andrey Konovalov573a4802021-02-24 12:05:21 -08001080 kfree(ptr);
1081}
1082
Patricia Alfonso73228c72020-10-13 16:55:06 -07001083static struct kunit_case kasan_kunit_test_cases[] = {
1084 KUNIT_CASE(kmalloc_oob_right),
1085 KUNIT_CASE(kmalloc_oob_left),
1086 KUNIT_CASE(kmalloc_node_oob_right),
1087 KUNIT_CASE(kmalloc_pagealloc_oob_right),
1088 KUNIT_CASE(kmalloc_pagealloc_uaf),
1089 KUNIT_CASE(kmalloc_pagealloc_invalid_free),
Andrey Konovalov858bdeb2021-02-24 12:05:55 -08001090 KUNIT_CASE(pagealloc_oob_right),
1091 KUNIT_CASE(pagealloc_uaf),
Patricia Alfonso73228c72020-10-13 16:55:06 -07001092 KUNIT_CASE(kmalloc_large_oob_right),
Andrey Konovalovb87c28b92021-02-25 17:20:15 -08001093 KUNIT_CASE(krealloc_more_oob),
1094 KUNIT_CASE(krealloc_less_oob),
1095 KUNIT_CASE(krealloc_pagealloc_more_oob),
1096 KUNIT_CASE(krealloc_pagealloc_less_oob),
Andrey Konovalov26a5ca72021-02-25 17:20:19 -08001097 KUNIT_CASE(krealloc_uaf),
Patricia Alfonso73228c72020-10-13 16:55:06 -07001098 KUNIT_CASE(kmalloc_oob_16),
Andrey Konovalov58b999d2020-11-01 17:07:37 -08001099 KUNIT_CASE(kmalloc_uaf_16),
Patricia Alfonso73228c72020-10-13 16:55:06 -07001100 KUNIT_CASE(kmalloc_oob_in_memset),
1101 KUNIT_CASE(kmalloc_oob_memset_2),
1102 KUNIT_CASE(kmalloc_oob_memset_4),
1103 KUNIT_CASE(kmalloc_oob_memset_8),
1104 KUNIT_CASE(kmalloc_oob_memset_16),
1105 KUNIT_CASE(kmalloc_memmove_invalid_size),
1106 KUNIT_CASE(kmalloc_uaf),
1107 KUNIT_CASE(kmalloc_uaf_memset),
1108 KUNIT_CASE(kmalloc_uaf2),
1109 KUNIT_CASE(kfree_via_page),
1110 KUNIT_CASE(kfree_via_phys),
1111 KUNIT_CASE(kmem_cache_oob),
Andrey Konovalov11516132021-02-24 12:05:59 -08001112 KUNIT_CASE(kmem_cache_accounted),
1113 KUNIT_CASE(kmem_cache_bulk),
Patricia Alfonso73228c72020-10-13 16:55:06 -07001114 KUNIT_CASE(kasan_global_oob),
1115 KUNIT_CASE(kasan_stack_oob),
1116 KUNIT_CASE(kasan_alloca_oob_left),
1117 KUNIT_CASE(kasan_alloca_oob_right),
1118 KUNIT_CASE(ksize_unpoisons_memory),
Andrey Konovalov611806b2021-02-24 12:05:50 -08001119 KUNIT_CASE(ksize_uaf),
Patricia Alfonso73228c72020-10-13 16:55:06 -07001120 KUNIT_CASE(kmem_cache_double_free),
1121 KUNIT_CASE(kmem_cache_invalid_free),
1122 KUNIT_CASE(kasan_memchr),
1123 KUNIT_CASE(kasan_memcmp),
1124 KUNIT_CASE(kasan_strings),
Andrey Konovalov58b999d2020-11-01 17:07:37 -08001125 KUNIT_CASE(kasan_bitops_generic),
1126 KUNIT_CASE(kasan_bitops_tags),
Patricia Alfonso73228c72020-10-13 16:55:06 -07001127 KUNIT_CASE(kmalloc_double_kzfree),
1128 KUNIT_CASE(vmalloc_oob),
Andrey Konovalov573a4802021-02-24 12:05:21 -08001129 KUNIT_CASE(match_all_not_assigned),
1130 KUNIT_CASE(match_all_ptr_tag),
1131 KUNIT_CASE(match_all_mem_tag),
Patricia Alfonso73228c72020-10-13 16:55:06 -07001132 {}
1133};
Walter Wu387d6e42020-08-06 23:24:42 -07001134
Patricia Alfonso73228c72020-10-13 16:55:06 -07001135static struct kunit_suite kasan_kunit_test_suite = {
1136 .name = "kasan",
1137 .init = kasan_test_init,
1138 .test_cases = kasan_kunit_test_cases,
1139 .exit = kasan_test_exit,
1140};
Walter Wu387d6e42020-08-06 23:24:42 -07001141
Patricia Alfonso73228c72020-10-13 16:55:06 -07001142kunit_test_suite(kasan_kunit_test_suite);
Walter Wu387d6e42020-08-06 23:24:42 -07001143
Andrey Ryabinin3f158012015-02-13 14:39:53 -08001144MODULE_LICENSE("GPL");