From 1670382fc228fbbf437b6b219bd5f04b673aff09 Mon Sep 17 00:00:00 2001 From: steven_q Date: Wed, 11 May 2022 12:41:24 +0800 Subject: [PATCH] fixed 3dc97dc from https://gitee.com/steven-q/security_selinux/pulls/102 fix non init process param log callback Signed-off-by: steven_q Change-Id: I340c6a5aa683e6c74b08195dc57203036fda8851 --- BUILD.gn | 1 + .../policycoreutils/src/paraperm_checker.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/BUILD.gn b/BUILD.gn index e7ce35031..e20ad92e9 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -161,6 +161,7 @@ ohos_shared_library("libparaperm_checker") { ] public_configs = [ ":selinux_core_config" ] deps = [ + ":libselinux_hilog_static", ":libselinux_klog_static", "$THIRD_PARTY_SELINUX_DIR:libselinux", "//third_party/bounds_checking_function:libsec_static", diff --git a/interfaces/policycoreutils/src/paraperm_checker.cpp b/interfaces/policycoreutils/src/paraperm_checker.cpp index 51cfd2c33..1abf5bed6 100644 --- a/interfaces/policycoreutils/src/paraperm_checker.cpp +++ b/interfaces/policycoreutils/src/paraperm_checker.cpp @@ -25,6 +25,7 @@ #include "callbacks.h" #include "selinux_error.h" #include "selinux_klog.h" +#include "selinux_log.h" #include "contexts_trie.h" using namespace Selinux; @@ -34,6 +35,7 @@ static const std::string PARAMETER_CONTEXTS_FILE = "/system/etc/selinux/targeted static const std::string TYPE_PREFIX = "u:object_r:"; static const char *DEFAULT_CONTEXT = "u:object_r:default_param:s0"; static pthread_once_t FC_ONCE = PTHREAD_ONCE_INIT; +static pthread_once_t HILOG_ONCE = PTHREAD_ONCE_INIT; static std::unique_ptr g_contextsTrie = nullptr; static ParamContextsList *g_contextsList = nullptr; static const int CONTEXTS_LENGTH_MIN = 16; // sizeof("x u:object_r:x:s0") @@ -72,6 +74,16 @@ static void SelinuxSetCallback() selinux_set_callback(SELINUX_CB_AUDIT, cb); } +static void SelinuxSetHilogCallback() +{ + if (getpid() != 1) { + union selinux_callback cb; + SetSelinuxHilogLevel(SELINUX_HILOG_ERROR); + cb.func_log = SelinuxHilog; + selinux_set_callback(SELINUX_CB_LOG, cb); + } +} + static void ReleaseMem() { DestroyParamList(&g_contextsList); @@ -236,6 +248,8 @@ ParamContextsList *GetParamList() const char *GetParamLabel(const char *paraName) { + __selinux_once(HILOG_ONCE, SelinuxSetHilogCallback); + if (paraName == nullptr) { selinux_log(SELINUX_ERROR, "paraName is null!\n"); return DEFAULT_CONTEXT; -- Gitee