@@ -215,6 +215,36 @@ static void kmalloc_node_oob_right(struct kunit *test)
215
215
kfree (ptr );
216
216
}
217
217
218
+ static void kmalloc_track_caller_oob_right (struct kunit * test )
219
+ {
220
+ char * ptr ;
221
+ size_t size = 128 - KASAN_GRANULE_SIZE ;
222
+
223
+ /*
224
+ * Check that KASAN detects out-of-bounds access for object allocated via
225
+ * kmalloc_track_caller().
226
+ */
227
+ ptr = kmalloc_track_caller (size , GFP_KERNEL );
228
+ KUNIT_ASSERT_NOT_ERR_OR_NULL (test , ptr );
229
+
230
+ OPTIMIZER_HIDE_VAR (ptr );
231
+ KUNIT_EXPECT_KASAN_FAIL (test , ptr [size ] = 'y' );
232
+
233
+ kfree (ptr );
234
+
235
+ /*
236
+ * Check that KASAN detects out-of-bounds access for object allocated via
237
+ * kmalloc_node_track_caller().
238
+ */
239
+ ptr = kmalloc_node_track_caller (size , GFP_KERNEL , 0 );
240
+ KUNIT_ASSERT_NOT_ERR_OR_NULL (test , ptr );
241
+
242
+ OPTIMIZER_HIDE_VAR (ptr );
243
+ KUNIT_EXPECT_KASAN_FAIL (test , ptr [size ] = 'y' );
244
+
245
+ kfree (ptr );
246
+ }
247
+
218
248
/*
219
249
* Check that KASAN detects an out-of-bounds access for a big object allocated
220
250
* via kmalloc(). But not as big as to trigger the page_alloc fallback.
@@ -2015,6 +2045,7 @@ static struct kunit_case kasan_kunit_test_cases[] = {
2015
2045
KUNIT_CASE (kmalloc_oob_right ),
2016
2046
KUNIT_CASE (kmalloc_oob_left ),
2017
2047
KUNIT_CASE (kmalloc_node_oob_right ),
2048
+ KUNIT_CASE (kmalloc_track_caller_oob_right ),
2018
2049
KUNIT_CASE (kmalloc_big_oob_right ),
2019
2050
KUNIT_CASE (kmalloc_large_oob_right ),
2020
2051
KUNIT_CASE (kmalloc_large_uaf ),
0 commit comments