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
1718static 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+
1963static 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+ }
0 commit comments