Date: Fri, 16 Aug 2019 21:01:36 +0000 (UTC) From: Kyle Evans <kevans@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r351142 - in stable: 11/sys/compat/cloudabi 11/sys/kern 12/sys/compat/cloudabi 12/sys/kern Message-ID: <201908162101.x7GL1aRM032353@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kevans Date: Fri Aug 16 21:01:35 2019 New Revision: 351142 URL: https://svnweb.freebsd.org/changeset/base/351142 Log: MFC r350464: 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. Modified: stable/12/sys/compat/cloudabi/cloudabi_fd.c stable/12/sys/kern/uipc_shm.c Directory Properties: stable/12/ (props changed) Changes in other areas also in this revision: Modified: stable/11/sys/compat/cloudabi/cloudabi_fd.c stable/11/sys/kern/uipc_shm.c Directory Properties: stable/11/ (props changed) Modified: stable/12/sys/compat/cloudabi/cloudabi_fd.c ============================================================================== --- stable/12/sys/compat/cloudabi/cloudabi_fd.c Fri Aug 16 20:56:35 2019 (r351141) +++ stable/12/sys/compat/cloudabi/cloudabi_fd.c Fri Aug 16 21:01:35 2019 (r351142) @@ -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); } Modified: stable/12/sys/kern/uipc_shm.c ============================================================================== --- stable/12/sys/kern/uipc_shm.c Fri Aug 16 20:56:35 2019 (r351141) +++ stable/12/sys/kern/uipc_shm.c Fri Aug 16 21:01:35 2019 (r351142) @@ -732,7 +732,14 @@ kern_shm_open(struct thread *td, const char *userpath, 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); @@ -847,7 +854,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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201908162101.x7GL1aRM032353>