Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F152956981
D31970.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D31970.id.diff
View Options
diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -399,13 +399,13 @@
if ((fmode & O_PATH) == 0 || (fmode & FEXEC) != 0)
return (EMLINK);
}
- if (vp->v_type == VSOCK)
- return (EOPNOTSUPP);
if (vp->v_type != VDIR && fmode & O_DIRECTORY)
return (ENOTDIR);
accmode = 0;
if ((fmode & O_PATH) == 0) {
+ if (vp->v_type == VSOCK)
+ return (EOPNOTSUPP);
if ((fmode & (FWRITE | O_TRUNC)) != 0) {
if (vp->v_type == VDIR)
return (EISDIR);
@@ -437,11 +437,8 @@
return (error);
}
if ((fmode & O_PATH) != 0) {
- if (vp->v_type == VFIFO)
- error = EPIPE;
- else
- error = VOP_ACCESS(vp, VREAD, cred, td);
- if (error == 0)
+ if (vp->v_type != VFIFO && vp->v_type != VSOCK &&
+ VOP_ACCESS(vp, VREAD, cred, td) == 0)
fp->f_flag |= FKQALLOWED;
return (0);
}
diff --git a/tests/sys/file/path_test.c b/tests/sys/file/path_test.c
--- a/tests/sys/file/path_test.c
+++ b/tests/sys/file/path_test.c
@@ -845,13 +845,15 @@
CHECKED_CLOSE(sd[1]);
}
-/* Verify that a local socket can't be opened with O_PATH. */
+/* Verify that a local socket can be opened with O_PATH. */
ATF_TC_WITHOUT_HEAD(path_unix);
ATF_TC_BODY(path_unix, tc)
{
- char path[PATH_MAX];
+ char buf[BUFSIZ], path[PATH_MAX];
+ struct kevent ev;
struct sockaddr_un sun;
- int pathfd, sd;
+ struct stat sb;
+ int kq, pathfd, sd;
snprintf(path, sizeof(path), "path_unix.XXXXXX");
ATF_REQUIRE_MSG(mktemp(path) == path, FMT_ERR("mktemp"));
@@ -866,9 +868,31 @@
FMT_ERR("bind"));
pathfd = open(path, O_PATH);
- ATF_REQUIRE_ERRNO(EOPNOTSUPP, pathfd < 0);
+ ATF_REQUIRE_MSG(pathfd >= 0, FMT_ERR("open"));
+
+ ATF_REQUIRE_MSG(fstatat(pathfd, "", &sb, AT_EMPTY_PATH) == 0,
+ FMT_ERR("fstatat"));
+ ATF_REQUIRE_MSG(sb.st_mode & S_IFSOCK, "socket mode %#x", sb.st_mode);
+ ATF_REQUIRE_MSG(sb.st_ino != 0, "socket has inode number 0");
+
+ memset(buf, 0, sizeof(buf));
+ ATF_REQUIRE_ERRNO(EBADF, write(pathfd, buf, sizeof(buf)));
+ ATF_REQUIRE_ERRNO(EBADF, read(pathfd, buf, sizeof(buf)));
+
+ /* kevent() is disallowed with sockets. */
+ kq = kqueue();
+ ATF_REQUIRE_MSG(kq >= 0, FMT_ERR("kqueue"));
+ EV_SET(&ev, pathfd, EVFILT_READ, EV_ADD | EV_ENABLE, 0, 0, 0);
+ ATF_REQUIRE_ERRNO(EBADF, kevent(kq, &ev, 1, NULL, 0, NULL) == -1);
+
+ /* Should not be able to open a socket without O_PATH. */
+ ATF_REQUIRE_ERRNO(EOPNOTSUPP, openat(pathfd, "", O_EMPTY_PATH) == -1);
+
+ ATF_REQUIRE_MSG(funlinkat(AT_FDCWD, path, pathfd, 0) == 0,
+ FMT_ERR("funlinkat"));
CHECKED_CLOSE(sd);
+ CHECKED_CLOSE(pathfd);
}
ATF_TP_ADD_TCS(tp)
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Apr 19, 7:54 AM (5 h, 19 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31754728
Default Alt Text
D31970.id.diff (2 KB)
Attached To
Mode
D31970: vfs: Permit unix sockets to be opened with O_PATH
Attached
Detach File
Event Timeline
Log In to Comment