File U_11-Switch-creat-to-open-with-O_EXCL.patch of Package slurm.32299

From: Tim Wickberg <tim@schedmd.com>
Date: Wed Oct 11 12:45:25 2023 -0600
Subject: [PATCH 11/19]Switch creat() to open() with O_EXCL.
Patch-mainline: Upstream
Git-repo: https://github.com/SchedMD/slurm
Git-commit: 3846d9e959605ac73ffc31c9a2c53d7cddc0af18
References: CVE-2022-29500, bsc#1216207
Signed-off-by: Egbert Eich <eich@suse.de>

Protect against apinfo having been created as a dangling symlink.

Co-authored-by: Alejandro Sanchez <alex@schedmd.com>
---
 src/plugins/mpi/cray_shasta/apinfo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/plugins/mpi/cray_shasta/apinfo.c b/src/plugins/mpi/cray_shasta/apinfo.c
index c13ab80661..fd64d2449f 100644
--- a/src/plugins/mpi/cray_shasta/apinfo.c
+++ b/src/plugins/mpi/cray_shasta/apinfo.c
@@ -381,7 +381,7 @@ static int _open_apinfo(const stepd_step_rec_t *job)
 	apinfo = xstrdup_printf("%s/apinfo", appdir);
 
 	// Create file
-	fd = creat(apinfo, 0600);
+	fd = open(apinfo, (O_CREAT | O_WRONLY | O_TRUNC | O_EXCL), 0600);
 	if (fd == -1) {
 		error("%s: Couldn't open apinfo file %s: %m",
 		      plugin_type, apinfo);
openSUSE Build Service is sponsored by