• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2012-2022 Huawei Technologies Co., Ltd.
3  * Description: allowed_ext_agent_ca list and functions.
4  *
5  * This software is licensed under the terms of the GNU General Public
6  * License version 2, as published by the Free Software Foundation, and
7  * may be copied, distributed, and modified under those terms.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  */
14 
15 #include "agent.h"
16 #include <linux/uaccess.h>
17 #include <linux/kernel.h>
18 #include <securec.h>
19 
20 static struct ca_info g_allowed_ext_agent_ca[] = {
21 #ifdef CONFIG_TZDRIVER
22 	{
23 		"/vendor/bin/hiaiserver",
24 		3094,
25 		TEE_SECE_AGENT_ID,
26 	},
27 	{
28 		"/vendor/bin/hw/hdf_devhost",
29 		1114,
30 		TEE_FACE_AGENT1_ID,
31 	},
32 #endif
33 #ifdef DEF_ENG
34 	{
35 		"/vendor/bin/tee_test_agent",
36 		0,
37 		TEE_SECE_AGENT_ID,
38 	},
39 #endif
40 };
41 
is_allowed_agent_ca(const struct ca_info * ca,bool check_agent_id)42 int is_allowed_agent_ca(const struct ca_info *ca,
43 	bool check_agent_id)
44 {
45 	uint32_t i;
46 	struct ca_info *tmp_ca = g_allowed_ext_agent_ca;
47 	const uint32_t nr = ARRAY_SIZE(g_allowed_ext_agent_ca);
48 
49 	if (!ca)
50 		return -EFAULT;
51 
52 	if (!check_agent_id) {
53 		for (i = 0; i < nr; i++) {
54 			if (!strncmp(ca->path, tmp_ca->path,
55 				strlen(tmp_ca->path) + 1) &&
56 				ca->uid == tmp_ca->uid)
57 				return 0;
58 			tmp_ca++;
59 		}
60 	} else {
61 		for (i = 0; i < nr; i++) {
62 			if (!strncmp(ca->path, tmp_ca->path,
63 					strlen(tmp_ca->path) + 1) &&
64 					ca->uid == tmp_ca->uid &&
65 					ca->agent_id == tmp_ca->agent_id)
66 					return 0;
67 				tmp_ca++;
68 		}
69 	}
70 	tlogd("ca-uid is %u, ca_path is %s, agent id is %x\n", ca->uid,
71 		ca->path, ca->agent_id);
72 
73 	return -EACCES;
74 }