There is a privilege escaltion issue in case the temporary directories
(scripts and datadst) are created in advance by an attacker who has set
the sticky bit. To avoid this, SWUpdate will remove and recreate the
directories at each update.
Signed-off-by: Stefano Babic <
stefan...@swupdate.org>
Reported-by : Reinhard Kugler <
RKu...@sba-research.org>
---
core/stream_interface.c | 4 ++++
core/util.c | 2 ++
2 files changed, 6 insertions(+)
diff --git a/core/stream_interface.c b/core/stream_interface.c
index 85d13fda..a0c73470 100644
--- a/core/stream_interface.c
+++ b/core/stream_interface.c
@@ -619,6 +619,10 @@ void *network_initializer(void *data)
TRACE("Software update started");
/* Create directories for scripts/datadst */
+ if (swupdate_remove_directory(SCRIPTS_DIR_SUFFIX) || swupdate_remove_directory(DATADST_DIR_SUFFIX)) {
+ ERROR("Previous dirs cannot be removed, something wrong, skipping...");
+ continue;
+ }
swupdate_create_directory(SCRIPTS_DIR_SUFFIX);
swupdate_create_directory(DATADST_DIR_SUFFIX);
diff --git a/core/util.c b/core/util.c
index f2997b8b..3f62e070 100644
--- a/core/util.c
+++ b/core/util.c
@@ -149,6 +149,8 @@ static int _is_mount_point(const char *path, const char *parent_path) {
struct stat path_stat, parent_stat;
if (stat(path, &path_stat)) {
+ if (errno == ENOENT)
+ return 0;
ERROR("stat for path %s failed: %s", path, strerror(errno));
return -errno;
}
--
2.43.0