GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fgetpriority_NEXT/kernel/routine_raw.c at master · CKAndroidProject/fgetpriority_NEXT

Expand file tree

/

routine_raw.c

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
180 lines (145 loc) · 4.76 KB
/

routine_raw.c

Copy path

File metadata and controls

180 lines (145 loc) · 4.76 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (C) 2026 \xx
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
*/
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpragmas"
#pragma GCC diagnostic ignored "-Winfinite-recursion"
#if defined(__GNUC__) && !defined(__clang__)
#define KEEP_SYMBOL_NO_TAIL __attribute__((used)) noinline __attribute__((optimize("no-optimize-sibling-calls")))
#else
#define KEEP_SYMBOL_NO_TAIL __attribute__((used)) noinline __attribute__((disable_tail_calls))
#endif
#ifdef MODULE /* stub for free_uid() */
__asm__ (
"\n .text "
"\n .p2align 2 "
"\n .global gp_free_uid "
"\n gp_free_uid: "
"\n brk #1 "
);
KEEP_SYMBOL_NO_TAIL void gp_free_uid(struct user_struct *up);
#else /* ! MODULE */
extern void free_uid(struct user_struct *);
#define gp_free_uid free_uid
#endif /* ! MODULE */
KEEP_SYMBOL_NO_TAIL struct user_struct *gphook_find_user(kuid_t uid)
{
// we can actually return early if we want to
// but, this makes sure everything does the same work.
struct user_struct *ret = gphook_find_user(uid);
if (getpriority_should_swap(*(int *)&uid)) {
gp_free_uid(ret);
return nullptr;
}
return ret;
}
#pragma GCC diagnostic pop
#undef KEEP_SYMBOL_NO_TAIL
#define estimate_sz (256 * 4)
#ifdef CONFIG_MODULES
#define kernel_function_lookup(name) kallsyms_lookup_name(#name)
#else
#define kernel_function_lookup(name) ({ \
pr_info("kernel_function_lookup: %s addr: 0x%lx\n", #name, (uintptr_t)&name); \
(uintptr_t)&name; \
})
#endif
#define self_patch_hook(hook_fn, tgt) ({ \
uintptr_t hook_p = kernel_function_lookup(hook_fn); \
int ret = arm64_b_or_bl_patch(hook_p, get_ksym_size(hook_p, estimate_sz), hook_p, tgt); \
pr_info("patch_hook: %s ret: %d \n", #hook_fn, ret); \
ret; \
})
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 17, 0)
#define syscall_lookup(name) kallsyms_lookup_name("__arm64_" name)
#else
#define syscall_lookup(name) kallsyms_lookup_name(name)
#endif
static __init int getpriority_hook_init(void)
{
uintptr_t symbol_addr = kallsyms_lookup_name("find_user");
if (!symbol_addr)
return -ENOENT;
int ret = self_patch_hook(gphook_find_user, symbol_addr);
if (ret)
return ret;
#ifdef MODULE
uintptr_t symbol_addr2 = kallsyms_lookup_name("free_uid");
if (!symbol_addr2)
return -ENOENT;
uintptr_t gphook_find_user_p = kallsyms_lookup_name("gphook_find_user");
if (!gphook_find_user_p)
return -ENOENT;
ret = arm64_b_or_bl_patch(gphook_find_user_p, get_ksym_size(gphook_find_user_p, estimate_sz), kernel_function_lookup(gp_free_uid), (uintptr_t)symbol_addr2);
if (ret)
return ret;
#endif
// now patch callsites
uintptr_t callsite = syscall_lookup("sys_getpriority");
if (!callsite)
return -ENOENT;
ret = arm64_b_or_bl_patch(callsite, get_ksym_size(callsite, estimate_sz), symbol_addr, (uintptr_t)&gphook_find_user);
if (ret)
return ret;
callsite = syscall_lookup("sys_setpriority");
if (!callsite)
return -ENOENT;
ret = arm64_b_or_bl_patch(callsite, get_ksym_size(callsite, estimate_sz), symbol_addr, (uintptr_t)&gphook_find_user);
if (ret)
return ret;
callsite = syscall_lookup("sys_ioprio_set");
if (!callsite)
return -ENOENT;
ret = arm64_b_or_bl_patch(callsite, get_ksym_size(callsite, estimate_sz), symbol_addr, (uintptr_t)&gphook_find_user);
if (ret)
return ret;
callsite = syscall_lookup("sys_ioprio_get");
if (!callsite)
return -ENOENT;
ret = arm64_b_or_bl_patch(callsite, get_ksym_size(callsite, estimate_sz), symbol_addr, (uintptr_t)&gphook_find_user);
if (ret)
return ret;
pr_info("%s: ok! \n", __func__);
return ret;
}
static int getpriority_hook_exit(void)
{
uintptr_t symbol_addr = kallsyms_lookup_name("find_user");
if (!symbol_addr)
return -ENOENT;
uintptr_t hook_addr = (uintptr_t)&gphook_find_user;
if (!hook_addr)
return -ENOENT;
// restore callsites
uintptr_t callsite = syscall_lookup("sys_getpriority");
if (!callsite)
return -ENOENT;
int ret = arm64_b_or_bl_patch(callsite, get_ksym_size(callsite, estimate_sz), hook_addr, symbol_addr);
if (ret)
return ret;
callsite = syscall_lookup("sys_setpriority");
if (!callsite)
return -ENOENT;
ret = arm64_b_or_bl_patch(callsite, get_ksym_size(callsite, estimate_sz), hook_addr, symbol_addr);
if (ret)
return ret;
callsite = syscall_lookup("sys_ioprio_set");
if (!callsite)
return -ENOENT;
ret = arm64_b_or_bl_patch(callsite, get_ksym_size(callsite, estimate_sz), hook_addr, symbol_addr);
if (ret)
return ret;
callsite = syscall_lookup("sys_ioprio_get");
if (!callsite)
return -ENOENT;
ret = arm64_b_or_bl_patch(callsite, get_ksym_size(callsite, estimate_sz), hook_addr, symbol_addr);
if (ret)
return ret;
return 0;
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.