mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-16 13:23:36 +00:00
kern_shm_open: push O_CLOEXEC into caller control
The motivation for this change is to allow wrappers around shm to be written that don't set CLOEXEC. kern_shm_open currently accepts O_CLOEXEC but sets it unconditionally. kern_shm_open is used by the shm_open(2) syscall, which is mandated by POSIX to set CLOEXEC, and CloudABI's sys_fd_create1(). Presumably O_CLOEXEC is intended in the latter caller, but it's unclear from the context. sys_shm_open() now unconditionally sets O_CLOEXEC to meet POSIX requirements, and a comment has been dropped in to kern_fd_open() to explain the situation and add a pointer to where O_CLOEXEC setting is maintained for shm_open(2) correctness. CloudABI's sys_fd_create1() also unconditionally sets O_CLOEXEC to match previous behavior. This also has the side-effect of making flags correctly reflect the O_CLOEXEC status on this fd for the rest of kern_shm_open(), but a glance-over leads me to believe that it didn't really matter. Reviewed by: kib, markj MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D21119
This commit is contained in:
parent
43ded0a321
commit
b5a7ac997f
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=350464
|
@ -94,7 +94,8 @@ cloudabi_sys_fd_create1(struct thread *td,
|
|||
case CLOUDABI_FILETYPE_SHARED_MEMORY:
|
||||
cap_rights_init(&fcaps.fc_rights, CAP_FSTAT, CAP_FTRUNCATE,
|
||||
CAP_MMAP_RWX);
|
||||
return (kern_shm_open(td, SHM_ANON, O_RDWR, 0, &fcaps));
|
||||
return (kern_shm_open(td, SHM_ANON, O_RDWR | O_CLOEXEC, 0,
|
||||
&fcaps));
|
||||
default:
|
||||
return (EINVAL);
|
||||
}
|
||||
|
|
|
@ -729,7 +729,14 @@ kern_shm_open(struct thread *td, const char *userpath, int flags, mode_t mode,
|
|||
fdp = td->td_proc->p_fd;
|
||||
cmode = (mode & ~fdp->fd_cmask) & ACCESSPERMS;
|
||||
|
||||
error = falloc_caps(td, &fp, &fd, O_CLOEXEC, fcaps);
|
||||
/*
|
||||
* shm_open(2) created shm should always have O_CLOEXEC set, as mandated
|
||||
* by POSIX. We allow it to be unset here so that an in-kernel
|
||||
* interface may be written as a thin layer around shm, optionally not
|
||||
* setting CLOEXEC. For shm_open(2), O_CLOEXEC is set unconditionally
|
||||
* in sys_shm_open() to keep this implementation compliant.
|
||||
*/
|
||||
error = falloc_caps(td, &fp, &fd, flags & O_CLOEXEC, fcaps);
|
||||
if (error)
|
||||
return (error);
|
||||
|
||||
|
@ -844,7 +851,8 @@ int
|
|||
sys_shm_open(struct thread *td, struct shm_open_args *uap)
|
||||
{
|
||||
|
||||
return (kern_shm_open(td, uap->path, uap->flags, uap->mode, NULL));
|
||||
return (kern_shm_open(td, uap->path, uap->flags | O_CLOEXEC, uap->mode,
|
||||
NULL));
|
||||
}
|
||||
|
||||
int
|
||||
|
|
Loading…
Reference in a new issue