shm_open2(2): completely unbreak
kern_shm_open2(), since conception, completely fails to pass the mode along to kern_shm_open(). This breaks most uses of it. Add tests alongside this that actually check the mode of the returned files. PR: 240934 [pulseaudio breakage] Reported by: ler, Andrew Gierth [postgres breakage] Diagnosed by: Andrew Gierth (great catch) Tested by: ler, tmunro Pointy hat to: kevans
This commit is contained in:
parent
a9fe8c68aa
commit
5a391b572b
@ -1484,7 +1484,7 @@ kern_shm_open2(struct thread *td, const char *path, int flags, mode_t mode,
|
||||
initial_seals = F_SEAL_SEAL;
|
||||
if ((shmflags & SHM_ALLOW_SEALING) != 0)
|
||||
initial_seals &= ~F_SEAL_SEAL;
|
||||
return (kern_shm_open(td, path, flags, 0, NULL, initial_seals));
|
||||
return (kern_shm_open(td, path, flags, mode, NULL, initial_seals));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -881,6 +881,40 @@ ATF_TC_BODY(cloexec, tc)
|
||||
close(fd);
|
||||
}
|
||||
|
||||
ATF_TC_WITHOUT_HEAD(mode);
|
||||
ATF_TC_BODY(mode, tc)
|
||||
{
|
||||
struct stat st;
|
||||
int fd;
|
||||
mode_t restore_mask;
|
||||
|
||||
gen_test_path();
|
||||
|
||||
/* Remove inhibitions from umask */
|
||||
restore_mask = umask(0);
|
||||
fd = shm_open(test_path, O_CREAT | O_RDWR, 0600);
|
||||
ATF_REQUIRE_MSG(fd >= 0, "shm_open failed; errno=%d", errno);
|
||||
ATF_REQUIRE(fstat(fd, &st) == 0);
|
||||
ATF_REQUIRE((st.st_mode & ACCESSPERMS) == 0600);
|
||||
close(fd);
|
||||
ATF_REQUIRE(shm_unlink(test_path) == 0);
|
||||
|
||||
fd = shm_open(test_path, O_CREAT | O_RDWR, 0660);
|
||||
ATF_REQUIRE_MSG(fd >= 0, "shm_open failed; errno=%d", errno);
|
||||
ATF_REQUIRE(fstat(fd, &st) == 0);
|
||||
ATF_REQUIRE((st.st_mode & ACCESSPERMS) == 0660);
|
||||
close(fd);
|
||||
ATF_REQUIRE(shm_unlink(test_path) == 0);
|
||||
|
||||
fd = shm_open(test_path, O_CREAT | O_RDWR, 0666);
|
||||
ATF_REQUIRE_MSG(fd >= 0, "shm_open failed; errno=%d", errno);
|
||||
ATF_REQUIRE(fstat(fd, &st) == 0);
|
||||
ATF_REQUIRE((st.st_mode & ACCESSPERMS) == 0666);
|
||||
close(fd);
|
||||
ATF_REQUIRE(shm_unlink(test_path) == 0);
|
||||
|
||||
umask(restore_mask);
|
||||
}
|
||||
|
||||
ATF_TP_ADD_TCS(tp)
|
||||
{
|
||||
@ -914,6 +948,7 @@ ATF_TP_ADD_TCS(tp)
|
||||
ATF_TP_ADD_TC(tp, unlink_path_too_long);
|
||||
ATF_TP_ADD_TC(tp, object_resize);
|
||||
ATF_TP_ADD_TC(tp, cloexec);
|
||||
ATF_TP_ADD_TC(tp, mode);
|
||||
|
||||
return (atf_no_error());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user