diff options
| author | Peter Griffin <peter.griffin@linaro.org> | 2019-10-25 11:34:53 +0200 |
|---|---|---|
| committer | Otavio Salvador <otavio@ossystems.com.br> | 2019-11-08 15:31:25 -0300 |
| commit | d331f7043142626ce2250ccd7f9a3e4791b1d377 (patch) | |
| tree | 1899e6d8167b5fc52c98f5fa52aa557ed8e9537d | |
| parent | c8b32341043831f4e8933b00ddf83831e7d015ce (diff) | |
| download | meta-freescale-d331f7043142626ce2250ccd7f9a3e4791b1d377.tar.gz | |
optee-client: Add support for optee-client imx fork
This also includes some backported gcc 8 fixes from upstream.
Signed-off-by: Peter Griffin <peter.griffin@linaro.org>
3 files changed, 239 insertions, 0 deletions
diff --git a/recipes-security/optee-imx/optee-client/0001-libteec-refactor-_dprintf.patch b/recipes-security/optee-imx/optee-client/0001-libteec-refactor-_dprintf.patch new file mode 100644 index 000000000..1c053f38d --- /dev/null +++ b/recipes-security/optee-imx/optee-client/0001-libteec-refactor-_dprintf.patch | |||
| @@ -0,0 +1,171 @@ | |||
| 1 | Upstream-Status: Backport 3.3.0 | ||
| 2 | |||
| 3 | Signed-off-by: Peter Griffin <peter.griffin@linaro.org> | ||
| 4 | --- | ||
| 5 | From 0361f9b21bb1acfaf23323a121f542fe03dcd2c8 Mon Sep 17 00:00:00 2001 | ||
| 6 | From: Jerome Forissier <jerome.forissier@linaro.org> | ||
| 7 | Date: Thu, 5 Jul 2018 15:15:31 +0200 | ||
| 8 | Subject: [PATCH] libteec: refactor _dprintf() | ||
| 9 | MIME-Version: 1.0 | ||
| 10 | Content-Type: text/plain; charset=UTF-8 | ||
| 11 | Content-Transfer-Encoding: 8bit | ||
| 12 | |||
| 13 | GCC8.1 gives an error when compiling _dprintf(): | ||
| 14 | |||
| 15 | src/teec_trace.c: In function ‘_dprintf’: | ||
| 16 | src/teec_trace.c:110:5: error: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size 246 [-Werror=format-truncation=] | ||
| 17 | "%s [%d] %s:%s:%d: %s", | ||
| 18 | ^~~~~~~~~~~~~~~~~~~~~~ | ||
| 19 | src/teec_trace.c:112:11: | ||
| 20 | line, raw); | ||
| 21 | ~~~ | ||
| 22 | src/teec_trace.c:109:3: note: ‘snprintf’ output 11 or more bytes (assuming 266) into a destination of size 256 | ||
| 23 | snprintf(prefixed, MAX_PRINT_SIZE, | ||
| 24 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 25 | "%s [%d] %s:%s:%d: %s", | ||
| 26 | ~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 27 | trace_level_strings[level], thread_id, prefix, func, | ||
| 28 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 29 | line, raw); | ||
| 30 | ~~~~~~~~~~ | ||
| 31 | |||
| 32 | Fix this error by using a single output buffer, printing the prefix first | ||
| 33 | then the other arguments with the supplied format. | ||
| 34 | |||
| 35 | In addition, further simplify the function by getting rid of things that | ||
| 36 | do not make much sense: | ||
| 37 | - Remove the 'flen' parameter, which is only ever set to zero or | ||
| 38 | strlen(__func__). | ||
| 39 | - Remove the TRACE_FUNC_LENGTH_CST macro which is not set by default and | ||
| 40 | does not seem very useful. | ||
| 41 | - Change the return type to void because callers do not care about success | ||
| 42 | or failure. | ||
| 43 | |||
| 44 | Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> | ||
| 45 | Reviewed-by: Joakim Bech <joakim.bech@linaro.org> | ||
| 46 | --- | ||
| 47 | libteec/src/teec_trace.c | 63 +++++++++++++++--------------------------------- | ||
| 48 | public/teec_trace.h | 8 +++--- | ||
| 49 | 2 files changed, 23 insertions(+), 48 deletions(-) | ||
| 50 | |||
| 51 | diff --git a/libteec/src/teec_trace.c b/libteec/src/teec_trace.c | ||
| 52 | index 78b79d6..3a2a0da 100644 | ||
| 53 | --- a/libteec/src/teec_trace.c | ||
| 54 | +++ b/libteec/src/teec_trace.c | ||
| 55 | @@ -47,7 +47,6 @@ | ||
| 56 | * PPPP: MMMMM [FFFFFFFFFFFFFFF : LLLLL] | ||
| 57 | */ | ||
| 58 | #define MAX_PRINT_SIZE 256 | ||
| 59 | -#define MAX_FUNC_PRINT_SIZE 32 | ||
| 60 | |||
| 61 | #ifdef TEEC_LOG_FILE | ||
| 62 | static void log_to_file(const char *buffer) | ||
| 63 | @@ -69,57 +68,33 @@ static const char * const trace_level_strings[] = { | ||
| 64 | "", "ERR", "INF", "DBG", "FLW" | ||
| 65 | }; | ||
| 66 | |||
| 67 | -int _dprintf(const char *function, int flen, int line, int level, | ||
| 68 | - const char *prefix, const char *fmt, ...) | ||
| 69 | +void _dprintf(const char *function, int line, int level, const char *prefix, | ||
| 70 | + const char *fmt, ...) | ||
| 71 | { | ||
| 72 | - char raw[MAX_PRINT_SIZE]; | ||
| 73 | - char prefixed[MAX_PRINT_SIZE]; | ||
| 74 | - char *to_print = NULL; | ||
| 75 | - const char *func; | ||
| 76 | - int err; | ||
| 77 | + char msg[MAX_PRINT_SIZE]; | ||
| 78 | + int n = 0; | ||
| 79 | va_list ap; | ||
| 80 | |||
| 81 | - va_start(ap, fmt); | ||
| 82 | - err = vsnprintf(raw, sizeof(raw), fmt, ap); | ||
| 83 | - va_end(ap); | ||
| 84 | - | ||
| 85 | if (function) { | ||
| 86 | -#ifdef TRACE_FUNC_LENGTH_CST | ||
| 87 | - char func_buf[MAX_FUNC_PRINT_SIZE]; | ||
| 88 | - /* Limit the function name to MAX_FUNC_PRINT_SIZE characters. */ | ||
| 89 | - strncpy(func_buf, function, flen > MAX_FUNC_PRINT_SIZE ? | ||
| 90 | - (MAX_FUNC_PRINT_SIZE - 1) : flen); | ||
| 91 | - if (flen < (MAX_FUNC_PRINT_SIZE - 1)) { | ||
| 92 | - memset(func_buf + flen, 0x20, | ||
| 93 | - (MAX_FUNC_PRINT_SIZE - flen)); | ||
| 94 | - } | ||
| 95 | - func_buf[MAX_FUNC_PRINT_SIZE - 1] = '\0'; | ||
| 96 | - func = func_buf; | ||
| 97 | -#else | ||
| 98 | - (void)flen; | ||
| 99 | - func = function; | ||
| 100 | -#endif | ||
| 101 | + int thread_id = syscall(SYS_gettid); | ||
| 102 | |||
| 103 | - /* | ||
| 104 | - * pthread_self returns the POSIX tid which is different from | ||
| 105 | - * the kernel id | ||
| 106 | - */ | ||
| 107 | - int thread_id = syscall(SYS_gettid); /* perf issue ? */ | ||
| 108 | - | ||
| 109 | - snprintf(prefixed, MAX_PRINT_SIZE, | ||
| 110 | - "%s [%d] %s:%s:%d: %s", | ||
| 111 | - trace_level_strings[level], thread_id, prefix, func, | ||
| 112 | - line, raw); | ||
| 113 | - to_print = prefixed; | ||
| 114 | - } else { | ||
| 115 | - to_print = raw; | ||
| 116 | + n = snprintf(msg, sizeof(msg), "%s [%d] %s:%s:%d: ", | ||
| 117 | + trace_level_strings[level], thread_id, prefix, | ||
| 118 | + function, line); | ||
| 119 | + if (n < 0) | ||
| 120 | + return; | ||
| 121 | } | ||
| 122 | |||
| 123 | - fprintf(stdout, "%s", to_print); | ||
| 124 | - | ||
| 125 | - log_to_file(to_print); | ||
| 126 | + if ((size_t)n < sizeof(msg)) { | ||
| 127 | + va_start(ap, fmt); | ||
| 128 | + n = vsnprintf(msg + n, sizeof(msg) - n, fmt, ap); | ||
| 129 | + va_end(ap); | ||
| 130 | + if (n < 0) | ||
| 131 | + return; | ||
| 132 | + } | ||
| 133 | |||
| 134 | - return err; | ||
| 135 | + fprintf(stdout, "%s", msg); | ||
| 136 | + log_to_file(msg); | ||
| 137 | } | ||
| 138 | |||
| 139 | #if (defined(DEBUGLEVEL_3) || defined(DEBUGLEVEL_true) || defined(DEBUGLEVEL_4)) | ||
| 140 | diff --git a/public/teec_trace.h b/public/teec_trace.h | ||
| 141 | index 28e290c..f75358f 100644 | ||
| 142 | --- a/public/teec_trace.h | ||
| 143 | +++ b/public/teec_trace.h | ||
| 144 | @@ -91,12 +91,12 @@ extern "C" { | ||
| 145 | #define __PRINTFLIKE(__fmt, __varargs) __attribute__\ | ||
| 146 | ((__format__(__printf__, __fmt, __varargs))) | ||
| 147 | |||
| 148 | -int _dprintf(const char *function, int flen, int line, int level, | ||
| 149 | - const char *prefix, const char *fmt, ...) __PRINTFLIKE(6, 7); | ||
| 150 | +void _dprintf(const char *function, int line, int level, const char *prefix, | ||
| 151 | + const char *fmt, ...) __PRINTFLIKE(5, 6); | ||
| 152 | |||
| 153 | #define dprintf(level, x...) do { \ | ||
| 154 | if ((level) <= DEBUGLEVEL) { \ | ||
| 155 | - _dprintf(__func__, strlen(__func__), __LINE__, level, \ | ||
| 156 | + _dprintf(__func__, __LINE__, level, \ | ||
| 157 | BINARY_PREFIX, x); \ | ||
| 158 | } \ | ||
| 159 | } while (0) | ||
| 160 | @@ -118,7 +118,7 @@ int _dprintf(const char *function, int flen, int line, int level, | ||
| 161 | |||
| 162 | #define dprintf_raw(level, x...) do { \ | ||
| 163 | if ((level) <= DEBUGLEVEL) \ | ||
| 164 | - _dprintf(0, 0, 0, (level), BINARY_PREFIX, x); \ | ||
| 165 | + _dprintf(0, 0, (level), BINARY_PREFIX, x); \ | ||
| 166 | } while (0) | ||
| 167 | |||
| 168 | #define EMSG_RAW(fmt, ...) dprintf_raw(TRACE_ERROR, fmt, ##__VA_ARGS__) | ||
| 169 | -- | ||
| 170 | 2.7.4 | ||
| 171 | |||
diff --git a/recipes-security/optee-imx/optee-client/tee-supplicant.service b/recipes-security/optee-imx/optee-client/tee-supplicant.service new file mode 100644 index 000000000..0e2b4f6ba --- /dev/null +++ b/recipes-security/optee-imx/optee-client/tee-supplicant.service | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | [Unit] | ||
| 2 | Description=TEE Supplicant | ||
| 3 | |||
| 4 | [Service] | ||
| 5 | User=root | ||
| 6 | EnvironmentFile=-/etc/default/tee-supplicant | ||
| 7 | ExecStart=/usr/bin/tee-supplicant $OPTARGS | ||
| 8 | |||
| 9 | [Install] | ||
| 10 | WantedBy=basic.target | ||
| 11 | |||
diff --git a/recipes-security/optee-imx/optee-client_3.2.0.imx.bb b/recipes-security/optee-imx/optee-client_3.2.0.imx.bb new file mode 100644 index 000000000..2b0bcf48c --- /dev/null +++ b/recipes-security/optee-imx/optee-client_3.2.0.imx.bb | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | # Copyright (C) 2017-2018 NXP | ||
| 2 | |||
| 3 | SUMMARY = "OPTEE Client libs" | ||
| 4 | HOMEPAGE = "http://www.optee.org/" | ||
| 5 | LICENSE = "BSD" | ||
| 6 | LIC_FILES_CHKSUM = "file://LICENSE;md5=69663ab153298557a59c67a60a743e5b" | ||
| 7 | |||
| 8 | inherit pythonnative systemd | ||
| 9 | |||
| 10 | SRCBRANCH = "imx_4.14.78_1.0.0_ga" | ||
| 11 | OPTEE_CLIENT_SRC ?= "git://source.codeaurora.org/external/imx/imx-optee-client.git;protocol=https" | ||
| 12 | SRC_URI = "${OPTEE_CLIENT_SRC};branch=${SRCBRANCH}" | ||
| 13 | |||
| 14 | SRCREV = "d06647d201520ac57f1331e97db6138d63bc2666" | ||
| 15 | |||
| 16 | FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" | ||
| 17 | |||
| 18 | SRC_URI_append = " file://0001-libteec-refactor-_dprintf.patch \ | ||
| 19 | file://tee-supplicant.service" | ||
| 20 | |||
| 21 | S = "${WORKDIR}/git" | ||
| 22 | SYSTEMD_SERVICE_${PN} = "tee-supplicant.service" | ||
| 23 | |||
| 24 | EXTRA_OEMAKE = "CFG_SECURE_DATA_PATH=y" | ||
| 25 | |||
| 26 | do_compile () { | ||
| 27 | if [ ${DEFAULTTUNE} = "aarch64" ]; then | ||
| 28 | oe_runmake -C ${S} ARCH=arm64 | ||
| 29 | else | ||
| 30 | oe_runmake -C ${S} ARCH=arm | ||
| 31 | fi | ||
| 32 | } | ||
| 33 | |||
| 34 | do_install () { | ||
| 35 | oe_runmake install | ||
| 36 | |||
| 37 | install -D -p -m0644 ${S}/out/export/lib/libteec.so.1.0 ${D}${libdir}/libteec.so.1.0 | ||
| 38 | ln -sf libteec.so.1.0 ${D}${libdir}/libteec.so | ||
| 39 | ln -sf libteec.so.1.0 ${D}${libdir}/libteec.so.1 | ||
| 40 | |||
| 41 | install -D -p -m0755 ${S}/out/export/bin/tee-supplicant ${D}${bindir}/tee-supplicant | ||
| 42 | |||
| 43 | cp -a ${S}/out/export/include ${D}/usr/ | ||
| 44 | |||
| 45 | sed -i -e s:/etc:${sysconfdir}:g -e s:/usr/bin:${bindir}:g ${WORKDIR}/tee-supplicant.service | ||
| 46 | install -D -p -m0644 ${WORKDIR}/tee-supplicant.service ${D}${systemd_system_unitdir}/tee-supplicant.service | ||
| 47 | } | ||
| 48 | |||
| 49 | PACKAGES += "tee-supplicant" | ||
| 50 | FILES_${PN} += "${libdir}/* ${includedir}/*" | ||
| 51 | FILES_tee-supplicant += "${bindir}/tee-supplicant" | ||
| 52 | |||
| 53 | INSANE_SKIP_${PN} = "ldflags dev-elf" | ||
| 54 | INSANE_SKIP_${PN}-dev = "ldflags dev-elf" | ||
| 55 | INSANE_SKIP_tee-supplicant = "ldflags" | ||
| 56 | |||
| 57 | COMPATIBLE_MACHINE = "(mx6|mx7|mx8)" | ||
