From owner-dev-commits-src-main@freebsd.org Mon May 10 23:40:03 2021 Return-Path: Delivered-To: dev-commits-src-main@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 0CDC46460A1; Mon, 10 May 2021 23:40:03 +0000 (UTC) (envelope-from git@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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4FfHbQ70KLz4dw2; Mon, 10 May 2021 23:40:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id D865D5A91; Mon, 10 May 2021 23:40:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 14ANe28D012139; Mon, 10 May 2021 23:40:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 14ANe2ro012136; Mon, 10 May 2021 23:40:02 GMT (envelope-from git) Date: Mon, 10 May 2021 23:40:02 GMT Message-Id: <202105102340.14ANe2ro012136@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 5e7cdf181792 - main - openat(2): add O_EMPTY_PATH MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 5e7cdf1817924f8ae0333c0b53c2da32f35b65ea Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 May 2021 23:40:03 -0000 The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=5e7cdf1817924f8ae0333c0b53c2da32f35b65ea commit 5e7cdf1817924f8ae0333c0b53c2da32f35b65ea Author: Konstantin Belousov AuthorDate: 2021-05-06 17:16:53 +0000 Commit: Konstantin Belousov CommitDate: 2021-05-10 23:39:24 +0000 openat(2): add O_EMPTY_PATH It reopens the passed file descriptor, checking the file backing vnode' current access rights against open mode. In particular, this flag allows to convert file descriptor opened with O_PATH, into operable file descriptor, assuming permissions allow that. Reviewed by: markj Tested by: Andrew Walker Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D30148 --- lib/libc/sys/open.2 | 18 +++++++++++++++++- sys/kern/vfs_vnops.c | 2 ++ sys/sys/fcntl.h | 3 +++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/libc/sys/open.2 b/lib/libc/sys/open.2 index a7806df69daf..5a6f161291f6 100644 --- a/lib/libc/sys/open.2 +++ b/lib/libc/sys/open.2 @@ -28,7 +28,7 @@ .\" @(#)open.2 8.2 (Berkeley) 11/16/93 .\" $FreeBSD$ .\" -.Dd March 18, 2021 +.Dd May 6, 2021 .Dt OPEN 2 .Os .Sh NAME @@ -169,6 +169,7 @@ O_CLOEXEC set FD_CLOEXEC upon open O_VERIFY verify the contents of the file O_RESOLVE_BENEATH path resolution must not cross the fd directory O_PATH record only the target path in the opened descriptor +O_EMPTY_PATH openat, open file referenced by fd if path is empty .Ed .Pp Opening a file with @@ -355,6 +356,21 @@ are not allowed. File opened with the .Dv O_PATH flag does not prevent non-forced unmount of the volume it belongs to. +.Pp +A file descriptor created with the +.Dv O_PATH +flag can be opened into normal (operable) file descriptor by +specifying it as the +.Fa fd +argument to +.Fn openat +with empty +.Fa path +and flag +.Dv O_EMPTY_PATH . +Such an open behaves as if the current path of the file referenced by +.Fa fd +is passed, except that the path walk permissions are not checked. See also the description of .Dv AT_EMPTY_PATH flag for diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index d4396f67a67b..670bc4bf8fcc 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -200,6 +200,8 @@ open2nameif(int fmode, u_int vn_open_flags) res = ISOPEN | LOCKLEAF; if ((fmode & O_RESOLVE_BENEATH) != 0) res |= RBENEATH; + if ((fmode & O_EMPTY_PATH) != 0) + res |= EMPTYPATH; if ((vn_open_flags & VN_OPEN_NOAUDIT) == 0) res |= AUDITVNODE1; if ((vn_open_flags & VN_OPEN_NOCAPCHECK) != 0) diff --git a/sys/sys/fcntl.h b/sys/sys/fcntl.h index 58d46ae26338..8fa52aeacafd 100644 --- a/sys/sys/fcntl.h +++ b/sys/sys/fcntl.h @@ -141,6 +141,9 @@ typedef __pid_t pid_t; #endif #define O_DSYNC 0x01000000 /* POSIX data sync */ +#if __BSD_VISIBLE +#define O_EMPTY_PATH 0x02000000 +#endif /* * XXX missing O_RSYNC.