From owner-svn-src-all@freebsd.org Mon Aug 31 15:07:16 2020 Return-Path: Delivered-To: svn-src-all@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 BAE973C4121; Mon, 31 Aug 2020 15:07:16 +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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 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 4BgD842C19z4cyl; Mon, 31 Aug 2020 15:07:16 +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 E45029A5B; Mon, 31 Aug 2020 15:07:15 +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 07VF7Fcm097926; Mon, 31 Aug 2020 15:07:15 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 07VF7Fcf097925; Mon, 31 Aug 2020 15:07:15 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <202008311507.07VF7Fcf097925@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Mon, 31 Aug 2020 15:07:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r364990 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 364990 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 Aug 2020 15:07:16 -0000 Author: kevans Date: Mon Aug 31 15:07:15 2020 New Revision: 364990 URL: https://svnweb.freebsd.org/changeset/base/364990 Log: posixshm: fix setting of shm_flags Noted in D24652, we currently set shmfd->shm_flags on every shm_open()/shm_open2(). This wasn't properly thought out; one shouldn't be able to specify incompatible flags on subsequent opens of non-anon shm. Move setting of shm_flags explicitly to the two places shmfd are created, as we do with seals, and validate when we're opening a pre-existing mapping that we've either passed no flags or we've passed the exact same flags as the first time. Reviewed by: kib, markj Differential Revision: https://reviews.freebsd.org/D26242 Modified: head/sys/kern/uipc_shm.c Modified: head/sys/kern/uipc_shm.c ============================================================================== --- head/sys/kern/uipc_shm.c Mon Aug 31 15:03:23 2020 (r364989) +++ head/sys/kern/uipc_shm.c Mon Aug 31 15:07:15 2020 (r364990) @@ -833,6 +833,7 @@ kern_shm_open2(struct thread *td, const char *userpath } shmfd = shm_alloc(td->td_ucred, cmode); shmfd->shm_seals = initial_seals; + shmfd->shm_flags = shmflags; } else { error = shm_copyin_path(td, userpath, &path); if (error != 0) { @@ -855,6 +856,7 @@ kern_shm_open2(struct thread *td, const char *userpath #endif shmfd = shm_alloc(td->td_ucred, cmode); shmfd->shm_seals = initial_seals; + shmfd->shm_flags = shmflags; shm_insert(path, fnv, shmfd); #ifdef MAC } @@ -898,6 +900,8 @@ kern_shm_open2(struct thread *td, const char *userpath else if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) error = EEXIST; + else if (shmflags != 0 && shmflags != shmfd->shm_flags) + error = EINVAL; else { #ifdef MAC error = mac_posixshm_check_open(td->td_ucred, @@ -947,7 +951,6 @@ kern_shm_open2(struct thread *td, const char *userpath } } - shmfd->shm_flags = shmflags; finit(fp, FFLAGS(flags & O_ACCMODE), DTYPE_SHM, shmfd, &shm_ops); td->td_retval[0] = fd;