git: 32d4139b3eb8 - stable/13 - fsetown: Avoid process group lock recursion

Mark Johnston markj at FreeBSD.org
Wed Sep 1 13:08:02 UTC 2021


The branch stable/13 has been updated by markj:

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

commit 32d4139b3eb8a088add57a326e60ec8e7e2e8f08
Author:     Mark Johnston <markj at FreeBSD.org>
AuthorDate: 2021-08-28 19:50:44 +0000
Commit:     Mark Johnston <markj at FreeBSD.org>
CommitDate: 2021-09-01 13:07:39 +0000

    fsetown: Avoid process group lock recursion
    
    Restore the pre-1d874ba4f8ba behaviour of disassociating the current
    SIGIO recipient before looking up the specified process or process
    group.  This avoids a lock recursion in the scenario where a process
    group is configured to receive SIGIO for an fd when it has already been
    so configured.
    
    Reported by:    pho
    Tested by:      pho
    Reviewed by:    kib
    
    (cherry picked from commit 7326e8589cc21431d62f25802eac7c5dd6f74122)
---
 sys/kern/kern_descrip.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index f78e999ab3b5..ed7fe83cf02f 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -1158,14 +1158,12 @@ fsetown(pid_t pgid, struct sigio **sigiop)
 	sigio->sio_ucred = crhold(curthread->td_ucred);
 	sigio->sio_myref = sigiop;
 
-	osigio = NULL;
 	ret = 0;
 	if (pgid > 0) {
 		ret = pget(pgid, PGET_NOTWEXIT | PGET_NOTID | PGET_HOLD, &proc);
 		SIGIO_LOCK();
+		osigio = funsetown_locked(*sigiop);
 		if (ret == 0) {
-			osigio = funsetown_locked(*sigiop);
-
 			PROC_LOCK(proc);
 			_PRELE(proc);
 			if ((proc->p_flag & P_WEXIT) != 0) {
@@ -1191,12 +1189,11 @@ fsetown(pid_t pgid, struct sigio **sigiop)
 	} else /* if (pgid < 0) */ {
 		sx_slock(&proctree_lock);
 		SIGIO_LOCK();
+		osigio = funsetown_locked(*sigiop);
 		pgrp = pgfind(-pgid);
 		if (pgrp == NULL) {
 			ret = ESRCH;
 		} else {
-			osigio = funsetown_locked(*sigiop);
-
 			if (pgrp->pg_session != curthread->td_proc->p_session) {
 				/*
 				 * Policy - Don't allow a process to FSETOWN a


More information about the dev-commits-src-all mailing list