corCTF2022-cache of castaways

corCTF2022-cache of castaways 题目复现

漏洞分析

给了模块的源码,可以直接找到漏洞:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#define OVERFLOW_SZ 0x6
#define CHUNK_SIZE 512

typedef struct
{
char pad[OVERFLOW_SZ];
char buf[];
}castaway_t;

static long castaway_edit(int64_t idx, uint64_t size, char *buf)
{
char temp[CHUNK_SIZE];
if (idx < 0 || idx >= MAX || !castaway_arr[idx])
{
goto edit_fail;
}
if (size > CHUNK_SIZE || copy_from_user(temp, buf, size))
{
goto edit_fail;
}
memcpy(castaway_arr[idx]->buf, temp, size);

return size;
···
}

整个模块包含两个 ioctl 模块,一个是 add,一个是 edit,edit 存在一个 6 字节的溢出。那利用的地方就是这里了。

Cross-Cache

漏洞利用

其他

参考文章

  1. Linux kernel heap feng shui in 2022 - Michael S, Vitaly Nikolenko (duasynt.com)