kernel: expose umount list to ioctl interface (#2950)
This idea is borrowed from simonpunk's susfs4ksu. What we see here is that, yeah well, lets just have userspace send us what it wants unmounted, this is better than hardcoding everything. This also solves that issue where MNT_DETACH fails, as long as we send unmountables in proper order. A small anti-duplicate mechanism is also added. While in-kernel umount is a bit worse than zygisk-provider-based ones, this can still serve as a healthy alternative. --------- - Remove duplicate checks Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com> Co-authored-by: weishu <twsxtd@gmail.com> Co-authored-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com>
This commit is contained in:
@@ -18,6 +18,7 @@ const KSU_IOCTL_SET_FEATURE: u32 = 0x40004b0e; // _IOC(_IOC_WRITE, 'K', 14, 0)
|
||||
const KSU_IOCTL_GET_WRAPPER_FD: u32 = 0x40004b0f; // _IOC(_IOC_WRITE, 'K', 15, 0)
|
||||
const KSU_IOCTL_MANAGE_MARK: u32 = 0xc0004b10; // _IOC(_IOC_READ|_IOC_WRITE, 'K', 16, 0)
|
||||
const KSU_IOCTL_NUKE_EXT4_SYSFS: u32 = 0x40004b11; // _IOC(_IOC_WRITE, 'K', 17, 0)
|
||||
const KSU_IOCTL_ADD_TRY_UMOUNT: u32 = 0x40004b12; // _IOC(_IOC_WRITE, 'K', 18, 0)
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Default)]
|
||||
@@ -80,12 +81,25 @@ pub struct NukeExt4SysfsCmd {
|
||||
pub arg: u64,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Default)]
|
||||
struct AddTryUmountCmd {
|
||||
arg: u64, // char ptr, this is the mountpoint
|
||||
flags: u32, // this is the flag we use for it
|
||||
mode: u8, // denotes what to do with it 0:wipe_list 1:add_to_list 2:delete_entry
|
||||
}
|
||||
|
||||
// Mark operation constants
|
||||
const KSU_MARK_GET: u32 = 1;
|
||||
const KSU_MARK_MARK: u32 = 2;
|
||||
const KSU_MARK_UNMARK: u32 = 3;
|
||||
const KSU_MARK_REFRESH: u32 = 4;
|
||||
|
||||
// Umount operation constants
|
||||
const KSU_UMOUNT_WIPE: u8 = 0;
|
||||
const KSU_UMOUNT_ADD: u8 = 1;
|
||||
const KSU_UMOUNT_DEL: u8 = 2;
|
||||
|
||||
// Global driver fd cache
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
static DRIVER_FD: OnceLock<RawFd> = OnceLock::new();
|
||||
@@ -310,3 +324,38 @@ pub fn nuke_ext4_sysfs(mnt: &str) -> anyhow::Result<()> {
|
||||
ksuctl(KSU_IOCTL_NUKE_EXT4_SYSFS, &mut ioctl_cmd as *mut _)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Wipe all entries from umount list
|
||||
pub fn umount_list_wipe() -> std::io::Result<()> {
|
||||
let mut cmd = AddTryUmountCmd {
|
||||
arg: 0,
|
||||
flags: 0,
|
||||
mode: KSU_UMOUNT_WIPE,
|
||||
};
|
||||
ksuctl(KSU_IOCTL_ADD_TRY_UMOUNT, &mut cmd as *mut _)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Add mount point to umount list
|
||||
pub fn umount_list_add(path: &str, flags: u32) -> anyhow::Result<()> {
|
||||
let c_path = std::ffi::CString::new(path)?;
|
||||
let mut cmd = AddTryUmountCmd {
|
||||
arg: c_path.as_ptr() as u64,
|
||||
flags,
|
||||
mode: KSU_UMOUNT_ADD,
|
||||
};
|
||||
ksuctl(KSU_IOCTL_ADD_TRY_UMOUNT, &mut cmd as *mut _)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Delete mount point from umount list
|
||||
pub fn umount_list_del(path: &str) -> anyhow::Result<()> {
|
||||
let c_path = std::ffi::CString::new(path)?;
|
||||
let mut cmd = AddTryUmountCmd {
|
||||
arg: c_path.as_ptr() as u64,
|
||||
flags: 0,
|
||||
mode: KSU_UMOUNT_DEL,
|
||||
};
|
||||
ksuctl(KSU_IOCTL_ADD_TRY_UMOUNT, &mut cmd as *mut _)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user