From c4510ef554ef4441f5fdd654536b7805c2f1057a Mon Sep 17 00:00:00 2001 From: gaoyang3513 Date: Mon, 14 Oct 2024 15:53:47 +0800 Subject: [PATCH] =?UTF-8?q?[Add]=20=E6=96=B0=E5=A2=9E=E2=80=9C=E5=86=85?= =?UTF-8?q?=E5=AD=98=E8=AE=BF=E9=97=AE=E8=B6=8A=E7=95=8C=E2=80=9D=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E5=86=85=E6=A0=B8=E6=8A=A5=E9=94=99=EF=BC=9ASegmentat?= =?UTF-8?q?ion=20fault?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 01-Debug/01-Panic/test_ps.c | 27 +++++++++++++++++++++++++++ Makefile | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) 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