]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
Provide O_SEARCH
authorkevans <kevans@FreeBSD.org>
Sun, 2 Feb 2020 16:34:57 +0000 (16:34 +0000)
committerkevans <kevans@FreeBSD.org>
Sun, 2 Feb 2020 16:34:57 +0000 (16:34 +0000)
commit11e74d9fa26b9a1948b06d8cce76932b0ac05212
treedb300f6040643046bb920b04cfb37a8576cec10d
parent1f9321e091492a0c796f68445b1478ec4e22fab3
Provide O_SEARCH

O_SEARCH is defined by POSIX [0] to open a directory for searching, skipping
permissions checks on the directory itself after the initial open(). This is
close to the semantics we've historically applied for O_EXEC on a directory,
which is UB according to POSIX. Conveniently, O_SEARCH on a file is also
explicitly undefined behavior according to POSIX, so O_EXEC would be a fine
choice. The spec goes on to state that O_SEARCH and O_EXEC need not be
distinct values, but they're not defined to be the same value.

This was pointed out as an incompatibility with other systems that had made
its way into libarchive, which had assumed that O_EXEC was an alias for
O_SEARCH.

This defines compatibility O_SEARCH/FSEARCH (equivalent to O_EXEC and FEXEC
respectively) and expands our UB for O_EXEC on a directory. O_EXEC on a
directory is checked in vn_open_vnode already, so for completeness we add a
NOEXECCHECK when O_SEARCH has been specified on the top-level fd and do not
re-check that when descending in namei.

[0] https://pubs.opengroup.org/onlinepubs/9699919799/

Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D23247
15 files changed:
contrib/netbsd-tests/lib/libc/c063/t_o_search.c
lib/libc/sys/open.2
lib/libc/tests/c063/Makefile
sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
sys/fs/devfs/devfs_vnops.c
sys/fs/fuse/fuse_vnops.c
sys/fs/nfsclient/nfs_clvnops.c
sys/fs/smbfs/smbfs_vnops.c
sys/fs/tmpfs/tmpfs_vnops.c
sys/kern/vfs_cache.c
sys/kern/vfs_lookup.c
sys/kern/vfs_subr.c
sys/sys/fcntl.h
sys/sys/namei.h
sys/sys/vnode.h