From nobody Mon Dec 6 20:18:34 2021 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 7160A18CCC88; Mon, 6 Dec 2021 20:18:35 +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 4J7FB25lXyz4qDp; Mon, 6 Dec 2021 20:18:34 +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 9E9EF12769; Mon, 6 Dec 2021 20:18:34 +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 1B6KIYL1087201; Mon, 6 Dec 2021 20:18:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1B6KIY3p087200; Mon, 6 Dec 2021 20:18:34 GMT (envelope-from git) Date: Mon, 6 Dec 2021 20:18:34 GMT Message-Id: <202112062018.1B6KIY3p087200@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: 794d3e8e63f4 - main - fcntl(2): add F_KINFO operation List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org 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: 794d3e8e63f4a6ebc8926030b6c937109ddc5485 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1638821914; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iMOuqbsCcI0wjNKVsXmaV5Mx1twteRvTK8dgr+9os4g=; b=hXsC7EcLd0kh2m5MgwKPFo2Wc81U+5dOgX5bEKYVK1W+J8nhdSniO2lSG5vLYhY5X3G2ay J+4O0KGSHHJhRCLnVhBDSLxfYL725jkRi+Se6yxFNh/LOsgYLsrlGnM2v80Vl5qCGU4wRi kHZv57WlqNW4hzSFJjEMrTq46x/HuXfno2sLSr04jW6OjnBVdA+MV5J6r4nYt0oi544PVG bA5wRC2XI/q8qm/DKEqncvQMkiqgGoiOhWvHGFzvNToTjXnpy5tO1H1jS5z5+MtNf52RqD ZKqF9Io//M1X9j907+JPc7ciTNKj/pLat3Sy4oMCf5Ai1r0tnuELx05pW8nTRQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1638821914; a=rsa-sha256; cv=none; b=DRUQwRpIwwrMK8KmXFpUJiXKAx1ZaPPfxQzY6YlPtE/+9LrK4dyKM206eX2A8QuoEkU4XX W95fQCobUITxkueLH2F2kjRCxbfCW4oFdCDEXCwlO7ibMBLhDurRewBKtcebK6k0lgIyvF GIol9JC3Km4mrqM9kSpQFeBshrJ2a4gp8RXJCs1+3f8mXJEWORmBpa2oX3rgUM/tNSgwv2 oCkXHaLqF4KPAUd0ACK0dNE3UQ++NVKySZXLeMDQuohFuvSvQhMe4AUYk7sUAyftFooWPe XOo1TOU4cKNCypajJwBAyaf2qzS5YxtxVPt8hwGCeZwUbUv4lEbmjSYmMMOtgA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=794d3e8e63f4a6ebc8926030b6c937109ddc5485 commit 794d3e8e63f4a6ebc8926030b6c937109ddc5485 Author: Konstantin Belousov AuthorDate: 2021-12-05 18:45:50 +0000 Commit: Konstantin Belousov CommitDate: 2021-12-06 20:18:09 +0000 fcntl(2): add F_KINFO operation that returns struct kinfo_file for the given file descriptor. Among other data, it also returns kf_path, if file op was able to restore file path. Reviewed by: jhb, markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D33277 --- lib/libc/sys/fcntl.2 | 17 ++++++++++++++-- sys/compat/freebsd32/freebsd32_misc.c | 1 + sys/kern/kern_descrip.c | 38 ++++++++++++++++++++++++++++++++++- sys/sys/fcntl.h | 1 + 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/lib/libc/sys/fcntl.2 b/lib/libc/sys/fcntl.2 index 33ad7a5673e1..c0a13ee6df18 100644 --- a/lib/libc/sys/fcntl.2 +++ b/lib/libc/sys/fcntl.2 @@ -28,7 +28,7 @@ .\" @(#)fcntl.2 8.2 (Berkeley) 1/12/94 .\" $FreeBSD$ .\" -.Dd January 6, 2021 +.Dd December 7, 2021 .Dt FCNTL 2 .Os .Sh NAME @@ -53,7 +53,7 @@ Depending on the value of .Fa cmd , .Fn fcntl can take an additional third argument -.Fa "int arg" . +.Fa "long arg" . .Bl -tag -width F_DUP2FD_CLOEXEC .It Dv F_DUPFD Return a new descriptor as follows: @@ -190,6 +190,19 @@ Check if the vnode is part of a union stack (either the "union" flag from .Xr mount 2 or unionfs). This is a hack not intended to be used outside of libc. +.It Dv F_KINFO +Fills a +.Vt struct kinfo_file +for the file referenced by the specified file descriptor. +The +.Fa arg +argument should point to the storage for +.Vt struct kinfo_file . +The +.Va kf_structsize +member of the passed structure must be initialized with the sizeof of +.Vt struct kinfo_file , +to allow for the interface versioning and evolution. .El .Pp The flags for the diff --git a/sys/compat/freebsd32/freebsd32_misc.c b/sys/compat/freebsd32/freebsd32_misc.c index a51daec85fcd..89322772a83c 100644 --- a/sys/compat/freebsd32/freebsd32_misc.c +++ b/sys/compat/freebsd32/freebsd32_misc.c @@ -3767,6 +3767,7 @@ freebsd32_fcntl(struct thread *td, struct freebsd32_fcntl_args *uap) case F_OGETLK: case F_OSETLK: case F_OSETLKW: + case F_KINFO: tmp = (unsigned int)(uap->arg); break; default: diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 8970e80a9818..03cc77ff31ba 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -480,7 +480,8 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg) struct proc *p; struct vnode *vp; struct mount *mp; - int error, flg, seals, tmp; + struct kinfo_file *kif; + int error, flg, kif_sz, seals, tmp; uint64_t bsize; off_t foffset; @@ -855,6 +856,41 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg) fdrop(fp, td); break; + case F_KINFO: +#ifdef CAPABILITY_MODE + if (IN_CAPABILITY_MODE(td)) { + error = ECAPMODE; + break; + } +#endif + error = copyin((void *)arg, &kif_sz, sizeof(kif_sz)); + if (error != 0) + break; + if (kif_sz != sizeof(*kif)) { + error = EINVAL; + break; + } + kif = malloc(sizeof(*kif), M_TEMP, M_WAITOK | M_ZERO); + FILEDESC_SLOCK(fdp); + error = fget_cap_locked(fdp, fd, &cap_fcntl_rights, &fp, NULL); + if (error == 0 && fhold(fp)) { + export_file_to_kinfo(fp, fd, NULL, kif, fdp, 0); + FILEDESC_SUNLOCK(fdp); + fdrop(fp, td); + if ((kif->kf_status & KF_ATTR_VALID) != 0) { + kif->kf_structsize = sizeof(*kif); + error = copyout(kif, (void *)arg, sizeof(*kif)); + } else { + error = EBADF; + } + } else { + FILEDESC_SUNLOCK(fdp); + if (error == 0) + error = EBADF; + } + free(kif, M_TEMP); + break; + default: error = EINVAL; break; diff --git a/sys/sys/fcntl.h b/sys/sys/fcntl.h index 934c648aecc0..491b0172a1e6 100644 --- a/sys/sys/fcntl.h +++ b/sys/sys/fcntl.h @@ -270,6 +270,7 @@ typedef __pid_t pid_t; #define F_ADD_SEALS 19 #define F_GET_SEALS 20 #define F_ISUNIONSTACK 21 /* Kludge for libc, don't use it. */ +#define F_KINFO 22 /* Return kinfo_file for this fd */ /* Seals (F_ADD_SEALS, F_GET_SEALS). */ #define F_SEAL_SEAL 0x0001 /* Prevent adding sealings */