Add debugproxy stub 82/185682/1
authorIgor Kotrasinski <i.kotrasinsk@partner.samsung.com>
Tue, 10 Jul 2018 08:29:58 +0000 (10:29 +0200)
committerIgor Kotrasinski <i.kotrasinsk@partner.samsung.com>
Tue, 10 Jul 2018 08:32:51 +0000 (10:32 +0200)
Change-Id: Ifb3f5b0cee73f9d19cbdd08b8436de9c5d2e4bb1
Signed-off-by: Igor Kotrasinski <i.kotrasinsk@partner.samsung.com>
CMakeLists.txt
packaging/tef-simulator.spec
simulatordaemon/CMakeLists.txt
simulatordaemon/debugproxy/CMakeLists.txt [new file with mode: 0644]
simulatordaemon/debugproxy/README [new file with mode: 0644]
simulatordaemon/debugproxy/src/main.cpp [new file with mode: 0644]

index 860cce5..53d6468 100644 (file)
@@ -76,6 +76,7 @@ SET(TARGET_TEF_SIMULATOR_LOG ${TARGET_TEF_SIMULATOR}-log)
 SET(TARGET_TEF_SIMULATOR_OSAL ${TARGET_TEF_SIMULATOR}-osal)
 SET(TARGET_TEF_SIMULATOR_DAEMON ${TARGET_TEF_SIMULATOR}-daemon)
 SET(TARGET_TEF_SIMULATOR_DAEMONCTL ${TARGET_TEF_SIMULATOR}-daemonctl)
+SET(TARGET_TEF_SIMULATOR_DEBUGPROXY ${TARGET_TEF_SIMULATOR}-debugproxy)
 SET(TARGET_TEF_SIMULATOR_SSFLIB ${TARGET_TEF_SIMULATOR}-ssflib)
 
 # below targets need different names due to linking with CAs and TAs (libteec for client)
index 7963ef3..7d301a6 100644 (file)
@@ -142,6 +142,7 @@ fi
 %manifest tef-simulator.manifest
 %attr(111,security_fw,security_fw) %{bin_dir}/tef-simulator-daemon
 %attr(111,security_fw,security_fw) %{bin_dir}/tef-simulator-daemonctl
+%attr(111,security_fw,security_fw) %{bin_dir}/tef-simulator-debugproxy
 %{lib_dir}/libtef-simulator-ssflib.so
 %{lib_dir}/libtef-simulator-log.so
 %{lib_dir}/libTEEStubEx.so
index 9fe4d20..7bc382f 100644 (file)
@@ -18,6 +18,7 @@
 #
 
 SET(DAEMONCTL_PATH ${DAEMON_PATH}/daemonctl)
+SET(DEBUGPROXY_PATH ${DAEMON_PATH}/debugproxy)
 
 PKG_CHECK_MODULES(DAEMON_DEPS REQUIRED
                   libsystemd-daemon
@@ -26,8 +27,6 @@ PKG_CHECK_MODULES(DAEMON_DEPS REQUIRED
 
 FIND_PACKAGE(Threads REQUIRED)
 
-SET(DAEMONCTL_PATH ${DAEMON_PATH}/daemonctl)
-
 SET(DAEMON_SOURCES
     ${DAEMON_PATH}/src/ConnectionSession.cpp
     ${DAEMON_PATH}/src/ControlConnectionHandler.cpp
@@ -110,3 +109,4 @@ INSTALL(DIRECTORY DESTINATION ${BUILD_ROOT}${EXTRACT_DIR})
 INSTALL(DIRECTORY DESTINATION ${BUILD_ROOT}${STORAGE_DIR})
 
 ADD_SUBDIRECTORY(daemonctl)
+ADD_SUBDIRECTORY(debugproxy)
diff --git a/simulatordaemon/debugproxy/CMakeLists.txt b/simulatordaemon/debugproxy/CMakeLists.txt
new file mode 100644 (file)
index 0000000..90bb085
--- /dev/null
@@ -0,0 +1,32 @@
+# Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+#
+#    Licensed under the Apache License, Version 2.0 (the "License");
+#    you may not use this file except in compliance with the License.
+#    You may obtain a copy of the License at
+#
+#        http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS,
+#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#    See the License for the specific language governing permissions and
+#    limitations under the License.
+#
+# @file
+# @author  Igor Kotrasinski (i.kotrasinsk@partner.samsung.com)
+# @brief   CMakeLists for tef-simulator daemon debugproxy
+#
+
+SET(DEBUGPROXY_SOURCES
+        ${DEBUGPROXY_PATH}/src/main.cpp
+    )
+
+ADD_EXECUTABLE(${TARGET_TEF_SIMULATOR_DEBUGPROXY}
+    ${DEBUGPROXY_SOURCES}
+    )
+
+INCLUDE_DIRECTORIES(
+        ${DEBUGPROXY_PATH}/inc
+    )
+
+INSTALL(TARGETS ${TARGET_TEF_SIMULATOR_DEBUGPROXY} DESTINATION ${BIN_DIR})
diff --git a/simulatordaemon/debugproxy/README b/simulatordaemon/debugproxy/README
new file mode 100644 (file)
index 0000000..7e10580
--- /dev/null
@@ -0,0 +1,36 @@
+This binary is intended to help tef-simulator punch a hole in MAC for TA
+debugging. Details follow below.
+
+
+Problem
+=======
+- tef-simulator runs with the `System::TEF` label, and so does everything that
+  needs to access TAs
+- This includes instances of gdbserver that the simulator launches when a TA is
+  run with debug mode
+- Currently debugging works as follows:
+    - A mapping between UUIDs and ports can be set up using
+      tef-simulator-daemonctl
+    - When launching a TA, if a mapping is set, gdbserver is launched listening
+      on a provided localhost port
+    - The host can use `sdb forward` to communicate with the gdbserver instance
+      on the device
+    - Under the hood, sdb daemons on host and device communicate on remote
+      ports, serving as proxies between local ports on host and device
+    - sdbd on device runs as `sdk` user with `System` label
+- This causes a problem when gdbserver is run with `System::TEF` label, as a
+  process with a `System` label is denied connection to its port!
+
+
+Solution
+==================
+- Make a new daemon - tef-simulator-debugproxy
+- Runs with `System` label, as `security_fw` user, exposes a
+  `/var/run/tef-simulator-debugproxy` socket
+- The socket has a `security_fw` owner and group, `0660` permissions
+- When launching a TA in debug mode, tef-simulator opens the debugproxy socket
+  and tells the debugproxy which port it should listen to
+- After that, tef-simulator forks, makes the socket its stdin/stdout and runs
+  gdbserver in stdin/out mode
+- The debugproxy listens for connections, gets the port it should listen to,
+  then listens on it forwarding all communications to and from the gdbserver
diff --git a/simulatordaemon/debugproxy/src/main.cpp b/simulatordaemon/debugproxy/src/main.cpp
new file mode 100644 (file)
index 0000000..cb3f748
--- /dev/null
@@ -0,0 +1,3 @@
+int main() {
+       return 0;
+}