From nobody Wed Jan 31 00:46:06 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 4TPjyQ4mbBz580d5; Wed, 31 Jan 2024 00:46:06 +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 4TPjyQ2lX3z45VR; Wed, 31 Jan 2024 00:46:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706661966; 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=EenYaNVYpIMbCuawSUQ+A2Qdnr/oXzvUfjSiUWpgdv8=; b=HwLzc79kYXRnd88mX+a8t/NctfpZuU9pZj7TU38lEZRR64JakivLahSfbq8tvm4iI0E7dg RWb9Nf32mnz68mGEGZrMka12rYcgU06q2KvnaGj/q8g/OlomGzs0209rc7TSWu9MwJMjHn HBLWyZ2OpBYBK2gcixmI7/HH7Jlh7d+2JB/ZOPegTvhCcOEBqcpHhy8E+H1rnaIXX0OTfX s3ku5j/Zm5c9kx8oXCXwRFQKsv6yZuXaB7nGjk2HTHM7/XFAQ/XQbnQQ4av0iWzcf1/bb8 DE3rDE0/VMws45pjUdh8CszB6gH1XqwsG2gHfbtUjkZFQ2Ch2uMV2skv7+ugZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706661966; 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=EenYaNVYpIMbCuawSUQ+A2Qdnr/oXzvUfjSiUWpgdv8=; b=IQCzyyOPVIrRab+Z7yVXVkp92DNCZRLwlMHephaFbAqru9tFJWh8D68cbMzg1Kml8+R5fn GRiOVIC/3iJ6DBrdByOS+mNJVBIO2K6fsfa9eTDIU4h1k23Q1NJHQnsE2bIo+Q3fPIJNcb EEl2K4YYIgds/yhDtBKBTHtpic837ajYIax1Fftx8Dry9XXbOxqFZRFLlOsC/HCjyK9pmJ SXLsIZomo4sDKtBiOrdTwK3l22U+DctyBYR65vjhY8EIwONWc1WtZ6A9V61/bDXJiT8hk9 QnDMTKVi1/0a2UMuhEvBJ9ZhLbQKniVpmpTR+w9Go4/+VGeEbIPPWScOqG6gTg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706661966; a=rsa-sha256; cv=none; b=L8p6VdQLv9f8Cx72FQJnLz8FQaIQnRZKS/Hw/COkQmE8tPMItbt6/kLjkFK8NqBuXjQRG8 2XJcurson277Dg4SBZ2BncbanGlWqm37JSmk6CDfvs3SmUovGW/Gd7xeUwt5vvQH5TKOTi ylUAmliCcfEw2CBG93inDyavivHPK7sQmtzRP4sdHdsqSHltHD5zW9GZS/Gh37rikLUOFN tHn7XVQNzJAXoiXT99YreSSEnOY6rUj1mZJ3evlCtG3sARE31AXQSp3W9Zz2q0aPLdgPER 63D/72+UyKOFpvHY+4ykcCbJ6SdD2baCRzzLFo+Vhp3HpnXMa2AuYldMtLtrXA== 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 4TPjyQ1fM2zxmd; Wed, 31 Jan 2024 00:46:06 +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 40V0k6j4063327; Wed, 31 Jan 2024 00:46:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40V0k6qU063324; Wed, 31 Jan 2024 00:46:06 GMT (envelope-from git) Date: Wed, 31 Jan 2024 00:46:06 GMT Message-Id: <202401310046.40V0k6qU063324@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: 3e3b87ea6e69 - stable/14 - 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/14 X-Git-Reftype: branch X-Git-Commit: 3e3b87ea6e6936c4757391477075d487b6745a12 Auto-Submitted: auto-generated The branch stable/14 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=3e3b87ea6e6936c4757391477075d487b6745a12 commit 3e3b87ea6e6936c4757391477075d487b6745a12 Author: Konstantin Belousov AuthorDate: 2024-01-22 22:31:55 +0000 Commit: Konstantin Belousov CommitDate: 2024-01-30 20:24:42 +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 fe6928e421db..7bb392eee6b2 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -2962,6 +2962,38 @@ fget_cap(struct thread *td, int fd, cap_rights_t *needrightsp, } #endif +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(td, 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_noref(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(struct nameidata *ndp, struct vnode **vpp, bool *fsearch) diff --git a/sys/sys/file.h b/sys/sys/file.h index cf2544ee70cf..ab8aefbb32f1 100644 --- a/sys/sys/file.h +++ b/sys/sys/file.h @@ -263,6 +263,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;