diff options
| author | Konstantin Belousov <kib@FreeBSD.org> | 2026-08-05 08:04:49 +0000 |
|---|---|---|
| committer | Konstantin Belousov <kib@FreeBSD.org> | 2026-08-05 18:15:54 +0000 |
| commit | e8b9b6b9f31c463137b4104550bfb3286a43703a (patch) | |
| tree | 1cd68a0128de0fff8a58935f7105247f07083210 | |
| parent | 200de1b70e2b4f809d1d3a4c430db80b24124468 (diff) | |
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
| -rw-r--r-- | sys/kern/kern_exit.c | 3 | ||||
| -rw-r--r-- | sys/kern/kern_sig.c | 3 | ||||
| -rw-r--r-- | sys/kern/sys_procdesc.c | 10 | ||||
| -rw-r--r-- | 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> |
