Skip to content

Commit

Permalink
kqueue: on process exit, force-clear its registered signal events
Browse files Browse the repository at this point in the history
Normally, process already has all its kqueue fds destroyed at the moment
p_klist is detached in exit flow. But, if the process was created with
rfork(2) with shared file descriptors, its signal knotes can survive.
Then, knlist_detach() does not destroy non-empty knlist. Later, when
owning kqueue is closed, we access freed (or rather, reused, because
struct proc is type-stable) memory by referencing p->p_klist from such
knote.

Handle this situation by deleting all knotes hanging from p_klist.

PR:	275286
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D42745
  • Loading branch information
kostikbel committed Nov 24, 2023
1 parent 50335b1 commit 393ac29
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions sys/kern/kern_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,7 @@ proc_reap(struct thread *td, struct proc *p, int *status, int options)
proc_id_clear(PROC_ID_PID, p->p_pid);

PROC_LOCK(p);
knlist_delete(p->p_klist, td, 1);
knlist_detach(p->p_klist);
p->p_klist = NULL;
PROC_UNLOCK(p);
Expand Down

0 comments on commit 393ac29

Please sign in to comment.