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:
Kyle Evans 2019-10-02 02:37:34 +00:00
parent a9fe8c68aa
commit 5a391b572b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=352952
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());
}