@@ -273,8 +273,8 @@ static void lkdtm_HUNG_TASK(void)
273
273
schedule ();
274
274
}
275
275
276
- volatile unsigned int huge = INT_MAX - 2 ;
277
- volatile unsigned int ignored ;
276
+ static volatile unsigned int huge = INT_MAX - 2 ;
277
+ static volatile unsigned int ignored ;
278
278
279
279
static void lkdtm_OVERFLOW_SIGNED (void )
280
280
{
@@ -305,7 +305,7 @@ static void lkdtm_OVERFLOW_UNSIGNED(void)
305
305
ignored = value ;
306
306
}
307
307
308
- /* Intentionally using old-style flex array definition of 1 byte . */
308
+ /* Intentionally using unannotated flex array definition. */
309
309
struct array_bounds_flex_array {
310
310
int one ;
311
311
int two ;
@@ -357,6 +357,46 @@ static void lkdtm_ARRAY_BOUNDS(void)
357
357
pr_expected_config (CONFIG_UBSAN_BOUNDS );
358
358
}
359
359
360
+ struct lkdtm_annotated {
361
+ unsigned long flags ;
362
+ int count ;
363
+ int array [] __counted_by (count );
364
+ };
365
+
366
+ static volatile int fam_count = 4 ;
367
+
368
+ static void lkdtm_FAM_BOUNDS (void )
369
+ {
370
+ struct lkdtm_annotated * inst ;
371
+
372
+ inst = kzalloc (struct_size (inst , array , fam_count + 1 ), GFP_KERNEL );
373
+ if (!inst ) {
374
+ pr_err ("FAIL: could not allocate test struct!\n" );
375
+ return ;
376
+ }
377
+
378
+ inst -> count = fam_count ;
379
+ pr_info ("Array access within bounds ...\n" );
380
+ inst -> array [1 ] = fam_count ;
381
+ ignored = inst -> array [1 ];
382
+
383
+ pr_info ("Array access beyond bounds ...\n" );
384
+ inst -> array [fam_count ] = fam_count ;
385
+ ignored = inst -> array [fam_count ];
386
+
387
+ kfree (inst );
388
+
389
+ pr_err ("FAIL: survived access of invalid flexible array member index!\n" );
390
+
391
+ if (!__has_attribute (__counted_by__ ))
392
+ pr_warn ("This is expected since this %s was built a compiler supporting __counted_by\n" ,
393
+ lkdtm_kernel_info );
394
+ else if (IS_ENABLED (CONFIG_UBSAN_BOUNDS ))
395
+ pr_expected_config (CONFIG_UBSAN_TRAP );
396
+ else
397
+ pr_expected_config (CONFIG_UBSAN_BOUNDS );
398
+ }
399
+
360
400
static void lkdtm_CORRUPT_LIST_ADD (void )
361
401
{
362
402
/*
@@ -616,6 +656,7 @@ static struct crashtype crashtypes[] = {
616
656
CRASHTYPE (OVERFLOW_SIGNED ),
617
657
CRASHTYPE (OVERFLOW_UNSIGNED ),
618
658
CRASHTYPE (ARRAY_BOUNDS ),
659
+ CRASHTYPE (FAM_BOUNDS ),
619
660
CRASHTYPE (CORRUPT_LIST_ADD ),
620
661
CRASHTYPE (CORRUPT_LIST_DEL ),
621
662
CRASHTYPE (STACK_GUARD_PAGE_LEADING ),
0 commit comments