The branch stable/14 has been updated by jamie:

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

commit 334c8ba7dd9c8dcb2322132cd927f2520126d820
Author:     Jamie Gritton <[email protected]>
AuthorDate: 2026-06-19 19:45:27 +0000
Commit:     Jamie Gritton <[email protected]>
CommitDate: 2026-07-05 03:09:16 +0000

    jail: call PR_METHOD_ATTACH again (with old jail) if the first call fails
    
    jail_attach lets modules do attachment-specific work by calling
    osd_jail_call(PR_METHOD_ATTACH).  If one of the modules returns an
    error, the call needs to be repeated with the thread's current prison,
    so possible earlier modules and undo any changes they may have made.
    
    (cherry picked from commit e91e8ebefadcce9d57c8ff945ff70050cbbe1ce1)
---
 sys/kern/kern_jail.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/sys/kern/kern_jail.c b/sys/kern/kern_jail.c
index 786a4d804115..a18da4472947 100644
--- a/sys/kern/kern_jail.c
+++ b/sys/kern/kern_jail.c
@@ -2680,10 +2680,8 @@ do_jail_attach(struct thread *td, struct prison *pr, int 
drflags)
 
        /* Let modules do whatever they need to prepare for attaching. */
        error = osd_jail_call(pr, PR_METHOD_ATTACH, td);
-       if (error) {
-               prison_deref(pr, drflags);
-               return (error);
-       }
+       if (error)
+               goto e_revert_osd;
        sx_unlock(&allprison_lock);
        drflags &= ~(PD_LIST_SLOCKED | PD_LIST_XLOCKED);
 
@@ -2748,8 +2746,10 @@ do_jail_attach(struct thread *td, struct prison *pr, int 
drflags)
        VOP_UNLOCK(pr->pr_root);
  e_revert_osd:
        /* Tell modules this thread is still in its old jail after all. */
-       sx_slock(&allprison_lock);
-       drflags |= PD_LIST_SLOCKED;
+       if (!(drflags & (PD_LIST_SLOCKED | PD_LIST_XLOCKED))) {
+               sx_slock(&allprison_lock);
+               drflags |= PD_LIST_SLOCKED;
+       }
        (void)osd_jail_call(td->td_ucred->cr_prison, PR_METHOD_ATTACH, td);
        prison_deref(pr, drflags);
        return (error);

Reply via email to