[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 04/11] linux-user: make exec_path realpath
From: |
YAMAMOTO Takashi |
Subject: |
[PATCH v2 04/11] linux-user: make exec_path realpath |
Date: |
Mon, 31 May 2021 14:50:11 +0900 |
Otherwise, it can be easily fooled by the user app using chdir().
Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
---
linux-user/main.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/linux-user/main.c b/linux-user/main.c
index a9d02f9583..be604a84f9 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -55,6 +55,7 @@
#endif
char *exec_path;
+char exec_path_store[PATH_MAX];
int exec_fd = -1;
int singlestep;
@@ -611,7 +612,20 @@ static int parse_args(int argc, char **argv)
exit(EXIT_FAILURE);
}
- exec_path = argv[optind];
+ /*
+ * Try to get the realpath of the executable to avoid being
+ * fooled by chdir is the user app.
+ *
+ * Note: realpath here can fail for some use cases.
+ * For example, runc executes an unlinked binary via
+ * /proc/self/fd.
+ * It isn't fatal as far as we have an exec fd.
+ * (Otherwise, we will fail to load the binary.
+ */
+ exec_path = realpath(argv[optind], exec_path_store);
+ if (exec_path == NULL) {
+ exec_path = argv[optind];
+ }
return optind;
}
--
2.21.1 (Apple Git-122.3)
- [PATCH v2 00/11] linux-user changes to run docker, YAMAMOTO Takashi, 2021/05/31
- [PATCH v2 01/11] linux-user: handle /proc/self/exe for execve, YAMAMOTO Takashi, 2021/05/31
- [PATCH v2 02/11] linux-user: Fix the execfd case of /proc/self/exe open, YAMAMOTO Takashi, 2021/05/31
- [PATCH v2 03/11] linux-user: dup the execfd on start up, YAMAMOTO Takashi, 2021/05/31
- [PATCH v2 04/11] linux-user: make exec_path realpath,
YAMAMOTO Takashi <=
- [PATCH v2 05/11] linux-user: Implement pivot_root, YAMAMOTO Takashi, 2021/05/31
- [PATCH v2 06/11] linux-user: add get_exe_path, YAMAMOTO Takashi, 2021/05/31
- [PATCH v2 07/11] linux-user: simplify is_proc_myself, YAMAMOTO Takashi, 2021/05/31
- [PATCH v2 08/11] linux-user: Implement exec of /proc/$pid/exe of qemu process, YAMAMOTO Takashi, 2021/05/31
- [PATCH v2 09/11] linux-user: Make the qemu detection for /proc/$pid/exe a bit conservative, YAMAMOTO Takashi, 2021/05/31
- [PATCH v2 10/11] linux-user: a crude hack for libcontainer (CLONE_PARENT) [!MERGE], YAMAMOTO Takashi, 2021/05/31
- [PATCH v2 11/11] linux-user: always assume preserve_argv0 for now [!MERGE], YAMAMOTO Takashi, 2021/05/31
- Re: [PATCH v2 00/11] linux-user changes to run docker, no-reply, 2021/05/31