Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 2 Oct 2019 02:37:34 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r352952 - in head: sys/kern tests/sys/posixshm
Message-ID:  <201910020237.x922bZb2060434@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Wed Oct  2 02:37:34 2019
New Revision: 352952
URL: https://svnweb.freebsd.org/changeset/base/352952

Log:
  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

Modified:
  head/sys/kern/uipc_shm.c
  head/tests/sys/posixshm/posixshm_test.c

Modified: head/sys/kern/uipc_shm.c
==============================================================================
--- head/sys/kern/uipc_shm.c	Wed Oct  2 01:27:50 2019	(r352951)
+++ head/sys/kern/uipc_shm.c	Wed Oct  2 02:37:34 2019	(r352952)
@@ -1484,7 +1484,7 @@ kern_shm_open2(struct thread *td, const char *path, in
 	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));
 }
 
 /*

Modified: head/tests/sys/posixshm/posixshm_test.c
==============================================================================
--- head/tests/sys/posixshm/posixshm_test.c	Wed Oct  2 01:27:50 2019	(r352951)
+++ head/tests/sys/posixshm/posixshm_test.c	Wed Oct  2 02:37:34 2019	(r352952)
@@ -881,7 +881,41 @@ 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());
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201910020237.x922bZb2060434>