From f35efc77ebbcc00dc2b11112f11a4bc7a86da386 Mon Sep 17 00:00:00 2001 From: Wu Shangwei <2826256824@qq.com> Date: Tue, 28 Dec 2021 13:35:20 +0800 Subject: [PATCH 1/2] Add domain white list Signed-off-by: Wu Shangwei <2826256824@qq.com> Change-Id: I977d3aa4089665eab663b89380434db5dda4e482 --- services/hilogd/include/domain_list.h | 43 +++++++++++++++++++++++++++ services/hilogd/log_collector.cpp | 9 ++++++ 2 files changed, 52 insertions(+) create mode 100644 services/hilogd/include/domain_list.h diff --git a/services/hilogd/include/domain_list.h b/services/hilogd/include/domain_list.h new file mode 100644 index 0000000..d78675b --- /dev/null +++ b/services/hilogd/include/domain_list.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef DOMAIN_LIST_H +#define DOMAIN_LIST_H +#include +#include + +// Must be in order for binary_search +// Last two digits can vary +constexpr std::array domainWhiteList{ + 0xd000000, + 0xd000100, + 0xd000700, + 0xd001000, + 0xd001100, + 0xd001400, + 0xd001500, + 0xd001600, + 0xd001800, + 0xd001b00, + 0xd002500, + 0xd002900, + 0xd002b00, + 0xd002f00, + 0xd003b00, + 0xd008800 +}; + +constexpr uint32_t DOMAIN_WHITELIST_MATCH = 0xdffff00; + +#endif \ No newline at end of file diff --git a/services/hilogd/log_collector.cpp b/services/hilogd/log_collector.cpp index ee69bcb..af01dc5 100644 --- a/services/hilogd/log_collector.cpp +++ b/services/hilogd/log_collector.cpp @@ -16,6 +16,7 @@ #include "log_collector.h" #include "log_kmsg.h" #include "flow_control_init.h" +#include "domain_list.h" #include #include @@ -24,11 +25,17 @@ #include #include #include +#include namespace OHOS { namespace HiviewDFX { using namespace std; +static bool DomainWritable(const uint32_t domain) +{ + return std::binary_search(domainWhiteList.cbegin(), domainWhiteList.cend(), (domain & DOMAIN_WHITELIST_MATCH)); +} + void LogCollector::InsertDropInfo(const HilogMsg &msg, int droppedCount) { string dropLog = to_string(droppedCount) + " line(s) dropped!"; @@ -76,6 +83,8 @@ void LogCollector::onDataRecv(const ucred& cred, std::vector& data) #ifdef __RECV_MSG_WITH_UCRED_ msg->pid = cred.pid; #endif + // Drop if not in domain whitelist + if (!DomainWritable(msg->domain)) return; // Domain flow control int ret = FlowCtrlDomain(msg); if (ret < 0) { -- Gitee From 8d5ccd701a58df0c2822b7815a3019abbc8f1b9d Mon Sep 17 00:00:00 2001 From: Wu Shangwei <2826256824@qq.com> Date: Tue, 4 Jan 2022 14:28:47 +0800 Subject: [PATCH 2/2] Update testing domain Signed-off-by: Wu Shangwei <2826256824@qq.com> Change-Id: I8b076dd4a6bfd3cd903954bbd4a00d582f1b9219 --- services/hilogd/include/domain_list.h | 1 + 1 file changed, 1 insertion(+) diff --git a/services/hilogd/include/domain_list.h b/services/hilogd/include/domain_list.h index d78675b..48312e2 100644 --- a/services/hilogd/include/domain_list.h +++ b/services/hilogd/include/domain_list.h @@ -23,6 +23,7 @@ constexpr std::array domainWhiteList{ 0xd000000, 0xd000100, 0xd000700, + 0xd000f00, // Domain for testing 0xd001000, 0xd001100, 0xd001400, -- Gitee