Skip to content

Commit 9886aa7

Browse files
support 6.12 (#210)
* make kernel 6.12 bootup * fist try safe systemcall * Update version
1 parent 566c2dc commit 9886aa7

File tree

9 files changed

+79
-7
lines changed

9 files changed

+79
-7
lines changed

kernel/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LD = $(TARGET_COMPILE)ld
99
AS = $(TARGET_COMPILE)as
1010
OBJCOPY = $(TARGET_COMPILE)objcopy
1111

12-
CFLAGS += -Wall -fno-builtin -std=gnu11 -nostdinc
12+
CFLAGS += -Wall -fno-builtin -std=gnu11 -nostdinc -mgeneral-regs-only
1313
CFLAGS += -g
1414

1515
ifdef DEBUG

kernel/base/baselib.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,11 @@ char *lib_strstr(const char *haystack, const char *needle)
345345
{
346346
return (char *)lib_memmem(haystack, lib_strlen(haystack), needle, lib_strlen(needle));
347347
}
348+
349+
void *memset(void *s, int c, size_t n) {
350+
unsigned char *p = s;
351+
while (n--) {
352+
*p++ = (unsigned char)c;
353+
}
354+
return s;
355+
}

kernel/linux/include/linux/vmalloc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ extern void *kfunc_def(vm_map_ram)(struct page **pages, unsigned int count, int
6464
extern void kfunc_def(vm_unmap_aliases)(void);
6565

6666
extern void *kfunc_def(vmalloc)(unsigned long size);
67+
extern void *kfunc_def(vmalloc_noprof)(unsigned long size);
6768
extern void *kfunc_def(vzalloc)(unsigned long size);
6869
extern void *kfunc_def(vmalloc_user)(unsigned long size);
6970
extern void *kfunc_def(vmalloc_node)(unsigned long size, int node);
@@ -121,6 +122,7 @@ static inline void vm_unmap_aliases(void)
121122
static inline void *vmalloc(unsigned long size)
122123
{
123124
kfunc_call(vmalloc, size);
125+
kfunc_call(vmalloc_noprof, size);
124126
kfunc_not_found();
125127
return 0;
126128
}

kernel/patch/common/utils.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ int __must_check compat_copy_to_user(void __user *to, const void *from, int n)
7575
{
7676
int cplen = 0;
7777

78-
if (kfunc(seq_buf_to_user)) {
79-
cplen = seq_buf_copy_to_user(to, from, n);
80-
} else if (kfunc(xt_data_to_user)) {
78+
if (kfunc(xt_data_to_user)) {
8179
// xt_data_to_user, xt_obj_to_user
8280
cplen = compat_xt_data_copy_to_user(to, from, n);
8381
if (!cplen) cplen = n;
82+
} else if (kfunc(seq_buf_to_user)) {
83+
cplen = seq_buf_copy_to_user(to, from, n);
8484
} else if (kfunc(bits_to_user)) {
8585
// bits_to_user, str_to_user
8686
cplen = compat_bits_copy_to_user(to, from, n);
@@ -98,6 +98,8 @@ KP_EXPORT_SYMBOL(compat_copy_to_user);
9898

9999
long compat_strncpy_from_user(char *dest, const char __user *src, long count)
100100
{
101+
kfunc_call(strncpy_from_user_nofault, dest, src, count);
102+
kfunc_call(strncpy_from_unsafe_user, dest, src, count);
101103
if (kfunc(strncpy_from_user)) {
102104
long rc = kfunc(strncpy_from_user)(dest, src, count);
103105
if (rc >= count) {
@@ -108,8 +110,6 @@ long compat_strncpy_from_user(char *dest, const char __user *src, long count)
108110
}
109111
return rc;
110112
}
111-
kfunc_call(strncpy_from_user_nofault, dest, src, count);
112-
kfunc_call(strncpy_from_unsafe_user, dest, src, count);
113113
return 0;
114114
}
115115
KP_EXPORT_SYMBOL(compat_strncpy_from_user);

kernel/patch/ksyms/misc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ void *kfunc_def(vm_map_ram)(struct page **pages, unsigned int count, int node) =
336336
void kfunc_def(vm_unmap_aliases)(void) = 0;
337337

338338
void *kfunc_def(vmalloc)(unsigned long size) = 0;
339+
void *kfunc_def(vmalloc_noprof)(unsigned long size) = 0;
339340
void *kfunc_def(vzalloc)(unsigned long size) = 0;
340341
void *kfunc_def(vmalloc_user)(unsigned long size) = 0;
341342
void *kfunc_def(vmalloc_node)(unsigned long size, int node) = 0;
@@ -383,6 +384,7 @@ static void _linux_mm_vmalloc_sym_match(const char *name, unsigned long addr)
383384
// kfunc_match(vm_unmap_aliases, name, addr);
384385

385386
kfunc_match(vmalloc, name, addr);
387+
kfunc_match(vmalloc_noprof, name, addr);
386388
kfunc_match(vzalloc, name, addr);
387389
// kfunc_match(vmalloc_user, name, addr);
388390
// kfunc_match(vmalloc_node, name, addr);

tools/kallsym.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,39 @@ static int find_linux_banner(kallsym_t *info, char *img, int32_t imglen)
8585
return 0;
8686
}
8787

88+
int kernel_if_need_patch(kallsym_t *info, char *img, int32_t imglen)
89+
{
90+
char linux_banner_prefix[] = "Linux version ";
91+
size_t prefix_len = strlen(linux_banner_prefix);
92+
93+
char *imgend = img + imglen;
94+
char *banner = (char *)img;
95+
info->banner_num = 0;
96+
while ((banner = (char *)memmem(banner + 1, imgend - banner - 1, linux_banner_prefix, prefix_len)) != NULL) {
97+
if (isdigit(*(banner + prefix_len)) && *(banner + prefix_len + 1) == '.') {
98+
info->linux_banner_offset[info->banner_num++] = (int32_t)(banner - img);
99+
}
100+
}
101+
banner = img + info->linux_banner_offset[info->banner_num - 1];
102+
103+
char *uts_release_start = banner + prefix_len;
104+
char *space = strchr(banner + prefix_len, ' ');
105+
106+
char *dot = NULL;
107+
108+
// VERSION
109+
info->version.major = (uint8_t)strtoul(uts_release_start, &dot, 10);
110+
// PATCHLEVEL
111+
info->version.minor = (uint8_t)strtoul(dot + 1, &dot, 10);
112+
// SUBLEVEL
113+
int32_t patch = (int32_t)strtoul(dot + 1, &dot, 10);
114+
info->version.patch = patch <= 256 ? patch : 255;
115+
116+
if (info->version.major < 6)return 0;
117+
if (info->version.minor < 7)return 0;
118+
return 1;
119+
}
120+
88121
static int dump_kernel_config(kallsym_t *info, char *img, int32_t imglen)
89122
{
90123
// todo:

tools/kallsym.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ typedef struct
117117

118118
} kallsym_t;
119119

120+
int kernel_if_need_patch(kallsym_t *info, char *img, int32_t imglen);
120121
int analyze_kallsym_info(kallsym_t *info, char *img, int32_t imglen, enum arch_type arch, int32_t is_64);
121122
int dump_all_symbols(kallsym_t *info, char *img);
122123
int dump_all_ikconfig(char *img, int32_t imglen);

tools/patch.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,29 @@ static void extra_append(char *kimg, const void *data, int len, int *offset)
336336
*offset += len;
337337
}
338338

339+
static void disable_pi_map(char *img, int32_t imglen)
340+
{
341+
342+
const unsigned char pattern[] = {
343+
0xE6, 0x03, 0x16, 0xAA,
344+
0xE7, 0x03, 0x1F, 0x2A,
345+
0x34, 0x11, 0x88, 0x9A
346+
};
347+
const size_t pattern_len = sizeof(pattern);
348+
349+
const unsigned char replace[] = {
350+
0xE6, 0x03, 0x16, 0xAA,
351+
0xE7, 0x03, 0x1F, 0x2A,
352+
0xF4, 0x03, 0x09, 0xAA
353+
};
354+
355+
unsigned char *p = memmem(img, imglen, pattern, pattern_len);
356+
if (p) {
357+
memcpy(p, replace, pattern_len);
358+
}
359+
360+
}
361+
339362
int patch_update_img(const char *kimg_path, const char *kpimg_path, const char *out_path, const char *superkey,
340363
bool root_key, const char **additional, extra_config_t *extra_configs, int extra_config_num)
341364
{
@@ -362,6 +385,9 @@ int patch_update_img(const char *kimg_path, const char *kpimg_path, const char *
362385
char *kallsym_kimg = (char *)malloc(pimg.ori_kimg_len);
363386
memcpy(kallsym_kimg, pimg.kimg, pimg.ori_kimg_len);
364387
kallsym_t kallsym = { 0 };
388+
389+
if (kernel_if_need_patch(&kallsym, kallsym_kimg ,pimg.ori_kimg_len))disable_pi_map(kernel_file.kimg, kernel_file.kimg_len);
390+
365391
if (analyze_kallsym_info(&kallsym, kallsym_kimg, pimg.ori_kimg_len, ARM64, 1)) {
366392
tools_loge_exit("analyze_kallsym_info error\n");
367393
}

version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#define MAJOR 0
22
#define MINOR 12
3-
#define PATCH 0
3+
#define PATCH 1

0 commit comments

Comments
 (0)