@@ -12,6 +12,7 @@
#include <linux/printk.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
+#include <linux/delay.h>
#include "../mm/kasan/kasan.h"
@@ -91,6 +92,29 @@ static noinline void __init kasan_rcu_uaf(void)
call_rcu(&global_rcu_ptr->rcu, kasan_rcu_reclaim);
}
+static noinline void __init kasan_timer_function(struct timer_list *timer)
+{
+ del_timer(timer);
+ kfree(timer);
+}
+
+static noinline void __init kasan_timer_uaf(void)
+{
+ struct timer_list *timer;
+
+ timer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
+ if (!timer) {
+ pr_err("Allocation failed\n");
+ return;
+ }
+
+ timer_setup(timer, kasan_timer_function, 0);
+ add_timer(timer);
+ msleep(100);
+
+ pr_info("use-after-free on timer\n");
+ ((volatile struct timer_list *)timer)->expires;
+}
static int __init test_kasan_module_init(void)
{
@@ -102,6 +126,7 @@ static int __init test_kasan_module_init(void)
copy_user_test();
kasan_rcu_uaf();
+ kasan_timer_uaf();
kasan_restore_multi_shot(multishot);
return -EAGAIN;