aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJerome Forissier2017-05-30 03:17:16 -0500
committerJérôme Forissier2017-05-30 06:46:10 -0500
commit326001cf31814c728eb2f441c477f4d29600d90b (patch)
tree9428861ce8227576909d21ac86e2ec9471bc31cf
parentd6a329167a13a124b5cf7a4f0e6f9911099e484a (diff)
downloadti-optee-client-326001cf31814c728eb2f441c477f4d29600d90b.tar.gz
ti-optee-client-326001cf31814c728eb2f441c477f4d29600d90b.tar.xz
ti-optee-client-326001cf31814c728eb2f441c477f4d29600d90b.zip
tee-supplicant: FS: remove unused legacy RPC functions
Since commit 129360332591 ("core: FS: remove unused legacy RPC functions"), OP-TEE OS does not use a number of filesystem-related commands anymore. Remove them from tee-supplicant. Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
-rw-r--r--tee-supplicant/src/tee_fs.h185
-rw-r--r--tee-supplicant/src/tee_supp_fs.c295
2 files changed, 0 insertions, 480 deletions
diff --git a/tee-supplicant/src/tee_fs.h b/tee-supplicant/src/tee_fs.h
deleted file mode 100644
index d973aee0..00000000
--- a/tee-supplicant/src/tee_fs.h
+++ /dev/null
@@ -1,185 +0,0 @@
1/*
2 * Copyright (c) 2014, STMicroelectronics International N.V.
3 * Copyright (c) 2016, Linaro Limited
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <fcntl.h>
30#include <stdint.h>
31#include <unistd.h>
32#include <sys/stat.h>
33#include <sys/types.h>
34
35/*
36 * Structure for file related RPC calls
37 *
38 * @op The operation like open, close, read, write etc
39 * @flags Flags to the operation shared with secure world
40 * @arg Argument to operation
41 * @fd Normal World file descriptor
42 * @len Length of buffer at the end of this struct
43 * @res Result of the operation
44 */
45struct tee_fs_rpc {
46 int op;
47 int flags;
48 int arg;
49 int fd;
50 uint32_t len;
51 int res;
52};
53
54/*
55 * Operations shared with TEE.
56 */
57#define TEE_FS_OPEN 1
58#define TEE_FS_CLOSE 2
59#define TEE_FS_READ 3
60#define TEE_FS_WRITE 4
61#define TEE_FS_SEEK 5
62#define TEE_FS_UNLINK 6
63#define TEE_FS_RENAME 7
64#define TEE_FS_TRUNC 8
65#define TEE_FS_MKDIR 9
66#define TEE_FS_OPENDIR 10
67#define TEE_FS_CLOSEDIR 11
68#define TEE_FS_READDIR 12
69#define TEE_FS_RMDIR 13
70#define TEE_FS_ACCESS 14
71#define TEE_FS_LINK 15
72#define TEE_FS_BEGIN 16 /* SQL FS: begin transaction */
73#define TEE_FS_END 17 /* SQL FS: end transaction */
74
75/*
76 * Open flags, defines shared with TEE.
77 */
78#define TEE_FS_O_RDONLY 0x1
79#define TEE_FS_O_WRONLY 0x2
80#define TEE_FS_O_RDWR 0x4
81#define TEE_FS_O_CREAT 0x8
82#define TEE_FS_O_EXCL 0x10
83#define TEE_FS_O_APPEND 0x20
84#define TEE_FS_O_TRUNC 0x40
85
86/*
87 * Seek flags, defines shared with TEE.
88 */
89#define TEE_FS_SEEK_SET 0x1
90#define TEE_FS_SEEK_END 0x2
91#define TEE_FS_SEEK_CUR 0x4
92
93/*
94 * Mkdir flags, defines shared with TEE.
95 */
96#define TEE_FS_S_IWUSR 0x1
97#define TEE_FS_S_IRUSR 0x2
98#define TEE_FS_S_IXUSR 0x4
99
100/*
101 * Access flags, X_OK not supported, defines shared with TEE.
102 */
103#define TEE_FS_R_OK 0x1
104#define TEE_FS_W_OK 0x2
105#define TEE_FS_F_OK 0x4
106
107/* Function to convert TEE open flags to UNIX IO */
108static int tee_fs_conv_oflags(int in)
109{
110 int flags = 0;
111
112 if (in & TEE_FS_O_RDONLY)
113 flags |= O_RDONLY;
114
115 if (in & TEE_FS_O_WRONLY)
116 flags |= O_WRONLY;
117
118 if (in & TEE_FS_O_RDWR)
119 flags |= O_RDWR;
120
121 if (in & TEE_FS_O_CREAT)
122 flags |= O_CREAT;
123
124 if (in & TEE_FS_O_EXCL)
125 flags |= O_EXCL;
126
127 if (in & TEE_FS_O_APPEND)
128 flags |= O_APPEND;
129
130 if (in & TEE_FS_O_TRUNC)
131 flags |= O_TRUNC;
132
133 return flags;
134}
135
136/* Function to convert TEE seek flags to UNIX IO */
137static int tee_fs_conv_whence(int in)
138{
139 int flags = 0;
140
141 if (in & TEE_FS_SEEK_SET)
142 flags |= SEEK_SET;
143
144 if (in & TEE_FS_SEEK_END)
145 flags |= SEEK_END;
146
147 if (in & TEE_FS_SEEK_CUR)
148 flags |= SEEK_CUR;
149
150 return flags;
151}
152
153/* Function to convert TEE open flags to UNIX IO */
154static mode_t tee_fs_conv_mkdflags(int in)
155{
156 int flags = 0;
157
158 if (in & TEE_FS_S_IWUSR)
159 flags |= S_IWUSR;
160
161 if (in & TEE_FS_S_IRUSR)
162 flags |= S_IRUSR;
163
164 if (in & TEE_FS_S_IXUSR)
165 flags |= S_IXUSR;
166
167 return flags;
168}
169
170static int tee_fs_conv_accessflags(int in)
171{
172 int flags = 0;
173
174 if (in & TEE_FS_R_OK)
175 flags |= R_OK;
176
177 if (in & TEE_FS_W_OK)
178 flags |= W_OK;
179
180 if (in & TEE_FS_F_OK)
181 flags |= F_OK;
182
183 return flags;
184}
185
diff --git a/tee-supplicant/src/tee_supp_fs.c b/tee-supplicant/src/tee_supp_fs.c
index bd1a220f..07fe7c9f 100644
--- a/tee-supplicant/src/tee_supp_fs.c
+++ b/tee-supplicant/src/tee_supp_fs.c
@@ -37,7 +37,6 @@
37#include <string.h> 37#include <string.h>
38#include <sys/stat.h> 38#include <sys/stat.h>
39#include <teec_trace.h> 39#include <teec_trace.h>
40#include <tee_fs.h>
41#include <tee_supp_fs.h> 40#include <tee_supp_fs.h>
42#include <tee_supplicant.h> 41#include <tee_supplicant.h>
43#include <unistd.h> 42#include <unistd.h>
@@ -77,228 +76,6 @@ static size_t tee_fs_get_absolute_filename(char *file, char *out,
77 return (size_t)s; 76 return (size_t)s;
78} 77}
79 78
80static int tee_fs_open(struct tee_fs_rpc *fsrpc)
81{
82 char abs_filename[PATH_MAX];
83 char *filename = (char *)(fsrpc + 1);
84 int flags;
85 size_t filesize = tee_fs_get_absolute_filename(filename, abs_filename,
86 sizeof(abs_filename));
87 if (!filesize)
88 return -1; /* Corresponds to error using open */
89
90 flags = tee_fs_conv_oflags(fsrpc->flags);
91 fsrpc->fd = open(abs_filename, flags, S_IRUSR | S_IWUSR);
92 return fsrpc->fd;
93}
94
95static int tee_fs_close(struct tee_fs_rpc *fsrpc)
96{
97 return close(fsrpc->fd);
98}
99
100static int tee_fs_read(struct tee_fs_rpc *fsrpc)
101{
102 void *data = (void *)(fsrpc + 1);
103
104 return read(fsrpc->fd, data, fsrpc->len);
105}
106
107static int tee_fs_write(struct tee_fs_rpc *fsrpc)
108{
109 void *data = (void *)(fsrpc + 1);
110
111 return write(fsrpc->fd, data, fsrpc->len);
112}
113
114static int tee_fs_seek(struct tee_fs_rpc *fsrpc)
115{
116 int wh = tee_fs_conv_whence(fsrpc->flags);
117
118 fsrpc->res = lseek(fsrpc->fd, fsrpc->arg, wh);
119
120 return fsrpc->res;
121}
122
123static int tee_fs_unlink(struct tee_fs_rpc *fsrpc)
124{
125 char abs_filename[PATH_MAX];
126 char *filename = (char *)(fsrpc + 1);
127 int ret = -1; /* Corresponds to error using unlink */
128 size_t filesize = tee_fs_get_absolute_filename(filename, abs_filename,
129 sizeof(abs_filename));
130 if (filesize)
131 ret = unlink(abs_filename);
132
133 return ret;
134}
135
136static int tee_fs_link(struct tee_fs_rpc *fsrpc)
137{
138 char old_fn[PATH_MAX];
139 char new_fn[PATH_MAX];
140 char *filenames = (char *)(fsrpc + 1);
141 int ret = -1; /* Corresponds to error value for link */
142
143 /*
144 * During a link operation secure world sends the two NULL terminated
145 * filenames as a single concatenated string, as for example:
146 * "old.txt\0new.txt\0"
147 * Therefore we start by finding the offset to where the new filename
148 * begins.
149 */
150 size_t offset_new_fn = strlen(filenames) + 1;
151 size_t filesize = tee_fs_get_absolute_filename(filenames, old_fn,
152 sizeof(old_fn));
153 if (!filesize)
154 goto exit;
155
156 filesize = tee_fs_get_absolute_filename(filenames + offset_new_fn,
157 new_fn, sizeof(new_fn));
158 if (filesize)
159 ret = link(old_fn, new_fn);
160
161exit:
162 return ret;
163}
164
165static int tee_fs_rename(struct tee_fs_rpc *fsrpc)
166{
167 char old_fn[PATH_MAX];
168 char new_fn[PATH_MAX];
169 char *filenames = (char *)(fsrpc + 1);
170 int ret = -1; /* Corresponds to error value for rename */
171
172 /*
173 * During a rename operation secure world sends the two NULL terminated
174 * filenames as a single concatenated string, as for example:
175 * "old.txt\0new.txt\0"
176 * Therefore we start by finding the offset to where the new filename
177 * begins.
178 */
179 size_t offset_new_fn = strlen(filenames) + 1;
180 size_t filesize = tee_fs_get_absolute_filename(filenames, old_fn,
181 sizeof(old_fn));
182 if (!filesize)
183 goto exit;
184
185 filesize = tee_fs_get_absolute_filename(filenames + offset_new_fn,
186 new_fn, sizeof(new_fn));
187 if (filesize)
188 ret = rename(old_fn, new_fn);
189
190exit:
191 return ret;
192}
193
194static int tee_fs_truncate(struct tee_fs_rpc *fsrpc)
195{
196 return ftruncate(fsrpc->fd, fsrpc->arg);
197}
198
199static int tee_fs_mkdir(struct tee_fs_rpc *fsrpc)
200{
201 char abs_dirname[PATH_MAX];
202 char *dname = (char *)(fsrpc + 1);
203 mode_t mode;
204 int ret = -1; /* Same as mkir on error */
205 size_t filesize = tee_fs_get_absolute_filename(dname, abs_dirname,
206 sizeof(abs_dirname));
207
208 if (filesize) {
209 mode = tee_fs_conv_mkdflags(fsrpc->flags);
210 ret = mkdir(abs_dirname, mode);
211 }
212
213 return ret;
214}
215
216static int tee_fs_opendir(struct tee_fs_rpc *fsrpc)
217{
218 char abs_dirname[PATH_MAX];
219 char *dname = (char *)(fsrpc + 1);
220 DIR *dir;
221 int handle = -1;
222 size_t filesize = tee_fs_get_absolute_filename(dname, abs_dirname,
223 sizeof(abs_dirname));
224 if (!filesize)
225 goto exit;
226
227 dir = opendir(abs_dirname);
228 if (!dir)
229 goto exit;
230
231 handle = handle_get(&dir_handle_db, dir);
232 if (handle < 0)
233 closedir(dir);
234exit:
235 return handle;
236}
237
238static int tee_fs_closedir(struct tee_fs_rpc *fsrpc)
239{
240 DIR *dir = handle_put(&dir_handle_db, fsrpc->arg);
241
242 return closedir(dir);
243}
244
245static int tee_fs_readdir(struct tee_fs_rpc *fsrpc)
246{
247 char *dname = (char *)(fsrpc + 1);
248 DIR *dir = handle_lookup(&dir_handle_db, fsrpc->arg);
249 struct dirent *dirent;
250 size_t len;
251
252 do
253 dirent = readdir(dir);
254 while (dirent != NULL && dirent->d_name[0] == '.');
255
256 if (dirent == NULL) {
257 fsrpc->len = 0;
258 return -1;
259 }
260
261 len = strlen(dirent->d_name);
262 if (len > PATH_MAX)
263 return -1;
264
265 len++;
266 memcpy(dname, dirent->d_name, len);
267 fsrpc->len = len;
268
269 return 0;
270}
271
272static int tee_fs_rmdir(struct tee_fs_rpc *fsrpc)
273{
274 char abs_dirname[PATH_MAX];
275 char *dname = (char *)(fsrpc + 1);
276 int ret = -1; /* Corresponds to the error value for rmdir */
277 size_t filesize = tee_fs_get_absolute_filename(dname, abs_dirname,
278 sizeof(abs_dirname));
279
280 if (filesize)
281 ret = rmdir(abs_dirname);
282
283 return ret;
284}
285
286static int tee_fs_access(struct tee_fs_rpc *fsrpc)
287{
288 char abs_filename[PATH_MAX];
289 char *filename = (char *)(fsrpc + 1);
290 int flags;
291 int ret = -1; /* Corresponds to the error value for access */
292 size_t filesize = tee_fs_get_absolute_filename(filename, abs_filename,
293 sizeof(abs_filename));
294 if (filesize) {
295 flags = tee_fs_conv_accessflags(fsrpc->flags);
296 ret = access(abs_filename, flags);
297 }
298
299 return ret;
300}
301
302int tee_supp_fs_init(void) 79int tee_supp_fs_init(void)
303{ 80{
304 struct stat st; 81 struct stat st;
@@ -310,70 +87,6 @@ int tee_supp_fs_init(void)
310 return 0; 87 return 0;
311} 88}
312 89
313static TEEC_Result tee_supp_fs_process_primitive(void *cmd, size_t cmd_size)
314{
315 struct tee_fs_rpc *fsrpc = cmd;
316
317 if (cmd_size < sizeof(struct tee_fs_rpc))
318 return TEEC_ERROR_BAD_PARAMETERS;
319
320 if (!cmd)
321 return TEEC_ERROR_BAD_PARAMETERS;
322
323 switch (fsrpc->op) {
324 case TEE_FS_OPEN:
325 fsrpc->res = tee_fs_open(fsrpc);
326 break;
327 case TEE_FS_CLOSE:
328 fsrpc->res = tee_fs_close(fsrpc);
329 break;
330 case TEE_FS_READ:
331 fsrpc->res = tee_fs_read(fsrpc);
332 break;
333 case TEE_FS_WRITE:
334 fsrpc->res = tee_fs_write(fsrpc);
335 break;
336 case TEE_FS_SEEK:
337 fsrpc->res = tee_fs_seek(fsrpc);
338 break;
339 case TEE_FS_UNLINK:
340 fsrpc->res = tee_fs_unlink(fsrpc);
341 break;
342 case TEE_FS_RENAME:
343 fsrpc->res = tee_fs_rename(fsrpc);
344 break;
345 case TEE_FS_TRUNC:
346 fsrpc->res = tee_fs_truncate(fsrpc);
347 break;
348 case TEE_FS_MKDIR:
349 fsrpc->res = tee_fs_mkdir(fsrpc);
350 break;
351 case TEE_FS_OPENDIR:
352 fsrpc->res = tee_fs_opendir(fsrpc);
353 break;
354 case TEE_FS_CLOSEDIR:
355 fsrpc->res = tee_fs_closedir(fsrpc);
356 break;
357 case TEE_FS_READDIR:
358 fsrpc->res = tee_fs_readdir(fsrpc);
359 break;
360 case TEE_FS_RMDIR:
361 fsrpc->res = tee_fs_rmdir(fsrpc);
362 break;
363 case TEE_FS_ACCESS:
364 fsrpc->res = tee_fs_access(fsrpc);
365 break;
366 case TEE_FS_LINK:
367 fsrpc->res = tee_fs_link(fsrpc);
368 break;
369 default:
370 EMSG("Unexpected REE FS operation: %d", fsrpc->op);
371 return TEEC_ERROR_NOT_SUPPORTED;
372 }
373
374 return TEEC_SUCCESS;
375}
376
377static int open_wrapper(const char *fname, int flags) 90static int open_wrapper(const char *fname, int flags)
378{ 91{
379 int fd; 92 int fd;
@@ -850,14 +563,6 @@ static TEEC_Result ree_fs_new_readdir(size_t num_params,
850TEEC_Result tee_supp_fs_process(size_t num_params, 563TEEC_Result tee_supp_fs_process(size_t num_params,
851 struct tee_ioctl_param *params) 564 struct tee_ioctl_param *params)
852{ 565{
853 if (num_params == 1 && tee_supp_param_is_memref(params)) {
854 void *va = tee_supp_param_to_va(params);
855
856 if (!va)
857 return TEEC_ERROR_BAD_PARAMETERS;
858 return tee_supp_fs_process_primitive(va, params->u.memref.size);
859 }
860
861 if (!num_params || !tee_supp_param_is_value(params)) 566 if (!num_params || !tee_supp_param_is_value(params))
862 return TEEC_ERROR_BAD_PARAMETERS; 567 return TEEC_ERROR_BAD_PARAMETERS;
863 568