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:
kevans 2019-10-02 02:37:34 +00:00
parent c13136b1b6
commit e3f43eab06
2 changed files with 36 additions and 1 deletions

View File

@ -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));
}
/*

View File

@ -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());
}