Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F178042667
D58089.1795831975.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
D58089.1795831975.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 28, 2:12 AM (11 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42047769
Default Alt Text
D58089.1795831975.diff (1 KB)
Attached To
Mode
D58089: kern: set UF_RESOLVE_BENEATH on all fds during jail attach
Attached
Detach File
Event Timeline