diff --git a/01-Debug/01-Panic/test_ps.c b/01-Debug/01-Panic/test_ps.c index b70c4c948..e016bba68 100644 --- a/01-Debug/01-Panic/test_ps.c +++ b/01-Debug/01-Panic/test_ps.c @@ -20,6 +20,31 @@ static int trigger_oops(void) return 0; } +static int trigger_oob(void) { + char *buffer; + int *out_of_bounds; + + printk(KERN_INFO "Out-of-bounds memory access test module loaded\n"); + + // Allocate a small buffer +// buffer = kmalloc(256, GFP_KERNEL); + buffer = vmalloc(PAGE_SIZE * 2); + if (!buffer) { + printk(KERN_ERR "Failed to allocate memory\n"); + return -ENOMEM; + } + + // Attempt to access memory out of bounds + out_of_bounds = (int *)(buffer + PAGE_SIZE * 3); // Move pointer to the end of the buffer + *out_of_bounds = 0; // This should cause an out-of-bounds write + + printk(KERN_INFO "Out-of-bounds Ofst[%lu] memory access performed\n", 256 + PAGE_SIZE); + + kfree(buffer); + + return 0; +} + static int trigger_oom(void) { void *memory = NULL; @@ -122,6 +147,8 @@ static int trigger_init(void) { trigger_rcu(); else if (test_type == 3) trigger_deadlock(); + else if (test_type == 4) + trigger_oob(); return 0; // 加载模块不应该有返回值,但这里返回0避免编译警告。 } diff --git a/Makefile b/Makefile index 3d4b7d55a..ca710d2dd 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ INSTALL_DIR ?= $(LOCAL_DIR)/__install #******************************************************************************* MULTI_CORES ?= $(shell grep -c ^processor /proc/cpuinfo) -SUB_DIRS := 01-Debug/ +SUB_DIRS := spi 01-Debug #******************************************************************************* # Compile configure