kernel: support setting selinux context for profile

This commit is contained in:
weishu
2023-06-06 16:35:25 +08:00
parent c7f6a7d11b
commit 53be8612c8
4 changed files with 12 additions and 6 deletions

View File

@@ -37,7 +37,7 @@ static void init_default_profiles()
memset(&default_root_profile.capabilities, 0xff, memset(&default_root_profile.capabilities, 0xff,
sizeof(default_root_profile.capabilities)); sizeof(default_root_profile.capabilities));
default_root_profile.namespaces = 0; default_root_profile.namespaces = 0;
strcpy(default_root_profile.selinux_domain, "su"); strcpy(default_root_profile.selinux_domain, "u:r:su:s0");
// This means that we will umount modules by default! // This means that we will umount modules by default!
default_non_root_profile.umount_modules = true; default_non_root_profile.umount_modules = true;
@@ -112,7 +112,12 @@ static bool profile_valid(struct app_profile *profile)
if (profile->rp_config.profile.groups_count > KSU_MAX_GROUPS) { if (profile->rp_config.profile.groups_count > KSU_MAX_GROUPS) {
return false; return false;
} }
if (strlen(profile->rp_config.profile.selinux_domain) == 0) {
return false;
}
} }
return true; return true;
} }

View File

@@ -135,7 +135,7 @@ void escape_to_root(void)
setup_groups(profile, cred); setup_groups(profile, cred);
setup_selinux(); setup_selinux(profile->selinux_domain);
} }
int ksu_handle_rename(struct dentry *old_dentry, struct dentry *new_dentry) int ksu_handle_rename(struct dentry *old_dentry, struct dentry *new_dentry)

View File

@@ -39,9 +39,9 @@ static int transive_to_domain(const char *domain)
return error; return error;
} }
void setup_selinux() void setup_selinux(const char *domain)
{ {
if (transive_to_domain(KERNEL_SU_DOMAIN)) { if (transive_to_domain(domain)) {
pr_err("transive domain failed."); pr_err("transive domain failed.");
return; return;
} }
@@ -88,7 +88,8 @@ bool getenforce()
#endif #endif
} }
#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)) && !defined(KSU_COMPAT_HAS_CURRENT_SID) #if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)) && \
!defined(KSU_COMPAT_HAS_CURRENT_SID)
/* /*
* get the subjective security ID of the current task * get the subjective security ID of the current task
*/ */

View File

@@ -8,7 +8,7 @@
#define KSU_COMPAT_USE_SELINUX_STATE #define KSU_COMPAT_USE_SELINUX_STATE
#endif #endif
void setup_selinux(); void setup_selinux(const char *);
void setenforce(bool); void setenforce(bool);