Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ksud: fix /debug_ramdisk not mounting #68

Draft
wants to merge 1 commit into
base: next
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions userspace/ksud/src/init_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,36 @@ use crate::module::{handle_updated_modules, prune_modules};
use crate::{assets, defs, ksucalls, restorecon, utils};
use anyhow::{Context, Result};
use log::{info, warn};
use rustix::fs::{mount, MountFlags};
use rustix::{fd::AsFd, fs::CWD, fs::MountFlags, mount::*};
use std::path::Path;

#[cfg(any(target_os = "linux", target_os = "android"))]
fn mount_tmpfs() -> Result<()> {
info!("mount tmpfs on {}", TEMP_DIR);
if let Result::Ok(fs) = fsopen("tmpfs", FsOpenFlags::FSOPEN_CLOEXEC) {
let fs = fs.as_fd();
fsconfig_set_string(fs, "source", KSU_MOUNT_SOURCE)?;
fsconfig_create(fs)?;
let mount = fsmount(fs, FsMountFlags::FSMOUNT_CLOEXEC, MountAttrFlags::empty())?;
move_mount(
mount.as_fd(),
"",
CWD,
TEMP_DIR,
MoveMountFlags::MOVE_MOUNT_F_EMPTY_PATH,
)?;
} else {
mount(
KSU_MOUNT_SOURCE,
TEMP_DIR,
"tmpfs",
MountFlags::empty(),
"",
)?;
}
Ok(())
}

pub fn on_post_data_fs() -> Result<()> {
ksucalls::report_post_fs_data();

Expand Down Expand Up @@ -69,7 +96,7 @@ pub fn on_post_data_fs() -> Result<()> {

// mount temp dir
if !Path::new(NO_TMPFS_PATH).exists() {
if let Err(e) = mount(KSU_MOUNT_SOURCE, TEMP_DIR, "tmpfs", MountFlags::empty(), "") {
if let Err(e) = mount_tmpfs() {
warn!("do temp dir mount failed: {}", e);
}
} else {
Expand Down