kernel: move some defs to single file
* Much cleaner code, although setenforce is not used anymore * Guard is_ksu_transition only for 4.19 and under. Signed-off-by: rsuntk <rsuntk@yukiprjkt.my.id>
This commit is contained in:
@@ -1,13 +1,6 @@
|
||||
#include "selinux.h"
|
||||
#include "objsec.h"
|
||||
#include "linux/version.h"
|
||||
#include <linux/version.h>
|
||||
#include "selinux_defs.h"
|
||||
#include "../klog.h" // IWYU pragma: keep
|
||||
#ifdef SAMSUNG_SELINUX_PORTING
|
||||
#include "security.h" // Samsung SELinux Porting
|
||||
#endif
|
||||
#ifndef KSU_COMPAT_USE_SELINUX_STATE
|
||||
#include "avc.h"
|
||||
#endif
|
||||
|
||||
#define KERNEL_SU_DOMAIN "u:r:su:s0"
|
||||
|
||||
@@ -31,15 +24,18 @@ static int transive_to_domain(const char *domain)
|
||||
pr_info("security_secctx_to_secid %s -> sid: %d, error: %d\n",
|
||||
domain, sid, error);
|
||||
}
|
||||
|
||||
if (!error) {
|
||||
tsec->sid = sid;
|
||||
tsec->create_sid = 0;
|
||||
tsec->keycreate_sid = 0;
|
||||
tsec->sockcreate_sid = 0;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
#if LINUX_VERSION_CODE <= KERNEL_VERSION(4, 19, 0)
|
||||
bool __maybe_unused is_ksu_transition(const struct task_security_struct *old_tsec,
|
||||
const struct task_security_struct *new_tsec)
|
||||
{
|
||||
@@ -49,7 +45,7 @@ bool __maybe_unused is_ksu_transition(const struct task_security_struct *old_tse
|
||||
bool allowed = false;
|
||||
|
||||
if (!ksu_sid)
|
||||
security_secctx_to_secid("u:r:su:s0", strlen("u:r:su:s0"), &ksu_sid);
|
||||
security_secctx_to_secid(KERNEL_SU_DOMAIN, strlen(KERNEL_SU_DOMAIN), &ksu_sid);
|
||||
|
||||
if (security_secid_to_secctx(old_tsec->sid, &secdata, &seclen))
|
||||
return false;
|
||||
@@ -58,6 +54,7 @@ bool __maybe_unused is_ksu_transition(const struct task_security_struct *old_tse
|
||||
security_release_secctx(secdata, seclen);
|
||||
return allowed;
|
||||
}
|
||||
#endif
|
||||
|
||||
void setup_selinux(const char *domain)
|
||||
{
|
||||
@@ -69,42 +66,16 @@ void setup_selinux(const char *domain)
|
||||
|
||||
void setenforce(bool enforce)
|
||||
{
|
||||
#ifdef CONFIG_SECURITY_SELINUX_DEVELOP
|
||||
#ifdef SAMSUNG_SELINUX_PORTING
|
||||
selinux_enforcing = enforce;
|
||||
#endif
|
||||
#ifdef KSU_COMPAT_USE_SELINUX_STATE
|
||||
selinux_state.enforcing = enforce;
|
||||
#else
|
||||
selinux_enforcing = enforce;
|
||||
#endif
|
||||
#endif
|
||||
__setenforce(enforce);
|
||||
}
|
||||
|
||||
bool getenforce()
|
||||
bool getenforce(void)
|
||||
{
|
||||
#ifdef CONFIG_SECURITY_SELINUX_DISABLE
|
||||
#ifdef KSU_COMPAT_USE_SELINUX_STATE
|
||||
if (selinux_state.disabled) {
|
||||
#else
|
||||
if (selinux_disabled) {
|
||||
#endif
|
||||
if (is_selinux_disabled()) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SECURITY_SELINUX_DEVELOP
|
||||
#ifdef SAMSUNG_SELINUX_PORTING
|
||||
return selinux_enforcing;
|
||||
#endif
|
||||
#ifdef KSU_COMPAT_USE_SELINUX_STATE
|
||||
return selinux_state.enforcing;
|
||||
#else
|
||||
return selinux_enforcing;
|
||||
#endif
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
|
||||
return __is_selinux_enforcing();
|
||||
}
|
||||
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)) && \
|
||||
@@ -125,10 +96,12 @@ bool is_ksu_domain()
|
||||
char *domain;
|
||||
u32 seclen;
|
||||
bool result;
|
||||
|
||||
int err = security_secid_to_secctx(current_sid(), &domain, &seclen);
|
||||
if (err) {
|
||||
return false;
|
||||
}
|
||||
|
||||
result = strncmp(KERNEL_SU_DOMAIN, domain, seclen) == 0;
|
||||
security_release_secctx(domain, seclen);
|
||||
return result;
|
||||
@@ -140,13 +113,16 @@ bool is_zygote(void *sec)
|
||||
if (!tsec) {
|
||||
return false;
|
||||
}
|
||||
|
||||
char *domain;
|
||||
u32 seclen;
|
||||
bool result;
|
||||
|
||||
int err = security_secid_to_secctx(tsec->sid, &domain, &seclen);
|
||||
if (err) {
|
||||
return false;
|
||||
}
|
||||
|
||||
result = strncmp("u:r:zygote:s0", domain, seclen) == 0;
|
||||
security_release_secctx(domain, seclen);
|
||||
return result;
|
||||
@@ -159,8 +135,9 @@ u32 ksu_get_devpts_sid()
|
||||
u32 devpts_sid = 0;
|
||||
int err = security_secctx_to_secid(DEVPTS_DOMAIN, strlen(DEVPTS_DOMAIN),
|
||||
&devpts_sid);
|
||||
if (err) {
|
||||
|
||||
if (err)
|
||||
pr_info("get devpts sid err %d\n", err);
|
||||
}
|
||||
|
||||
return devpts_sid;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user