git: e8b9b6b9f31c - main - pdkill(2), pdgetpid(2): return EBADF if the file type is not procdesc

Konstantin Belousov <[email protected]>
Newsgroups gmane.os.freebsd.devel.cvs.src
Message-ID <6a737e0b.32a3c.11aad7f4__47074.4596723065$1785953916$gmane$org@gitrepo.freebsd.org>
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=e8b9b6b9f31c463137b4104550bfb3286a43703a

commit e8b9b6b9f31c463137b4104550bfb3286a43703a
Author:     Konstantin Belousov <[email protected]>
AuthorDate: 2026-08-05 08:04:49 +0000
Commit:     Konstantin Belousov <[email protected]>
CommitDate: 2026-08-05 18:15:54 +0000

    pdkill(2), pdgetpid(2): return EBADF if the file type is not procdesc
    
    For pdwait(2) and pddupfd(2), the returned error is kept EINVAL.
    
    PR:     297293
    Reviewed by:    lwhsu, markj
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D58666
---
 sys/kern/kern_exit.c    |  3 ++-
 sys/kern/kern_sig.c     |  3 ++-
 sys/kern/sys_procdesc.c | 10 ++++++----
 sys/sys/procdesc.h      |  4 ++--
 4 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c
index efdd51e2ec97..fa1721fbaede 100644
--- a/sys/kern/kern_exit.c
+++ b/sys/kern/kern_exit.c
@@ -1563,7 +1563,8 @@ kern_pdwait(struct thread *td, int fd, int *status,
 	if (error != 0)
 		return (error);
 
-	error = fget_procdesc(td, fd, &cap_pdwait_rights, &fp, &pd, NULL);
+	error = fget_procdesc(td, fd, &cap_pdwait_rights, EINVAL, &fp,
+	    &pd, NULL);
 	if (error != 0)
 		goto exit_unlocked;
 
diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c
index 27ab109d2ac5..629ce1c3c40a 100644
--- a/sys/kern/kern_sig.c
+++ b/sys/kern/kern_sig.c
@@ -1965,7 +1965,8 @@ sys_pdkill(struct thread *td, struct pdkill_args *uap)
 		return (EINVAL);
 
 	sx_slock(&proctree_lock);
-	error = fget_procdesc(td, uap->fd, &cap_pdkill_rights, &fp, NULL, &p);
+	error = fget_procdesc(td, uap->fd, &cap_pdkill_rights, EBADF, &fp,
+	    NULL, &p);
 	sx_sunlock(&proctree_lock);
 	if (error != 0)
 		goto out;
diff --git a/sys/kern/sys_procdesc.c b/sys/kern/sys_procdesc.c
index 289b9f100897..0d0ca7b6871c 100644
--- a/sys/kern/sys_procdesc.c
+++ b/sys/kern/sys_procdesc.c
@@ -142,7 +142,7 @@ kern_pdgetpid(struct thread *td, int fd, const cap_rights_t *rightsp,
 	struct file *fp;
 	int error;
 
-	error = fget_procdesc(td, fd, rightsp, &fp, NULL, NULL);
+	error = fget_procdesc(td, fd, rightsp, EBADF, &fp, NULL, NULL);
 	if (error == 0)
 		*pidp = procdesc_pid(fp);
 	if (fp != NULL)
@@ -753,7 +753,8 @@ sys_pdopenpid(struct thread *td, struct pdopenpid_args *args)
  */
 int
 fget_procdesc(struct thread *td, int pdfd, const cap_rights_t *cap_rights,
-    struct file **pfp, struct procdesc **pdp, struct proc **pp)
+    int wrong_type_error, struct file **pfp, struct procdesc **pdp,
+    struct proc **pp)
 {
 	struct file *fp;
 	struct procdesc *pd;
@@ -769,7 +770,7 @@ fget_procdesc(struct thread *td, int pdfd, const cap_rights_t *cap_rights,
 		return (error);
 	*pfp = fp;
 	if (fp->f_type != DTYPE_PROCDESC)
-		return (EINVAL);
+		return (wrong_type_error);
 	pd = fp->f_data;
 	if (pp != NULL) {
 		p = pd->pd_proc;
@@ -795,7 +796,8 @@ kern_pddupfd(struct thread *td, int pdfd, int fd, int flags)
 	int error, fdr;
 
 	sx_slock(&proctree_lock);
-	error = fget_procdesc(td, pdfd, &cap_pddupfd_rights, &pfp, NULL, &p);
+	error = fget_procdesc(td, pdfd, &cap_pddupfd_rights, EINVAL, &pfp,
+	    NULL, &p);
 	if (error == 0) {
 		if ((p->p_flag & P_WEXIT) != 0) {
 			error = ESRCH;
diff --git a/sys/sys/procdesc.h b/sys/sys/procdesc.h
index 0c923509f6eb..6cb837af2d3b 100644
--- a/sys/sys/procdesc.h
+++ b/sys/sys/procdesc.h
@@ -122,8 +122,8 @@ void	 procdesc_fill_winfo(struct procdesc *pd, bool proc_locked);
 int	 procdesc_falloc(struct thread *, struct file **, int *, int,
 	    struct filecaps *);
 int	 fget_procdesc(struct thread *td, int pfd,
-	    const cap_rights_t *cap_rights, struct file **pfp,
-	    struct procdesc **pdp, struct proc **pp);
+	    const cap_rights_t *cap_rights, int wrong_type_error,
+	    struct file **pfp, struct procdesc **pdp, struct proc **pp);
 #else /* !_KERNEL */
 
 #include <sys/cdefs.h>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.