MALI: rockchip: upgrade to DDK r7p0-02rel0.
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / midgard / mali_kbase_security.c
1 /*
2  *
3  * (C) COPYRIGHT 2011-2015 ARM Limited. All rights reserved.
4  *
5  * This program is free software and is provided to you under the terms of the
6  * GNU General Public License version 2 as published by the Free Software
7  * Foundation, and any use by you of this program is subject to the terms
8  * of such GNU licence.
9  *
10  * A copy of the licence is included with the program, and can also be obtained
11  * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
12  * Boston, MA  02110-1301, USA.
13  *
14  */
15
16
17
18
19
20 /**
21  * @file mali_kbase_security.c
22  * Base kernel security capability API
23  */
24
25 #include <mali_kbase.h>
26
27 static inline bool kbasep_am_i_root(void)
28 {
29 #if KBASE_HWCNT_DUMP_BYPASS_ROOT
30         return true;
31 #else
32         /* Check if root */
33 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)
34         if (uid_eq(current_euid(), GLOBAL_ROOT_UID))
35                 return true;
36 #else
37         if (current_euid() == 0)
38                 return true;
39 #endif /*LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)*/
40         return false;
41 #endif /*KBASE_HWCNT_DUMP_BYPASS_ROOT*/
42 }
43
44 /**
45  * kbase_security_has_capability - see mali_kbase_caps.h for description.
46  */
47
48 bool kbase_security_has_capability(struct kbase_context *kctx, enum kbase_security_capability cap, u32 flags)
49 {
50         /* Assume failure */
51         bool access_allowed = false;
52         bool audit = KBASE_SEC_FLAG_AUDIT & flags;
53
54         KBASE_DEBUG_ASSERT(NULL != kctx);
55         CSTD_UNUSED(kctx);
56
57         /* Detect unsupported flags */
58         KBASE_DEBUG_ASSERT(((~KBASE_SEC_FLAG_MASK) & flags) == 0);
59
60         /* Determine if access is allowed for the given cap */
61         switch (cap) {
62         case KBASE_SEC_MODIFY_PRIORITY:
63         case KBASE_SEC_INSTR_HW_COUNTERS_COLLECT:
64                 /* Access is granted only if the caller is privileged */
65                 access_allowed = kbasep_am_i_root();
66                 break;
67         }
68
69         /* Report problem if requested */
70         if (!access_allowed && audit)
71                 dev_warn(kctx->kbdev->dev, "Security capability failure: %d, %p", cap, (void *)kctx);
72
73         return access_allowed;
74 }
75
76 KBASE_EXPORT_TEST_API(kbase_security_has_capability);