summaryrefslogtreecommitdiff
path: root/src/client/include/check-proper-drop.h
blob: ad1df5b5077f55e51fdd3927e2b780880e478fac (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
 *
 *  Contact: Rafal Krypa <r.krypa@samsung.com>
 *
 *  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
 */
/*
 * @file        check-proper-drop.h
 * @author      Rafal Krypa <r.krypa@samsung.com>
 * @version     1.0
 * @brief       Definition of proper privilege dropping check utilities
 */

#ifndef SECURITY_MANAGER_CHECK_PROPER_DROP_
#define SECURITY_MANAGER_CHECK_PROPER_DROP_

#include <dpl/exception.h>

#include <unistd.h>
#include <proc/readproc.h>

#include <vector>

namespace SecurityManager {

class CheckProperDrop {
public:
    class Exception {
    public:
        DECLARE_EXCEPTION_TYPE(SecurityManager::Exception, Base)
        DECLARE_EXCEPTION_TYPE(Base, ProcError)
        DECLARE_EXCEPTION_TYPE(Base, CapError)
    };

    ~CheckProperDrop();
    CheckProperDrop(pid_t pid = getpid()) : m_pid(pid) {};

    /**
     * Fetch credentials of the process and all its threads.
     * Must be called before checkThreads().
     */
    void getThreads();

    /**
     * Check whether all threads of the process has properly aligned
     * credentials:
     * - uids
     * - gids
     * - capabilities
     * - Smack labels
     *
     * It will terminate the calling process if any thread has different
     * value than the other threads. This prevents security risks associated
     * with improperly dropped privileges during application launch.
     */
    bool checkThreads();

private:
    pid_t m_pid;
    proc_t *m_proc = nullptr;
    std::vector<proc_t*> m_threads;
};

} // namespace SecurityManager
#endif /* SECURITY_MANAGER_CHECK_PROPER_DROP_H_ */