summaryrefslogtreecommitdiff
path: root/src/common/include/check-proper-drop.h
blob: 0d64447e13abd4f0bf0ed8a8c17220a0993d8075 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * This file is licensed under the terms of MIT License or the Apache License
 * Version 2.0 of your choice. See the LICENSE.MIT file for MIT license details.
 * See the LICENSE file or the notice below for Apache License Version 2.0
 * details.
 *
 * 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.
 */

/*
 * @brief Definition of proper privilege dropping check utilities
 */

#pragma once

#include <utils.h>
#include <vector>

namespace SecurityManager {
namespace CheckProperDrop {

// SERVICE & CLIENT

// "pid" and "user" imply consistency among threads so are not checked,
// see man unshare(2): CLONE_NEW{IPC,USER} implies CLONE_THREAD
constexpr inline const char *NS_NAMES[] = {"mnt", "ipc", "net", "uts"};

constexpr inline auto N_FLAG_BITS = sizeof NS_NAMES / sizeof NS_NAMES[0];
static_assert(N_FLAG_BITS <= 7, "flags too large for int8_t");

// SERVICE ONLY
// Negative on unrecoverable error.
// Otherwise bit i set iff NS_NAMES[i] checked.
int8_t computeFlags();


// CLIENT ONLY
void checkThreads(const std::vector<int> &synced_tids);

}  // namespace CheckProperDrop
}  // namespace SecurityManager