diff mbox series

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

Message ID 9231D502B07C5E4A8B32D5115C9F19991F9A9D55@IRSMSX108.ger.corp.intel.com
State RFC, archived
Headers show
Series [OpenWrt-Devel] procd-ujail on initramfs pivot_root fails | expand

Commit Message

Hauke Mehrtens Oct. 18, 2019, 5 p.m. UTC

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:

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;

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:

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:

diff mbox series


--- a/target/linux/generic/other-files/init
+++ b/target/linux/generic/other-files/init
@@ -1,4 +1,14 @@ 
 # 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 *)
+mkdir -p $NEW_ROOT
+mount -t tmpfs tmpfs $NEW_ROOT
+cp -pr $DIRS $NEW_ROOT
+exec switch_root $NEW_ROOT /sbin/init