@@ -131,6 +131,7 @@ static void kmalloc_oob_right(struct kunit *test)
131
131
ptr = kmalloc (size , GFP_KERNEL );
132
132
KUNIT_ASSERT_NOT_ERR_OR_NULL (test , ptr );
133
133
134
+ OPTIMIZER_HIDE_VAR (ptr );
134
135
/*
135
136
* An unaligned access past the requested kmalloc size.
136
137
* Only generic KASAN can precisely detect these.
@@ -159,6 +160,7 @@ static void kmalloc_oob_left(struct kunit *test)
159
160
ptr = kmalloc (size , GFP_KERNEL );
160
161
KUNIT_ASSERT_NOT_ERR_OR_NULL (test , ptr );
161
162
163
+ OPTIMIZER_HIDE_VAR (ptr );
162
164
KUNIT_EXPECT_KASAN_FAIL (test , * ptr = * (ptr - 1 ));
163
165
kfree (ptr );
164
166
}
@@ -171,6 +173,7 @@ static void kmalloc_node_oob_right(struct kunit *test)
171
173
ptr = kmalloc_node (size , GFP_KERNEL , 0 );
172
174
KUNIT_ASSERT_NOT_ERR_OR_NULL (test , ptr );
173
175
176
+ OPTIMIZER_HIDE_VAR (ptr );
174
177
KUNIT_EXPECT_KASAN_FAIL (test , ptr [0 ] = ptr [size ]);
175
178
kfree (ptr );
176
179
}
@@ -191,6 +194,7 @@ static void kmalloc_pagealloc_oob_right(struct kunit *test)
191
194
ptr = kmalloc (size , GFP_KERNEL );
192
195
KUNIT_ASSERT_NOT_ERR_OR_NULL (test , ptr );
193
196
197
+ OPTIMIZER_HIDE_VAR (ptr );
194
198
KUNIT_EXPECT_KASAN_FAIL (test , ptr [size + OOB_TAG_OFF ] = 0 );
195
199
196
200
kfree (ptr );
@@ -271,6 +275,7 @@ static void kmalloc_large_oob_right(struct kunit *test)
271
275
ptr = kmalloc (size , GFP_KERNEL );
272
276
KUNIT_ASSERT_NOT_ERR_OR_NULL (test , ptr );
273
277
278
+ OPTIMIZER_HIDE_VAR (ptr );
274
279
KUNIT_EXPECT_KASAN_FAIL (test , ptr [size ] = 0 );
275
280
kfree (ptr );
276
281
}
@@ -410,6 +415,8 @@ static void kmalloc_oob_16(struct kunit *test)
410
415
ptr2 = kmalloc (sizeof (* ptr2 ), GFP_KERNEL );
411
416
KUNIT_ASSERT_NOT_ERR_OR_NULL (test , ptr2 );
412
417
418
+ OPTIMIZER_HIDE_VAR (ptr1 );
419
+ OPTIMIZER_HIDE_VAR (ptr2 );
413
420
KUNIT_EXPECT_KASAN_FAIL (test , * ptr1 = * ptr2 );
414
421
kfree (ptr1 );
415
422
kfree (ptr2 );
@@ -756,6 +763,8 @@ static void ksize_unpoisons_memory(struct kunit *test)
756
763
KUNIT_ASSERT_NOT_ERR_OR_NULL (test , ptr );
757
764
real_size = ksize (ptr );
758
765
766
+ OPTIMIZER_HIDE_VAR (ptr );
767
+
759
768
/* This access shouldn't trigger a KASAN report. */
760
769
ptr [size ] = 'x' ;
761
770
@@ -778,6 +787,7 @@ static void ksize_uaf(struct kunit *test)
778
787
KUNIT_ASSERT_NOT_ERR_OR_NULL (test , ptr );
779
788
kfree (ptr );
780
789
790
+ OPTIMIZER_HIDE_VAR (ptr );
781
791
KUNIT_EXPECT_KASAN_FAIL (test , ksize (ptr ));
782
792
KUNIT_EXPECT_KASAN_FAIL (test , ((volatile char * )ptr )[0 ]);
783
793
KUNIT_EXPECT_KASAN_FAIL (test , ((volatile char * )ptr )[size ]);
0 commit comments