Add fallback to mount syscall (#1349)
This commit is contained in:
82
userspace/ksud/Cargo.lock
generated
82
userspace/ksud/Cargo.lock
generated
@@ -121,25 +121,6 @@ version = "1.6.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b"
|
checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bindgen"
|
|
||||||
version = "0.60.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "062dddbc1ba4aca46de6338e2bf87771414c335f7b2f2036e8f3e9befebf88e6"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags 1.3.2",
|
|
||||||
"cexpr",
|
|
||||||
"clang-sys",
|
|
||||||
"lazy_static",
|
|
||||||
"lazycell",
|
|
||||||
"peeking_take_while",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"regex",
|
|
||||||
"rustc-hash",
|
|
||||||
"shlex",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "1.3.2"
|
version = "1.3.2"
|
||||||
@@ -209,15 +190,6 @@ dependencies = [
|
|||||||
"jobserver",
|
"jobserver",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cexpr"
|
|
||||||
version = "0.6.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
|
|
||||||
dependencies = [
|
|
||||||
"nom",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cfg-if"
|
name = "cfg-if"
|
||||||
version = "0.1.10"
|
version = "0.1.10"
|
||||||
@@ -254,17 +226,6 @@ dependencies = [
|
|||||||
"generic-array",
|
"generic-array",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "clang-sys"
|
|
||||||
version = "1.7.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "67523a3b4be3ce1989d607a828d036249522dd9c1c8de7f4dd2dae43a37369d1"
|
|
||||||
dependencies = [
|
|
||||||
"glob",
|
|
||||||
"libc",
|
|
||||||
"libloading",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap"
|
name = "clap"
|
||||||
version = "4.1.4"
|
version = "4.1.4"
|
||||||
@@ -618,12 +579,6 @@ version = "0.27.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e"
|
checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "glob"
|
|
||||||
version = "0.3.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "heck"
|
name = "heck"
|
||||||
version = "0.4.1"
|
version = "0.4.1"
|
||||||
@@ -875,12 +830,6 @@ version = "1.4.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "lazycell"
|
|
||||||
version = "1.3.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.152"
|
version = "0.2.152"
|
||||||
@@ -907,16 +856,6 @@ dependencies = [
|
|||||||
"rle-decode-fast",
|
"rle-decode-fast",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "libloading"
|
|
||||||
version = "0.8.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c571b676ddfc9a8c12f1f3d3085a7b163966a8fd8098a90640953ce5f6170161"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if 1.0.0",
|
|
||||||
"windows-sys 0.48.0",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libm"
|
name = "libm"
|
||||||
version = "0.2.6"
|
version = "0.2.6"
|
||||||
@@ -953,9 +892,8 @@ checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "loopdev"
|
name = "loopdev"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
source = "git+https://github.com/tiann/loopdev?branch=loopfix#b6ca5e3ea163f66239f6a835874fe231b2a9286f"
|
source = "git+https://github.com/Kernel-SU/loopdev#7a921f8d966477a645b1188732fac486c71a68ef"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bindgen",
|
|
||||||
"errno 0.2.8",
|
"errno 0.2.8",
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
@@ -1080,12 +1018,6 @@ dependencies = [
|
|||||||
"sha2",
|
"sha2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "peeking_take_while"
|
|
||||||
version = "0.1.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pin-project-lite"
|
name = "pin-project-lite"
|
||||||
version = "0.2.9"
|
version = "0.2.9"
|
||||||
@@ -1349,12 +1281,6 @@ version = "0.1.23"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
|
checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rustc-hash"
|
|
||||||
version = "1.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustix"
|
name = "rustix"
|
||||||
version = "0.36.7"
|
version = "0.36.7"
|
||||||
@@ -1469,12 +1395,6 @@ dependencies = [
|
|||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "shlex"
|
|
||||||
version = "1.3.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "strsim"
|
name = "strsim"
|
||||||
version = "0.10.0"
|
version = "0.10.0"
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ rustix = { git = "https://github.com/Kernel-SU/rustix.git", branch = "main", fea
|
|||||||
# some android specific dependencies which compiles under unix are also listed here for convenience of coding
|
# some android specific dependencies which compiles under unix are also listed here for convenience of coding
|
||||||
android-properties = { version = "0.2.2", features = ["bionic-deprecated"] }
|
android-properties = { version = "0.2.2", features = ["bionic-deprecated"] }
|
||||||
procfs = "0.16"
|
procfs = "0.16"
|
||||||
loopdev = { git = "https://github.com/tiann/loopdev", branch = "loopfix" }
|
loopdev = { git = "https://github.com/Kernel-SU/loopdev" }
|
||||||
|
|
||||||
[target.'cfg(target_os = "android")'.dependencies]
|
[target.'cfg(target_os = "android")'.dependencies]
|
||||||
android_logger = "0.13"
|
android_logger = "0.13"
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ pub fn mount_ext4(source: impl AsRef<Path>, target: impl AsRef<Path>) -> Result<
|
|||||||
let new_loopback = loopdev::LoopControl::open()?.next_free()?;
|
let new_loopback = loopdev::LoopControl::open()?.next_free()?;
|
||||||
new_loopback.with().attach(source)?;
|
new_loopback.with().attach(source)?;
|
||||||
let lo = new_loopback.path().ok_or(anyhow!("no loop"))?;
|
let lo = new_loopback.path().ok_or(anyhow!("no loop"))?;
|
||||||
let fs = fsopen("ext4", FsOpenFlags::FSOPEN_CLOEXEC)?;
|
if let Result::Ok(fs) = fsopen("ext4", FsOpenFlags::FSOPEN_CLOEXEC) {
|
||||||
let fs = fs.as_fd();
|
let fs = fs.as_fd();
|
||||||
fsconfig_set_string(fs, "source", lo)?;
|
fsconfig_set_string(fs, "source", lo)?;
|
||||||
fsconfig_create(fs)?;
|
fsconfig_create(fs)?;
|
||||||
@@ -71,6 +71,9 @@ pub fn mount_ext4(source: impl AsRef<Path>, target: impl AsRef<Path>) -> Result<
|
|||||||
target.as_ref(),
|
target.as_ref(),
|
||||||
MoveMountFlags::MOVE_MOUNT_F_EMPTY_PATH,
|
MoveMountFlags::MOVE_MOUNT_F_EMPTY_PATH,
|
||||||
)?;
|
)?;
|
||||||
|
} else {
|
||||||
|
mount(lo, target.as_ref(), "ext4", MountFlags::empty(), "")?;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +105,7 @@ pub fn mount_overlayfs(
|
|||||||
upperdir,
|
upperdir,
|
||||||
workdir
|
workdir
|
||||||
);
|
);
|
||||||
let fs = fsopen("overlay", FsOpenFlags::FSOPEN_CLOEXEC)?;
|
if let Result::Ok(fs) = fsopen("overlay", FsOpenFlags::FSOPEN_CLOEXEC) {
|
||||||
let fs = fs.as_fd();
|
let fs = fs.as_fd();
|
||||||
fsconfig_set_string(fs, "lowerdir", lowerdir_config)?;
|
fsconfig_set_string(fs, "lowerdir", lowerdir_config)?;
|
||||||
if let (Some(upperdir), Some(workdir)) = (upperdir, workdir) {
|
if let (Some(upperdir), Some(workdir)) = (upperdir, workdir) {
|
||||||
@@ -121,13 +124,32 @@ pub fn mount_overlayfs(
|
|||||||
dest.as_ref(),
|
dest.as_ref(),
|
||||||
MoveMountFlags::MOVE_MOUNT_F_EMPTY_PATH,
|
MoveMountFlags::MOVE_MOUNT_F_EMPTY_PATH,
|
||||||
)?;
|
)?;
|
||||||
|
} else {
|
||||||
|
let mut data = format!("lowerdir={lowerdir_config}");
|
||||||
|
if let (Some(upperdir), Some(workdir)) = (upperdir, workdir) {
|
||||||
|
if upperdir.exists() && workdir.exists() {
|
||||||
|
data = format!(
|
||||||
|
"{data},upperdir={},workdir={}",
|
||||||
|
upperdir.display(),
|
||||||
|
workdir.display()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mount(
|
||||||
|
KSU_OVERLAY_SOURCE,
|
||||||
|
dest.as_ref(),
|
||||||
|
"overlay",
|
||||||
|
MountFlags::empty(),
|
||||||
|
data,
|
||||||
|
)?;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
pub fn mount_tmpfs(dest: impl AsRef<Path>) -> Result<()> {
|
pub fn mount_tmpfs(dest: impl AsRef<Path>) -> Result<()> {
|
||||||
info!("mount tmpfs on {}", dest.as_ref().display());
|
info!("mount tmpfs on {}", dest.as_ref().display());
|
||||||
let fs = fsopen("tmpfs", FsOpenFlags::FSOPEN_CLOEXEC)?;
|
if let Result::Ok(fs) = fsopen("tmpfs", FsOpenFlags::FSOPEN_CLOEXEC) {
|
||||||
let fs = fs.as_fd();
|
let fs = fs.as_fd();
|
||||||
fsconfig_set_string(fs, "source", KSU_OVERLAY_SOURCE)?;
|
fsconfig_set_string(fs, "source", KSU_OVERLAY_SOURCE)?;
|
||||||
fsconfig_create(fs)?;
|
fsconfig_create(fs)?;
|
||||||
@@ -139,6 +161,15 @@ pub fn mount_tmpfs(dest: impl AsRef<Path>) -> Result<()> {
|
|||||||
dest.as_ref(),
|
dest.as_ref(),
|
||||||
MoveMountFlags::MOVE_MOUNT_F_EMPTY_PATH,
|
MoveMountFlags::MOVE_MOUNT_F_EMPTY_PATH,
|
||||||
)?;
|
)?;
|
||||||
|
} else {
|
||||||
|
mount(
|
||||||
|
KSU_OVERLAY_SOURCE,
|
||||||
|
dest.as_ref(),
|
||||||
|
"tmpfs",
|
||||||
|
MountFlags::empty(),
|
||||||
|
"",
|
||||||
|
)?;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,13 +180,13 @@ fn bind_mount(from: impl AsRef<Path>, to: impl AsRef<Path>) -> Result<()> {
|
|||||||
from.as_ref().display(),
|
from.as_ref().display(),
|
||||||
to.as_ref().display()
|
to.as_ref().display()
|
||||||
);
|
);
|
||||||
let tree = open_tree(
|
if let Result::Ok(tree) = open_tree(
|
||||||
CWD,
|
CWD,
|
||||||
from.as_ref(),
|
from.as_ref(),
|
||||||
OpenTreeFlags::OPEN_TREE_CLOEXEC
|
OpenTreeFlags::OPEN_TREE_CLOEXEC
|
||||||
| OpenTreeFlags::OPEN_TREE_CLONE
|
| OpenTreeFlags::OPEN_TREE_CLONE
|
||||||
| OpenTreeFlags::AT_RECURSIVE,
|
| OpenTreeFlags::AT_RECURSIVE,
|
||||||
)?;
|
) {
|
||||||
move_mount(
|
move_mount(
|
||||||
tree.as_fd(),
|
tree.as_fd(),
|
||||||
"",
|
"",
|
||||||
@@ -163,6 +194,15 @@ fn bind_mount(from: impl AsRef<Path>, to: impl AsRef<Path>) -> Result<()> {
|
|||||||
to.as_ref(),
|
to.as_ref(),
|
||||||
MoveMountFlags::MOVE_MOUNT_F_EMPTY_PATH,
|
MoveMountFlags::MOVE_MOUNT_F_EMPTY_PATH,
|
||||||
)?;
|
)?;
|
||||||
|
} else {
|
||||||
|
mount(
|
||||||
|
from.as_ref(),
|
||||||
|
to.as_ref(),
|
||||||
|
"",
|
||||||
|
MountFlags::BIND | MountFlags::REC,
|
||||||
|
"",
|
||||||
|
)?;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user