Skip to content

Commit

Permalink
tee-supplicant: add CFG_TEE_SUPP_PLUGINS to enable or not plugin support
Browse files Browse the repository at this point in the history
This change allows optee_client configuration to enable or not supplicant
plugin support. The feature is enabled from switch CFG_TEE_SUPP_PLUGINS.
The configuration is default enable for backward compatibility purpose.

There are OSes where TEE supplicant plugin cannot be supported for
example when the OS does not enable dynamic/shared libraries. Such
systems should still be able to embed OP-TEE assuming the supplicant
plugin support is not embedded. Prior this change was optee_client
failing to build for such systems with a error message like the one
below reported by Buildroot CI build [1]:

/tmp/instance-2/output-1/build/optee-client-3.13.0/tee-supplicant/src/plugin.c:8:10: fatal error: dlfcn.h: No such file or directory
    8 | #include <dlfcn.h>
      |          ^~~~~~~~~

Link: [1] http://autobuild.buildroot.net/results/56d1ec172d0d857d6a968397b7785f961fad1043/
Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
Acked-by: Jerome Forissier <jerome@forissier.org>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
  • Loading branch information
etienne-lms authored and jforissier committed Aug 26, 2021
1 parent 7197806 commit f591143
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 14 deletions.
1 change: 1 addition & 0 deletions Android.mk
Expand Up @@ -11,6 +11,7 @@ CFG_TEE_SUPP_LOG_LEVEL ?= 2
CFG_TEE_CLIENT_LOAD_PATH ?= /vendor/lib
TEEC_TEST_LOAD_PATH ?= /data/vendor/tee
CFG_TEE_FS_PARENT_PATH ?= /data/vendor/tee
CFG_TEE_SUPP_PLUGINS ?= y
ifneq ($(strip $($(combo_2nd_arch_prefix)TARGET_TOOLS_PREFIX)),)
CFG_TEE_PLUGIN_LOAD_PATH ?= /vendor/lib64/tee-supplicant/plugins/
else
Expand Down
4 changes: 4 additions & 0 deletions config.mk
Expand Up @@ -33,6 +33,10 @@ CFG_TEE_CLIENT_LOG_FILE ?= $(CFG_TEE_FS_PARENT_PATH)/teec.log
# The location of the client library file.
CFG_TEE_CLIENT_LOAD_PATH ?= /lib

# CFG_TEE_SUPP_PLUGINS
# Enable (y) or disable (n) TEE supplicant plugin support
CFG_TEE_SUPP_PLUGINS ?= y

# CFG_TEE_PLUGIN_LOAD_PATH
# The location of the user plugins
CFG_TEE_PLUGIN_LOAD_PATH ?= /usr/lib/tee-supplicant/plugins/
Expand Down
27 changes: 23 additions & 4 deletions tee-supplicant/CMakeLists.txt
Expand Up @@ -7,6 +7,7 @@ option (CFG_TA_TEST_PATH "Enable tee-supplicant to load from test/debug path" OF
option (RPMB_EMU "Enable tee-supplicant to emulate RPMB" ON)
option (CFG_TA_GPROF_SUPPORT "Enable tee-supplicant support for TAs instrumented with gprof" ON)
option (CFG_FTRACE_SUPPORT "Enable tee-supplicant support for TAs instrumented with ftrace" ON)
option (CFG_TEE_SUPP_PLUGINS "Enable tee-supplicant plugin support" ON)

set (CFG_TEE_SUPP_LOG_LEVEL "1" CACHE STRING "tee-supplicant log level")
# FIXME: Question is, is this really needed? Should just use defaults from # GNUInstallDirs?
Expand All @@ -15,7 +16,10 @@ set (CFG_TEE_FS_PARENT_PATH "/data/tee" CACHE STRING "Location of TEE filesystem
# FIXME: Why do we have if defined(CFG_GP_SOCKETS) && CFG_GP_SOCKETS == 1 in the c-file?
set (CFG_GP_SOCKETS "1" CACHE STRING "Enable GlobalPlatform Socket API support")
set (CFG_TEE_PLUGIN_LOAD_PATH "/usr/lib/tee-supplicant/plugins/" CACHE STRING "tee-supplicant's plugins path")
set (CMAKE_INSTALL_RPATH "${CFG_TEE_PLUGIN_LOAD_PATH}")

if (CFG_TEE_SUPP_PLUGINS)
set (CMAKE_INSTALL_RPATH "${CFG_TEE_PLUGIN_LOAD_PATH}")
endif()

################################################################################
# Source files
Expand All @@ -28,7 +32,6 @@ set (SRC
src/tee_supp_fs.c
src/tee_supplicant.c
src/teec_ta_load.c
src/plugin.c
)

if (CFG_GP_SOCKETS)
Expand All @@ -39,6 +42,10 @@ if (CFG_TA_GPROF_SUPPORT OR CFG_FTRACE_SUPPORT)
set (SRC ${SRC} src/prof.c)
endif()

if (CFG_TEE_SUPP_PLUGINS)
set (SRC ${SRC} src/plugin.c)
endif()

################################################################################
# Built binary
################################################################################
Expand All @@ -52,7 +59,6 @@ target_compile_definitions (${PROJECT_NAME}
PRIVATE -DTEEC_LOAD_PATH="${CFG_TEE_CLIENT_LOAD_PATH}"
PRIVATE -DTEE_FS_PARENT_PATH="${CFG_TEE_FS_PARENT_PATH}"
PRIVATE -DBINARY_PREFIX="TSUP"
PRIVATE -DTEE_PLUGIN_LOAD_PATH="${CFG_TEE_PLUGIN_LOAD_PATH}"
)

################################################################################
Expand Down Expand Up @@ -83,6 +89,13 @@ if (CFG_FTRACE_SUPPORT)
PRIVATE -DCFG_FTRACE_SUPPORT)
endif()

if (CFG_TEE_SUPP_PLUGINS)
target_compile_definitions (${PROJECT_NAME}
PRIVATE -DTEE_SUPP_PLUGINS
PRIVATE -DTEE_PLUGIN_LOAD_PATH="${CFG_TEE_PLUGIN_LOAD_PATH}"
)
endif()

################################################################################
# Public and private header and library dependencies
################################################################################
Expand All @@ -91,7 +104,13 @@ target_include_directories(${PROJECT_NAME} PRIVATE src)
target_link_libraries (${PROJECT_NAME}
PRIVATE teec
PRIVATE optee-client-headers
PRIVATE dl)
)

if (CFG_TEE_SUPP_PLUGINS)
target_link_libraries (${PROJECT_NAME}
PRIVATE dl
)
endif()

################################################################################
# Install targets
Expand Down
19 changes: 14 additions & 5 deletions tee-supplicant/Makefile
Expand Up @@ -18,9 +18,7 @@ TEES_SRCS := tee_supplicant.c \
teec_ta_load.c \
tee_supp_fs.c \
rpmb.c \
handle.c \
plugin.c

handle.c

ifeq ($(CFG_GP_SOCKETS),y)
TEES_SRCS += tee_socket.c
Expand All @@ -33,6 +31,10 @@ ifneq (,$(filter y,$(CFG_TA_GPROF_SUPPORT) $(CFG_FTRACE_SUPPORT)))
TEES_SRCS += prof.c
endif

ifeq ($(CFG_TEE_SUPP_PLUGINS),y)
TEES_SRCS += plugin.c
endif

TEES_SRC_DIR := src
TEES_OBJ_DIR := $(OUT_DIR)
TEES_OBJS := $(patsubst %.c,$(TEES_OBJ_DIR)/%.o, $(TEES_SRCS))
Expand All @@ -45,7 +47,6 @@ TEES_CFLAGS := $(addprefix -I, $(TEES_INCLUDES)) $(CFLAGS) \
-DBINARY_PREFIX=\"TEES\" \
-DTEE_FS_PARENT_PATH=\"$(CFG_TEE_FS_PARENT_PATH)\" \
-DTEEC_LOAD_PATH=\"$(CFG_TEE_CLIENT_LOAD_PATH)\" \
-DTEE_PLUGIN_LOAD_PATH=\"$(CFG_TEE_PLUGIN_LOAD_PATH)\"

ifeq ($(CFG_GP_SOCKETS),y)
TEES_CFLAGS += -DCFG_GP_SOCKETS=1
Expand All @@ -67,13 +68,21 @@ ifeq ($(CFG_FTRACE_SUPPORT),y)
TEES_CFLAGS += -DCFG_FTRACE_SUPPORT
endif

ifeq ($(CFG_TEE_SUPP_PLUGINS),y)
TEES_CFLAGS += -DTEE_SUPP_PLUGINS \
-DTEE_PLUGIN_LOAD_PATH=\"$(CFG_TEE_PLUGIN_LOAD_PATH)\"
endif

TEES_LFLAGS += -lpthread
# Needed to get clock_gettime() for for glibc versions before 2.17
TEES_LFLAGS += -lrt

ifeq ($(CFG_TEE_SUPP_PLUGINS),y)
# Needed to dynamically load user plugins
TEES_LFLAGS += -ldl
# Needed for dlopen()
TEES_LFLAGS += -Wl,-rpath=$(CFG_TEE_PLUGIN_LOAD_PATH)
TEES_LFLAGS += -Wl,-rpath=$(CFG_TEE_PLUGIN_LOAD_PATH)
endif

tee-supplicant: $(TEES_FILE)

Expand Down
16 changes: 16 additions & 0 deletions tee-supplicant/src/plugin.h
Expand Up @@ -19,6 +19,7 @@ struct plugin {
struct plugin *next;
};

#ifdef TEE_SUPP_PLUGINS
/*
* Loads all shared objects from 'CFG_TEE_PLUGIN_LOAD_PATH'
* and binds all functions.
Expand All @@ -29,6 +30,21 @@ TEEC_Result plugin_load_all(void);

/* Plugin RPC handler */
TEEC_Result plugin_process(size_t num_params, struct tee_ioctl_param *params);
#else
static inline TEEC_Result plugin_load_all(void)
{
return TEEC_SUCCESS;
}

static inline TEEC_Result plugin_process(size_t num_params,
struct tee_ioctl_param *params)
{
(void)num_params;
(void)params;

return TEEC_ERROR_NOT_SUPPORTED;
}
#endif /*TEE_SUPP_PLUGINS*/

#endif /* PLUGIN_H */

16 changes: 11 additions & 5 deletions tee-supplicant/tee_supplicant_android.mk
Expand Up @@ -9,8 +9,7 @@ LOCAL_CFLAGS += $(optee_CFLAGS)
LOCAL_CFLAGS += -DDEBUGLEVEL_$(CFG_TEE_SUPP_LOG_LEVEL) \
-DBINARY_PREFIX=\"TEES\" \
-DTEE_FS_PARENT_PATH=\"$(CFG_TEE_FS_PARENT_PATH)\" \
-DTEEC_LOAD_PATH=\"$(CFG_TEE_CLIENT_LOAD_PATH)\" \
-DTEE_PLUGIN_LOAD_PATH=\"$(CFG_TEE_PLUGIN_LOAD_PATH)\"
-DTEEC_LOAD_PATH=\"$(CFG_TEE_CLIENT_LOAD_PATH)\"

ifneq ($(TEEC_TEST_LOAD_PATH),)
LOCAL_CFLAGS += -DTEEC_TEST_LOAD_PATH=\"$(TEEC_TEST_LOAD_PATH)\"
Expand All @@ -24,8 +23,7 @@ LOCAL_SRC_FILES += src/tee_supplicant.c \
src/teec_ta_load.c \
src/tee_supp_fs.c \
src/rpmb.c \
src/handle.c \
src/plugin.c
src/handle.c

ifeq ($(CFG_GP_SOCKETS),y)
LOCAL_SRC_FILES += src/tee_socket.c
Expand All @@ -46,11 +44,19 @@ ifeq ($(CFG_TA_GPROF_SUPPORT),y)
LOCAL_CFLAGS += -DCFG_TA_GPROF_SUPPORT
endif

LOCAL_CFLAGS += -pthread
ifeq ($(CFG_TEE_SUPP_PLUGINS),y)
LOCAL_SRC_FILES += src/plugin.c

LOCAL_CFLAGS += -DTEE_SUPP_PLUGINS \
-DTEE_PLUGIN_LOAD_PATH=\"$(CFG_TEE_PLUGIN_LOAD_PATH)\"

# Needed to dynamically load user plugins
LOCAL_LDFLAGS += -ldl
# Needed for dlopen()
LOCAL_LDFLAGS += -Wl,-rpath=$(CFG_TEE_PLUGIN_LOAD_PATH)
endif

LOCAL_CFLAGS += -pthread

ifeq ($(CFG_FTRACE_SUPPORT),y)
LOCAL_CFLAGS += -DCFG_FTRACE_SUPPORT
Expand Down

0 comments on commit f591143

Please sign in to comment.