sysctl_kern_proc_umask() held the target process and then read
p->p_pd->pd_cmask without the process lock and without a reference on
the pwddesc. The hold keeps exit1() from freeing p_pd, but it does not
stop pdswap(). pdswap() releases the old pwddesc, which can then be
freed while the sysctl still reads it.
Read pd_cmask with the process lock held instead of holding the process.
pdescfree_tail() waits for the process lock to be dropped before it
releases the old pwddesc, so the pwddesc read from p_pd under the lock
stays valid until the unlock. pget() checks P_WEXIT under the same
lock, and exit1() sets P_WEXIT before pdescfree() clears p_pd, so p_pd
cannot be NULL either.
Reported by: llm-postcr
Fixes: 6ce13747dc3c ("Add sysctl to retrieve or set umask of another process.")Details
Details
- Reviewers
markj - Commits
- rG684531038126: kern: fix use after free in sysctl_kern_proc_umask()
Diff Detail
Diff Detail
- Repository
- rG FreeBSD src repository
- Lint
Lint Not Applicable - Unit
Tests Not Applicable