Page MenuHomeFreeBSD

D58089.1795832318.diff
No OneTemporary

Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None

D58089.1795832318.diff

diff --git a/sys/kern/kern_jail.c b/sys/kern/kern_jail.c
--- a/sys/kern/kern_jail.c
+++ b/sys/kern/kern_jail.c
@@ -49,6 +49,7 @@
#include <sys/event.h>
#include <sys/taskqueue.h>
#include <sys/fcntl.h>
+#include <sys/filedesc.h>
#include <sys/jail.h>
#include <sys/jaildesc.h>
#include <sys/linker.h>
@@ -3066,6 +3067,34 @@
rctl_proc_ucred_changed(p, newcred);
crfree(newcred);
#endif
+ /*
+ * Set UF_RESOLVE_BENEATH on all existing file descriptors to
+ * prevent the jailed process from using them to escape the
+ * jail's directory tree. This must be done under FILEDESC_XLOCK
+ * to prevent other threads from installing new file descriptors
+ * without the flag while we iterate.
+ *
+ * XXX: Other threads with in-flight syscalls that cached the old
+ * credentials may install new file descriptors without the flag
+ * after FILEDESC_XUNLOCK. This is the same race as the one
+ * documented above for multi-threaded jail attach.
+ */
+ if (oldcred->cr_prison->pr_root != pr->pr_root) {
+ struct filedesc *fdp;
+ struct fdescenttbl *fdt;
+ struct filedescent *fde;
+ int fd;
+
+ fdp = p->p_fd;
+ FILEDESC_XLOCK(fdp);
+ fdt = fdp->fd_files;
+ for (fd = 0; fd < fdt->fdt_nfiles; fd++) {
+ fde = &fdt->fdt_ofiles[fd];
+ if (fde->fde_file != NULL)
+ fde->fde_flags |= UF_RESOLVE_BENEATH;
+ }
+ FILEDESC_XUNLOCK(fdp);
+ }
prison_proc_relink(oldcred->cr_prison, pr, p);
prison_deref(oldcred->cr_prison, drflags);
crfree(oldcred);

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 28, 2:18 AM (11 h, 29 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42047769
Default Alt Text
D58089.1795832318.diff (1 KB)

Event Timeline