From owner-svn-src-stable@freebsd.org Fri Aug 16 21:01:36 2019 Return-Path: Delivered-To: svn-src-stable@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 DEE38AEB31; Fri, 16 Aug 2019 21:01:36 +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 469G2m55Sbz4lj3; Fri, 16 Aug 2019 21:01:36 +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 906FB7185; Fri, 16 Aug 2019 21:01:36 +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 x7GL1asU032347; Fri, 16 Aug 2019 21:01:36 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x7GL1aNQ032345; Fri, 16 Aug 2019 21:01:36 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201908162101.x7GL1aNQ032345@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Fri, 16 Aug 2019 21:01:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r351142 - in stable: 11/sys/compat/cloudabi 11/sys/kern 12/sys/compat/cloudabi 12/sys/kern X-SVN-Group: stable-11 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: in stable: 11/sys/compat/cloudabi 11/sys/kern 12/sys/compat/cloudabi 12/sys/kern X-SVN-Commit-Revision: 351142 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Aug 2019 21:01:36 -0000 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/11/sys/compat/cloudabi/cloudabi_fd.c stable/11/sys/kern/uipc_shm.c Directory Properties: stable/11/ (props changed) Changes in other areas also in this revision: Modified: stable/12/sys/compat/cloudabi/cloudabi_fd.c stable/12/sys/kern/uipc_shm.c Directory Properties: stable/12/ (props changed) Modified: stable/11/sys/compat/cloudabi/cloudabi_fd.c ============================================================================== --- stable/11/sys/compat/cloudabi/cloudabi_fd.c Fri Aug 16 20:56:35 2019 (r351141) +++ stable/11/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/11/sys/kern/uipc_shm.c ============================================================================== --- stable/11/sys/kern/uipc_shm.c Fri Aug 16 20:56:35 2019 (r351141) +++ stable/11/sys/kern/uipc_shm.c Fri Aug 16 21:01:35 2019 (r351142) @@ -705,7 +705,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); @@ -819,7 +826,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