Skip to content

Commit aa2c14d

Browse files
[OpenMP] Close up permissions on /tmp files (#85469)
The SHM or /tmp files that might be created during library registration don't need to have such open permissions, so this change fixes that.
1 parent 51f7b26 commit aa2c14d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

openmp/runtime/src/kmp_runtime.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6752,11 +6752,11 @@ void __kmp_register_library_startup(void) {
67526752
int fd1 = -1;
67536753
shm_name = __kmp_str_format("/%s", name);
67546754
int shm_preexist = 0;
6755-
fd1 = shm_open(shm_name, O_CREAT | O_EXCL | O_RDWR, 0666);
6755+
fd1 = shm_open(shm_name, O_CREAT | O_EXCL | O_RDWR, 0600);
67566756
if ((fd1 == -1) && (errno == EEXIST)) {
67576757
// file didn't open because it already exists.
67586758
// try opening existing file
6759-
fd1 = shm_open(shm_name, O_RDWR, 0666);
6759+
fd1 = shm_open(shm_name, O_RDWR, 0600);
67606760
if (fd1 == -1) { // file didn't open
67616761
KMP_WARNING(FunctionError, "Can't open SHM");
67626762
__kmp_shm_available = false;
@@ -6800,11 +6800,11 @@ void __kmp_register_library_startup(void) {
68006800
int fd1 = -1;
68016801
temp_reg_status_file_name = __kmp_str_format("/tmp/%s", name);
68026802
int tmp_preexist = 0;
6803-
fd1 = open(temp_reg_status_file_name, O_CREAT | O_EXCL | O_RDWR, 0666);
6803+
fd1 = open(temp_reg_status_file_name, O_CREAT | O_EXCL | O_RDWR, 0600);
68046804
if ((fd1 == -1) && (errno == EEXIST)) {
68056805
// file didn't open because it already exists.
68066806
// try opening existing file
6807-
fd1 = open(temp_reg_status_file_name, O_RDWR, 0666);
6807+
fd1 = open(temp_reg_status_file_name, O_RDWR, 0600);
68086808
if (fd1 == -1) { // file didn't open if (fd1 == -1) {
68096809
KMP_WARNING(FunctionError, "Can't open TEMP");
68106810
__kmp_tmp_available = false;
@@ -6944,7 +6944,7 @@ void __kmp_unregister_library(void) {
69446944
int fd1;
69456945
if (__kmp_shm_available) {
69466946
shm_name = __kmp_str_format("/%s", name);
6947-
fd1 = shm_open(shm_name, O_RDONLY, 0666);
6947+
fd1 = shm_open(shm_name, O_RDONLY, 0600);
69486948
if (fd1 != -1) { // File opened successfully
69496949
char *data1 = (char *)mmap(0, SHM_SIZE, PROT_READ, MAP_SHARED, fd1, 0);
69506950
if (data1 != MAP_FAILED) {

0 commit comments

Comments
 (0)