From nobody Sun Feb 11 01:52:44 2024 X-Original-To: dev-commits-src-branches@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 4TXVwD2MVMz59641; Sun, 11 Feb 2024 01:52:44 +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 4TXVwD1VyTz45w3; Sun, 11 Feb 2024 01:52:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707616364; 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=njeisKh0espyNKexl8PhRvKFayfAt0MwM4MTzs/4dhE=; b=RlVuIXeFTLyUW/TN+A/8X6FfQMBKidecrSs8x0raB3cxTVKqnsiiWZVs78wfZ7P1TPXECp NQsGXH040s3E2Dkth0FrQMb5NkNdfD9O3DEbe2GhISTapoz9YoyTXEIY/HbCIa4eP0MYPc aVBlL+CplYw66H1UoHbw/RzBN4dF3ArbLS7PtOqIQeFIrXEva40d1tsLVUAL3/dCDZtei1 gOSfBOGskpHbZdCK+UcAOMOB4Yz+1jG1oQIgbreVhxtNLaDQAox4CT1/tY6NStCe6MWqN2 r1YVDvwIxxIY093bGHE2C7jVxMookTFChdzlZ0hl6XqrOJQmWxSgPjc7FjNWjw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1707616364; a=rsa-sha256; cv=none; b=M984/s4u+3w/jp42zuepT04uIklg0sj1xZpEn9Dq1CvFH+0pBnOscAfpzUQMfvvjsPU5pU UwaVNxa6oPMLTL19ZRcucQ2UOTsXSnahCa/hkYt8/BUoZtepwOdvtcS8G7cNls4cPPwp4s 8MEMduFGb+kgAjMGHQqf/cfXyHKxh/3Uug0kEJ0EAf6l9qiqdZ154ZjdHkhM4xTGnf2eI2 FnMsSUawBHMxUuhOxDnK6O8wT2lwrq+poWaMLXoBuSkdrMDT9AomBGSvRvK/x/9bB/H/7e DXstyBaXXiTBAtJrwcCuGnJsppidU7r14BFw3+uD+TNOHlncOCC1ZJ4uIzqPAA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707616364; 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=njeisKh0espyNKexl8PhRvKFayfAt0MwM4MTzs/4dhE=; b=qXrY1hKQqufaQss38BgqY9nrnLdmBceNcRZIKDBU+bPE7gsXSQpMWhianPCQKzKduvOWiw +PBZChk0HaN0zfqFAh/8q9yjWhAqpKUA3fjabbOZewEu03dpz9gtrSXSzxvAETvg5qOWRC fkLz+T6RnxivDBRttZizuP4IGr1zuJmdwgIb6bAgWoGbCEV3Lg1aDOarAZG7PzzOXHaEMr C7Eqhb/QxWYfZmO9ZpBGI9gn7jMxfBI5u6i5962yxAYNWR38pb5QaDDu/rYnGhA68HQMjX miB3uzl0+VBI7yQ+zG5MzHkhxLbaZmDWmULsfbvBSKuPCJQee2oEg8VZRG8SdA== 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 4TXVwD0YM2zgFv; Sun, 11 Feb 2024 01:52:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41B1qij2089287; Sun, 11 Feb 2024 01:52:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41B1qitV089284; Sun, 11 Feb 2024 01:52:44 GMT (envelope-from git) Date: Sun, 11 Feb 2024 01:52:44 GMT Message-Id: <202402110152.41B1qitV089284@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: eb34be853a21 - stable/13 - Add fget_remote() List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/stable/13 X-Git-Reftype: branch X-Git-Commit: eb34be853a21e05db54ad6f22abe366bc5b6086b Auto-Submitted: auto-generated The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=eb34be853a21e05db54ad6f22abe366bc5b6086b commit eb34be853a21e05db54ad6f22abe366bc5b6086b Author: Konstantin Belousov AuthorDate: 2024-01-22 22:31:55 +0000 Commit: Konstantin Belousov CommitDate: 2024-02-11 01:40:28 +0000 Add fget_remote() (cherry picked from commit 58d3171698341c664d7c676541b86385a924ae93) --- sys/kern/kern_descrip.c | 32 ++++++++++++++++++++++++++++++++ sys/sys/file.h | 1 + 2 files changed, 33 insertions(+) diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 0bd011ac2425..0a28f47bccdf 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -3055,6 +3055,38 @@ get_locked: return (error); } +int +fget_remote(struct thread *td, struct proc *p, int fd, struct file **fpp) +{ + struct filedesc *fdp; + struct file *fp; + int error; + + if (p == td->td_proc) /* curproc */ + return (fget_unlocked(p->p_fd, fd, &cap_no_rights, fpp)); + + PROC_LOCK(p); + fdp = fdhold(p); + PROC_UNLOCK(p); + if (fdp == NULL) + return (ENOENT); + FILEDESC_SLOCK(fdp); + if (refcount_load(&fdp->fd_refcnt) != 0) { + fp = fget_locked(fdp, fd); + if (fp != NULL && fhold(fp)) { + *fpp = fp; + error = 0; + } else { + error = EBADF; + } + } else { + error = ENOENT; + } + FILEDESC_SUNLOCK(fdp); + fddrop(fdp); + return (error); +} + #ifdef CAPABILITIES int fgetvp_lookup_smr(int fd, struct nameidata *ndp, struct vnode **vpp, bool *fsearch) diff --git a/sys/sys/file.h b/sys/sys/file.h index e5532b37572f..ca8a229b994a 100644 --- a/sys/sys/file.h +++ b/sys/sys/file.h @@ -257,6 +257,7 @@ int fget_write(struct thread *td, int fd, cap_rights_t *rightsp, int fget_fcntl(struct thread *td, int fd, cap_rights_t *rightsp, int needfcntl, struct file **fpp); int _fdrop(struct file *fp, struct thread *td); +int fget_remote(struct thread *td, struct proc *p, int fd, struct file **fpp); fo_rdwr_t invfo_rdwr; fo_truncate_t invfo_truncate;