File U_08-Use-rmdir_recursive.patch of Package slurm.31097

From: Tim Wickberg <tim@schedmd.com>
Date: Wed Oct 11 12:45:25 2023 -0600
Subject: [PATCH 8/19]Use rmdir_recursive().
Patch-mainline: Upstream
Git-repo: https://github.com/SchedMD/slurm
Git-commit: 3a0aa849da7877278b7d7b6c632c3654e8a0d4e1
References: bsc#1216207,CVE-2023-41914
Signed-off-by: Egbert Eich <eich@suse.de>

Discard vulnerable pmixp_rmdir_recursively().

Co-authored-by: Alejandro Sanchez <alex@schedmd.com>
---
 src/plugins/mpi/pmix/pmixp_client.c |  4 +--
 src/plugins/mpi/pmix/pmixp_utils.c  | 55 -------------------------------------
 src/plugins/mpi/pmix/pmixp_utils.h  |  1 -
 3 files changed, 2 insertions(+), 58 deletions(-)

diff --git a/src/plugins/mpi/pmix/pmixp_client.c b/src/plugins/mpi/pmix/pmixp_client.c
index caffced03b..d9a9c4d5af 100644
--- a/src/plugins/mpi/pmix/pmixp_client.c
+++ b/src/plugins/mpi/pmix/pmixp_client.c
@@ -486,14 +486,14 @@ extern int pmixp_libpmix_finalize(void)
 
 	rc = pmixp_lib_finalize();
 
-	rc1 = pmixp_rmdir_recursively(pmixp_info_tmpdir_lib());
+	rc1 = rmdir_recursive(pmixp_info_tmpdir_lib(), true);
 	if (0 != rc1) {
 		PMIXP_ERROR_STD("Failed to remove %s\n",
 				pmixp_info_tmpdir_lib());
 		/* Not considering this as fatal error */
 	}
 
-	rc1 = pmixp_rmdir_recursively(pmixp_info_tmpdir_cli());
+	rc1 = rmdir_recursive(pmixp_info_tmpdir_cli(), true);
 	if (0 != rc1) {
 		PMIXP_ERROR_STD("Failed to remove %s\n",
 				pmixp_info_tmpdir_cli());
diff --git a/src/plugins/mpi/pmix/pmixp_utils.c b/src/plugins/mpi/pmix/pmixp_utils.c
index 0d4ed2341b..f1faf05210 100644
--- a/src/plugins/mpi/pmix/pmixp_utils.c
+++ b/src/plugins/mpi/pmix/pmixp_utils.c
@@ -469,61 +469,6 @@ int pmixp_p2p_send(const char *nodename, const char *address, const char *data,
 	return rc;
 }
 
-static int _is_dir(char *path)
-{
-	struct stat stat_buf;
-	int rc;
-	if (0 > (rc = stat(path, &stat_buf))) {
-		PMIXP_ERROR_STD("Cannot stat() path=\"%s\"", path);
-		return rc;
-	} else if (!S_ISDIR(stat_buf.st_mode)) {
-		return 0;
-	}
-	return 1;
-}
-
-int pmixp_rmdir_recursively(char *path)
-{
-	char nested_path[PATH_MAX];
-	DIR *dp;
-	struct dirent *ent;
-
-	int rc;
-
-	/*
-	 * Make sure that "directory" exists and is a directory.
-	 */
-	if (1 != (rc = _is_dir(path))) {
-		PMIXP_ERROR("path=\"%s\" is not a directory", path);
-		return (rc == 0) ? -1 : rc;
-	}
-
-	if ((dp = opendir(path)) == NULL) {
-		PMIXP_ERROR_STD("cannot open path=\"%s\"", path);
-		return -1;
-	}
-
-	while ((ent = readdir(dp)) != NULL) {
-		if (0 == xstrcmp(ent->d_name, ".")
-		    || 0 == xstrcmp(ent->d_name, "..")) {
-			/* skip special dir's */
-			continue;
-		}
-		snprintf(nested_path, sizeof(nested_path), "%s/%s", path,
-			 ent->d_name);
-		if (_is_dir(nested_path)) {
-			pmixp_rmdir_recursively(nested_path);
-		} else {
-			unlink(nested_path);
-		}
-	}
-	closedir(dp);
-	if ((rc = rmdir(path))) {
-		PMIXP_ERROR_STD("Cannot remove path=\"%s\"", path);
-	}
-	return rc;
-}
-
 int pmixp_mkdir(char *path)
 {
 	char *base = NULL, *newdir = NULL, *slash;
diff --git a/src/plugins/mpi/pmix/pmixp_utils.h b/src/plugins/mpi/pmix/pmixp_utils.h
index b68c5cb1af..5d598427d8 100644
--- a/src/plugins/mpi/pmix/pmixp_utils.h
+++ b/src/plugins/mpi/pmix/pmixp_utils.h
@@ -60,7 +60,6 @@ int pmixp_stepd_send(const char *nodelist, const char *address,
 int pmixp_p2p_send(const char *nodename, const char *address, const char *data,
 		   uint32_t len, unsigned int start_delay,
 		   unsigned int retry_cnt, int silent);
-int pmixp_rmdir_recursively(char *path);
 int pmixp_mkdir(char *path);
 
 /* lightweight pmix list of pointers */
openSUSE Build Service is sponsored by