From owner-svn-src-head@freebsd.org Wed Jul 31 15:16:52 2019 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 30F96A163B; Wed, 31 Jul 2019 15:16:52 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 45zH8N0ZLbz3x11; Wed, 31 Jul 2019 15:16:52 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id CF7033796; Wed, 31 Jul 2019 15:16:51 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x6VFGpjf006505; Wed, 31 Jul 2019 15:16:51 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x6VFGpkb006503; Wed, 31 Jul 2019 15:16:51 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201907311516.x6VFGpkb006503@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Wed, 31 Jul 2019 15:16:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r350464 - in head/sys: compat/cloudabi kern X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: in head/sys: compat/cloudabi kern X-SVN-Commit-Revision: 350464 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 45zH8N0ZLbz3x11 X-Spamd-Bar: / Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [0.56 / 15.00]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_SPAM_SHORT(0.56)[0.563,0] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 31 Jul 2019 15:16:52 -0000 Author: kevans Date: Wed Jul 31 15:16:51 2019 New Revision: 350464 URL: https://svnweb.freebsd.org/changeset/base/350464 Log: 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 Modified: head/sys/compat/cloudabi/cloudabi_fd.c head/sys/kern/uipc_shm.c Modified: head/sys/compat/cloudabi/cloudabi_fd.c ============================================================================== --- head/sys/compat/cloudabi/cloudabi_fd.c Wed Jul 31 05:38:39 2019 (r350463) +++ head/sys/compat/cloudabi/cloudabi_fd.c Wed Jul 31 15:16:51 2019 (r350464) @@ -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: head/sys/kern/uipc_shm.c ============================================================================== --- head/sys/kern/uipc_shm.c Wed Jul 31 05:38:39 2019 (r350463) +++ head/sys/kern/uipc_shm.c Wed Jul 31 15:16:51 2019 (r350464) @@ -729,7 +729,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); @@ -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