[OpenWrt-Devel] procd-ujail on initramfs pivot_root fails

Mehrtens, Hauke hauke.mehrtens at intel.com
Fri Oct 18 13:00:31 EDT 2019


Hi,

We want to run some processes in the procd-ujail, this works when we use a SquashFS image and an overlay file system, but when we use an initramfs it does not work.

We see the following error message:
--------------
Fri Oct 18 16:31:51 2019 user.err : jail: pivot_root(/tmp/ujail-ngPNoo, /tmp/ujail-ngPNoo/old) failed: Invalid argument
Fri Oct 18 16:31:51 2019 user.err : jail: failed to build jail fs
--------------
It is failing here:
https://git.openwrt.org/?p=project/procd.git;a=blob;f=jail/jail.c;h=54e78419b539ae6b618bc3680c01fdd9582ea318;hb=HEAD#l158

There is the following code in procd jail.c which looks to me like it should prevent this problem:
--------------
/* oldroot can't be MS_SHARED else pivot_root() fails */
if (mount("none", "/", NULL, MS_REC|MS_PRIVATE, NULL)) {
	ERROR("private mount failed %m\n");
	return -1;
}
--------------
https://git.openwrt.org/?p=project/procd.git;a=blob;f=jail/jail.c;h=54e78419b539ae6b618bc3680c01fdd9582ea318;hb=HEAD#l133


When we switch from initramfs to tmpfs, it is working, we added this code to target/linux/generic/other-files/init to make it work:
--- a/target/linux/generic/other-files/init
+++ b/target/linux/generic/other-files/init
@@ -1,4 +1,14 @@
 #!/bin/sh
 # Copyright (C) 2006 OpenWrt.org
 export INITRAMFS=1
-exec /sbin/init
+
+# switch to tmpfs to allow run daemons in jail on initramfs boot
+DIRS=$(echo *)
+NEW_ROOT=/new_root
+
+mkdir -p $NEW_ROOT
+mount -t tmpfs tmpfs $NEW_ROOT
+
+cp -pr $DIRS $NEW_ROOT
+
+exec switch_root $NEW_ROOT /sbin/init

We see this on a MIPS BE system running OpenWrt master from beginning of March 2019 with kernel 4.9.

I also see this problem also on the MIPS Malta 32 bit BE target of today's OpenWrt master using this configuration and with the patch in this mail I do not see it any more:
CONFIG_TARGET_malta=y
CONFIG_TARGET_malta_be=y
CONFIG_TARGET_malta_be_Default=y
CONFIG_PACKAGE_procd-ujail=y

Hauke

_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list