aboutsummaryrefslogtreecommitdiff
path: root/sys/compat/linux/linux_util.c
diff options
context:
space:
mode:
authorDmitry Chagin <dchagin@FreeBSD.org>2023-05-29 08:16:46 +0000
committerDmitry Chagin <dchagin@FreeBSD.org>2023-05-29 08:16:46 +0000
commitfd745e1db6b561900b8e5e9caa4ed05cf15398b3 (patch)
tree70a8872a57c71fc4bbf7818c5c5c51db03d2c836 /sys/compat/linux/linux_util.c
parent3d2fec7db856c67e1a94a87a846d8ffe6f48b61f (diff)
linux(4): Use pwd_altroot() to tell namei() about ABI root path
PR: 72920 Differential Revision: https://reviews.freebsd.org/D40090 MFC after: 2 month
Diffstat (limited to 'sys/compat/linux/linux_util.c')
-rw-r--r--sys/compat/linux/linux_util.c41
1 files changed, 28 insertions, 13 deletions
diff --git a/sys/compat/linux/linux_util.c b/sys/compat/linux/linux_util.c
index afb0bb082dd5..4431bdd479c7 100644
--- a/sys/compat/linux/linux_util.c
+++ b/sys/compat/linux/linux_util.c
@@ -79,23 +79,38 @@ SYSCTL_STRING(_compat_linux, OID_AUTO, emul_path, CTLFLAG_RWTUN,
linux_emul_path, sizeof(linux_emul_path),
"Linux runtime environment path");
-/*
- * Search an alternate path before passing pathname arguments on to
- * system calls. Useful for keeping a separate 'emulation tree'.
- *
- * If cflag is set, we check if an attempt can be made to create the
- * named file, i.e. we check if the directory it should be in exists.
- */
int
-linux_emul_convpath(const char *path, enum uio_seg pathseg,
- char **pbuf, int cflag, int dfd)
+linux_pwd_onexec(struct thread *td)
{
- int retval;
+ struct nameidata nd;
+ struct pwd *pwd;
+ int error;
- retval = kern_alternate_path(linux_emul_path, path, pathseg, pbuf,
- cflag, dfd);
+ NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, linux_emul_path);
+ error = namei(&nd);
+ if (error != 0) {
+ /*
+ * Do not bother if we are in chroot or jail.
+ */
+ pwd = pwd_hold(td);
+ if (pwd->pwd_rdir != rootvnode) {
+ pwd_drop(pwd);
+ return (0);
+ }
+ pwd_drop(pwd);
+ return (error);
+ }
+ NDFREE_PNBUF(&nd);
+ pwd_altroot(td, nd.ni_vp);
+ vrele(nd.ni_vp);
+ return (0);
+}
+
+void
+linux_pwd_onexec_native(struct thread *td)
+{
- return (retval);
+ pwd_altroot(td, NULL);
}
void