Skip to content

Commit 3232e28

Browse files
KOWX712backslashxx
authored andcommitted
kernel: extras: add avc spoof to feature
rebase of: KOWX712@4b6f76d
1 parent db39be6 commit 3232e28

File tree

3 files changed

+75
-5
lines changed

3 files changed

+75
-5
lines changed

kernel/extras.c

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <linux/security.h>
22
#include <linux/atomic.h>
33

4+
#include "feature.h"
45
#include "klog.h"
56
#include "ksud.h"
67
#include "kernel_compat.h"
@@ -16,6 +17,49 @@ static u32 kernel_sid = 0;
1617
// init as disabled by default
1718
static atomic_t disable_spoof = ATOMIC_INIT(1);
1819

20+
void ksu_avc_spoof_enable();
21+
void ksu_avc_spoof_disable();
22+
23+
static bool ksu_avc_spoof_enabled = true;
24+
static bool boot_completed = false;
25+
26+
static int avc_spoof_feature_get(u64 *value)
27+
{
28+
*value = ksu_avc_spoof_enabled ? 1 : 0;
29+
return 0;
30+
}
31+
32+
static int avc_spoof_feature_set(u64 value)
33+
{
34+
bool enable = value != 0;
35+
36+
if (enable == ksu_avc_spoof_enabled) {
37+
pr_info("avc_spoof: no need to change\n");
38+
return 0;
39+
}
40+
41+
ksu_avc_spoof_enabled = enable;
42+
43+
if (boot_completed) {
44+
if (enable) {
45+
ksu_avc_spoof_enable();
46+
} else {
47+
ksu_avc_spoof_disable();
48+
}
49+
}
50+
51+
pr_info("avc_spoof: set to %d\n", enable);
52+
53+
return 0;
54+
}
55+
56+
static const struct ksu_feature_handler avc_spoof_handler = {
57+
.feature_id = KSU_FEATURE_AVC_SPOOF,
58+
.name = "avc_spoof",
59+
.get_handler = avc_spoof_feature_get,
60+
.set_handler = avc_spoof_feature_set,
61+
};
62+
1963
static int get_sid()
2064
{
2165
// dont load at all if we cant get sids
@@ -115,7 +159,7 @@ static void destroy_kprobe(struct kprobe **kp_ptr)
115159
}
116160
#endif // CONFIG_KPROBES
117161

118-
void avc_spoof_exit(void)
162+
void ksu_avc_spoof_disable(void)
119163
{
120164
#ifdef CONFIG_KPROBES
121165
pr_info("avc_spoof/exit: unregister slow_avc_audit kprobe!\n");
@@ -125,7 +169,7 @@ void avc_spoof_exit(void)
125169
pr_info("avc_spoof/exit: slow_avc_audit spoofing disabled!\n");
126170
}
127171

128-
void avc_spoof_init(void)
172+
void ksu_avc_spoof_enable(void)
129173
{
130174
int ret = get_sid();
131175
if (ret) {
@@ -142,3 +186,25 @@ void avc_spoof_init(void)
142186

143187
pr_info("avc_spoof/init: slow_avc_audit spoofing enabled!\n");
144188
}
189+
190+
void ksu_avc_spoof_init()
191+
{
192+
boot_completed = true;
193+
194+
if (ksu_avc_spoof_enabled) {
195+
ksu_avc_spoof_enable();
196+
}
197+
198+
199+
if (ksu_register_feature_handler(&avc_spoof_handler)) {
200+
pr_err("Failed to register avc spoof feature handler\n");
201+
}
202+
}
203+
204+
void ksu_avc_spoof_exit()
205+
{
206+
if (ksu_avc_spoof_enabled) {
207+
ksu_avc_spoof_disable();
208+
}
209+
ksu_unregister_feature_handler(KSU_FEATURE_AVC_SPOOF);
210+
}

kernel/feature.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ enum ksu_feature_id {
88
KSU_FEATURE_KERNEL_UMOUNT = 1,
99
KSU_FEATURE_ENHANCED_SECURITY = 2,
1010

11+
#ifdef CONFIG_KSU_EXTRAS // custom extensions
12+
KSU_FEATURE_AVC_SPOOF = 10003,
13+
#endif
14+
1115
KSU_FEATURE_MAX
1216
};
1317

kernel/ksud.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ bool ksu_module_mounted __read_mostly = false;
3535
bool ksu_boot_completed __read_mostly = false;
3636

3737
#ifdef CONFIG_KSU_EXTRAS
38-
extern void avc_spoof_init();
38+
extern void ksu_avc_spoof_init();
3939
#else
40-
void avc_spoof_init() {}
40+
void ksu_avc_spoof_init() {}
4141
#endif
4242

4343
#ifdef CONFIG_KSU_KPROBES_KSUD
@@ -125,7 +125,7 @@ void on_module_mounted(void){
125125
void on_boot_completed(void){
126126
ksu_boot_completed = true;
127127
pr_info("on_boot_completed!\n");
128-
avc_spoof_init();
128+
ksu_avc_spoof_init();
129129
}
130130

131131
#if defined(CONFIG_KRETPROBES) && defined(CONFIG_KSU_KPROBES_KSUD) && \

0 commit comments

Comments
 (0)