Skip to content

Commit 008f44b

Browse files
authored
sync KP 11.2 header files
1 parent 32236aa commit 008f44b

15 files changed

Lines changed: 750 additions & 0 deletions

File tree

kernel/patch/include/accctl.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* SPDX-License-Identifier: GPL-2.0-or-later */
2+
/*
3+
* Copyright (C) 2023 bmax121. All Rights Reserved.
4+
*/
5+
6+
#ifndef _KP_ACCCTL_H_
7+
#define _KP_ACCCTL_H_
8+
9+
#include <ktypes.h>
10+
#include <linux/cred.h>
11+
#include <linux/spinlock.h>
12+
#include <linux/sched.h>
13+
#include <uapi/scdefs.h>
14+
#include <pgtable.h>
15+
#include <taskext.h>
16+
#include <asm/current.h>
17+
18+
extern char all_allow_sctx[SUPERCALL_SCONTEXT_LEN];
19+
extern uint32_t all_allow_sid;
20+
21+
int set_all_allow_sctx(const char *sctx);
22+
int commit_kernel_su();
23+
int commit_common_su(uid_t to_uid, const char *sctx);
24+
int commit_su(uid_t uid, const char *sctx);
25+
int task_su(pid_t pid, uid_t to_uid, const char *sctx);
26+
27+
/**
28+
* @brief Whether to make the current task bypass all selinux permission checks.
29+
*
30+
* @param task
31+
* @param val
32+
*/
33+
static inline void set_priv_sel_allow(struct task_struct *task, bool val)
34+
{
35+
struct task_ext *ext = get_task_ext(task);
36+
ext->priv_sel_allow = val;
37+
dsb(ish);
38+
}
39+
40+
#endif

kernel/patch/include/hotpatch.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* SPDX-License-Identifier: GPL-2.0-or-later */
2+
/*
3+
* Copyright (C) 2023 bmax121. All Rights Reserved.
4+
*/
5+
6+
#ifndef _KP_HOTPATCH_H_
7+
#define _KP_HOTPATCH_H_
8+
9+
#include <hook.h>
10+
11+
#endif

kernel/patch/include/kconfig.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* SPDX-License-Identifier: GPL-2.0-or-later */
2+
/*
3+
* Copyright (C) 2023 bmax121. All Rights Reserved.
4+
*/
5+
6+
#ifndef _KP_KCONFIG_H_
7+
#define _KP_KCONFIG_H_
8+
9+
// todo: move config to here
10+
11+
extern bool has_config_compat;
12+
13+
#endif

kernel/patch/include/kputils.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* SPDX-License-Identifier: GPL-2.0-or-later */
2+
/*
3+
* Copyright (C) 2023 bmax121. All Rights Reserved.
4+
*/
5+
6+
#ifndef _KP_UTILS_H_
7+
#define _KP_UTILS_H_
8+
9+
#include <compiler.h>
10+
#include <ktypes.h>
11+
12+
int __must_check compat_copy_to_user(void __user *to, const void *from, int n);
13+
long compat_strncpy_from_user(char *dest, const char __user *src, long count);
14+
void *__user copy_to_user_stack(const void *data, int len);
15+
uid_t current_uid();
16+
uint64_t get_random_u64(void);
17+
18+
void print_bootlog();
19+
20+
#endif

kernel/patch/include/kstorage.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* SPDX-License-Identifier: GPL-2.0-or-later */
2+
/*
3+
* Copyright (C) 2024 bmax121. All Rights Reserved.
4+
*/
5+
6+
#ifndef _KP_KSTORAGE_H_
7+
#define _KP_KSTORAGE_H_
8+
9+
#include <ktypes.h>
10+
#include <uapi/scdefs.h>
11+
#include <stdbool.h>
12+
13+
struct kstorage
14+
{
15+
struct list_head list;
16+
struct rcu_head rcu;
17+
18+
int gid;
19+
long did;
20+
int dlen;
21+
char data[0];
22+
};
23+
24+
int try_alloc_kstroage_group();
25+
26+
int kstorage_group_size(int gid);
27+
28+
int write_kstorage(int gid, long did, void *data, int offset, int len, bool data_is_user);
29+
30+
/// must within rcu read lock
31+
const struct kstorage *get_kstorage(int gid, long did);
32+
33+
typedef int (*on_kstorage_cb)(struct kstorage *kstorage, void *udata);
34+
int on_each_kstorage_elem(int gid, on_kstorage_cb cb, void *udata);
35+
36+
int read_kstorage(int gid, long did, void *data, int offset, int len, bool data_is_user);
37+
38+
int list_kstorage_ids(int gid, long *ids, int idslen, bool data_is_user);
39+
40+
int remove_kstorage(int gid, long did);
41+
42+
#endif

kernel/patch/include/ksyms.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* SPDX-License-Identifier: GPL-2.0-or-later */
2+
/*
3+
* Copyright (C) 2023 bmax121. All Rights Reserved.
4+
*/
5+
6+
#ifndef _KP_KSYMS_H
7+
#define _KP_KSYMS_H
8+
9+
#include <linux/kallsyms.h>
10+
#include <log.h>
11+
12+
#define INIT_USE_KALLSYMS_LOOKUP_NAME
13+
14+
#define KFUNC_POISON 0xdeaddead00000000
15+
16+
#define kvar(var) kv_##var
17+
#define kvar_def(var) (*kv_##var)
18+
#define kvlen(var) kvl_##var
19+
#define kvar_val(var) (*kvar(var))
20+
21+
#define kfunc(func) kf_##func
22+
#define kfunc_def(func) (*kf_##func)
23+
24+
#define kvar_lookup_name(var) kv_##var = (typeof(kv_##var))kallsyms_lookup_name(#var)
25+
#define kfunc_lookup_name(func) kf_##func = (typeof(kf_##func))kallsyms_lookup_name(#func)
26+
27+
#ifdef INIT_USE_KALLSYMS_LOOKUP_NAME
28+
#define kvar_match(var, name, addr) kvar_lookup_name(var)
29+
#define kfunc_match(func, name, addr) kfunc_lookup_name(func)
30+
#define kfunc_match_cfi(func, name, addr) \
31+
kf_##func = (typeof(kf_##func))kallsyms_lookup_name(#func ".cfi_jt"); \
32+
if (!kf_##func) kf_##func = (typeof(kf_##func))kallsyms_lookup_name(#func);
33+
#else
34+
int _ksym_local_strcmp(const char *s1, const char *s2);
35+
#define kvar_match(var, name, addr) \
36+
if (!kv_##var && !_ksym_local_strcmp(#var, name)) kv_##var = (typeof(kv_##var))addr;
37+
#define kfunc_match(func, name, addr) \
38+
if (!kf_##func && !_ksym_local_strcmp(#func, name)) kf_##func = (typeof(kf_##func))addr
39+
#endif
40+
41+
#define kfunc_call(func, ...) \
42+
if (kf_##func) return kf_##func(__VA_ARGS__);
43+
44+
#define kfunc_direct_call(func, ...) return kf_##func(__VA_ARGS__);
45+
46+
#define kfunc_call_void(func, ...) \
47+
if (kf_##func) kf_##func(__VA_ARGS__);
48+
49+
#define kfunc_direct_call_void(func, ...) kf_##func(__VA_ARGS__);
50+
51+
// todo
52+
#define kfunc_not_found() logke("kfunc: %s not found\n", __func__);
53+
54+
#endif

kernel/patch/include/module.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/* SPDX-License-Identifier: GPL-2.0-or-later */
2+
/*
3+
* Copyright (C) 2023 bmax121. All Rights Reserved.
4+
*/
5+
6+
#ifndef _KP_MODULE_H_
7+
#define _KP_MODULE_H_
8+
9+
#include <asm-generic/module.h>
10+
#include <kpmodule.h>
11+
12+
struct load_info
13+
{
14+
struct
15+
{
16+
const char *base;
17+
unsigned long size;
18+
const char *name, *version, *license, *author, *description;
19+
} info;
20+
const Elf_Ehdr *hdr;
21+
unsigned long len;
22+
Elf_Shdr *sechdrs;
23+
char *secstrings, *strtab;
24+
unsigned long symoffs, stroffs;
25+
struct
26+
{
27+
unsigned int sym, str, mod, info;
28+
} index;
29+
};
30+
31+
struct module
32+
{
33+
struct
34+
{
35+
const char *base, *name, *version, *license, *author, *description;
36+
} info;
37+
38+
char *args, *ctl_args;
39+
40+
mod_initcall_t *init;
41+
mod_ctl0call_t *ctl0;
42+
mod_ctl1call_t *ctl1;
43+
mod_exitcall_t *exit;
44+
45+
unsigned int size;
46+
unsigned int text_size;
47+
unsigned int ro_size;
48+
49+
void *start;
50+
51+
struct list_head list;
52+
};
53+
54+
long load_module(const void *data, int len, const char *args, const char *event, void *__user reserved);
55+
long load_module_path(const char *path, const char *args, void *__user reserved);
56+
long module_control0(const char *name, const char *ctl_args, char *__user out_msg, int outlen);
57+
long module_control1(const char *name, void *a1, void *a2, void *a3);
58+
long unload_module(const char *name, void *__user reserved);
59+
struct module *find_module(const char *name);
60+
61+
int get_module_nums();
62+
int list_modules(char *out_names, int size);
63+
int get_module_info(const char *name, char *out_info, int size);
64+
65+
#endif

kernel/patch/include/pidmem.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* SPDX-License-Identifier: GPL-2.0-or-later */
2+
/*
3+
* Copyright (C) 2024 bmax121. All Rights Reserved.
4+
*/
5+
6+
#ifndef _KP_PIDMEM_H_
7+
#define _KP_PIDMEM_H_
8+
9+
#include <ktypes.h>
10+
11+
// phys_addr_t pid_virt_to_phys(pid_t pid, uintptr_t vaddr);
12+
13+
// void *pid_map_mem(pid_t pid, void *mem, size_t size, )
14+
15+
#endif
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* SPDX-License-Identifier: GPL-2.0-or-later */
2+
/*
3+
* Copyright (C) 2024 1f2003d5. All Rights Reserved.
4+
* Copyright (C) 2024 sekaiacg. All Rights Reserved.
5+
*/
6+
7+
#ifndef _KP_SEPOLICY_FLAGS_H_
8+
#define _KP_SEPOLICY_FLAGS_H_
9+
10+
#include <linux/string.h>
11+
12+
#define SELINUX_MAGIC 0xf97cff8c
13+
#define POLICYDB_MAGIC SELINUX_MAGIC
14+
#define POLICYDB_STRING "SE Linux"
15+
16+
#define POLICYDB_CONFIG_MLS 1
17+
#define POLICYDB_CONFIG_ANDROID_NETLINK_ROUTE (1 << 31)
18+
#define POLICYDB_CONFIG_ANDROID_NETLINK_GETNEIGH (1 << 30)
19+
20+
/*
21+
* config offset:
22+
* __le32(POLICYDB_MAGIC) + __le32(POLICYDB_STRING_LEN) +
23+
* char[POLICYDB_STRING_LEN] + __le32(policyvers)
24+
*/
25+
#define POLICYDB_CONFIG_OFFSET (2 * sizeof(__le32) + strlen(POLICYDB_STRING) + sizeof(__le32))
26+
27+
struct _policy_file
28+
{
29+
char *data;
30+
size_t len;
31+
};
32+
33+
struct _policydb
34+
{
35+
int mls_enabled;
36+
int android_netlink_route;
37+
int android_netlink_getneigh;
38+
};
39+
40+
#endif

kernel/patch/include/sucompat.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* SPDX-License-Identifier: GPL-2.0-or-later */
2+
/*
3+
* Copyright (C) 2024 bmax121. All Rights Reserved.
4+
*/
5+
6+
#ifndef _KP_SUCOMPAT_H_
7+
#define _KP_SUCOMPAT_H_
8+
9+
#include <ktypes.h>
10+
#include <uapi/scdefs.h>
11+
#include <hook.h>
12+
13+
extern const char sh_path[];
14+
extern const char default_su_path[];
15+
extern const char legacy_su_path[];
16+
extern const char apd_path[];
17+
18+
struct allow_uid
19+
{
20+
uid_t uid;
21+
struct su_profile profile;
22+
struct list_head list;
23+
struct rcu_head rcu;
24+
};
25+
26+
int is_su_allow_uid(uid_t uid);
27+
int su_add_allow_uid(uid_t uid, uid_t to_uid, const char *scontext);
28+
int su_remove_allow_uid(uid_t uid);
29+
int su_allow_uid_nums();
30+
int su_allow_uids(int is_user, uid_t *out_uids, int out_num);
31+
int su_allow_uid_profile(int is_user, uid_t uid, struct su_profile *profile);
32+
int su_reset_path(const char *path);
33+
const char *su_get_path();
34+
35+
int get_ap_mod_exclude(uid_t uid);
36+
int set_ap_mod_exclude(uid_t uid, int exclude);
37+
int list_ap_mod_exclude(uid_t *uids, int len);
38+
39+
#endif

0 commit comments

Comments
 (0)