[Add] 新增“内存访问越界”导致内核报错:Segmentation fault
This commit is contained in:
@ -20,6 +20,31 @@ static int trigger_oops(void)
|
|||||||
return 0;
|
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)
|
static int trigger_oom(void)
|
||||||
{
|
{
|
||||||
void *memory = NULL;
|
void *memory = NULL;
|
||||||
@ -122,6 +147,8 @@ static int trigger_init(void) {
|
|||||||
trigger_rcu();
|
trigger_rcu();
|
||||||
else if (test_type == 3)
|
else if (test_type == 3)
|
||||||
trigger_deadlock();
|
trigger_deadlock();
|
||||||
|
else if (test_type == 4)
|
||||||
|
trigger_oob();
|
||||||
|
|
||||||
return 0; // 加载模块不应该有返回值,但这里返回0避免编译警告。
|
return 0; // 加载模块不应该有返回值,但这里返回0避免编译警告。
|
||||||
}
|
}
|
||||||
|
|||||||
2
Makefile
2
Makefile
@ -24,7 +24,7 @@ INSTALL_DIR ?= $(LOCAL_DIR)/__install
|
|||||||
#*******************************************************************************
|
#*******************************************************************************
|
||||||
MULTI_CORES ?= $(shell grep -c ^processor /proc/cpuinfo)
|
MULTI_CORES ?= $(shell grep -c ^processor /proc/cpuinfo)
|
||||||
|
|
||||||
SUB_DIRS := 01-Debug/
|
SUB_DIRS := spi 01-Debug
|
||||||
|
|
||||||
#*******************************************************************************
|
#*******************************************************************************
|
||||||
# Compile configure
|
# Compile configure
|
||||||
|
|||||||
Reference in New Issue
Block a user