kernel & KernelSU: Refactor show enabled_features

- This simplies the logic in ksu_susfs tool, and it should be more convenient for some ksu manager variants that integrate susfs since they can just pass the char buffer and its size to get the result now, which means they no longer need to update the bit value each time a new susfs features deprecated or added.

Co-authored-by: simonpunk <simonpunk2016@gmail.com>
This commit is contained in:
ShirkNeko
2025-07-03 17:58:38 +08:00
parent cc2f28f1c1
commit e5f58caf11

View File

@@ -867,8 +867,11 @@ int ksu_handle_prctl(int option, unsigned long arg2, unsigned long arg3,
} }
if (arg2 == CMD_SUSFS_SHOW_ENABLED_FEATURES) { if (arg2 == CMD_SUSFS_SHOW_ENABLED_FEATURES) {
int error = 0; int error = 0;
u64 enabled_features = 0; if (arg4 <= 0) {
if (!ksu_access_ok((void __user*)arg3, sizeof(u64))) { pr_err("susfs: CMD_SUSFS_SHOW_ENABLED_FEATURES -> arg4 cannot be <= 0\n");
return 0;
}
if (!ksu_access_ok((void __user*)arg3, arg4)) {
pr_err("susfs: CMD_SUSFS_SHOW_ENABLED_FEATURES -> arg3 is not accessible\n"); pr_err("susfs: CMD_SUSFS_SHOW_ENABLED_FEATURES -> arg3 is not accessible\n");
return 0; return 0;
} }
@@ -876,49 +879,7 @@ int ksu_handle_prctl(int option, unsigned long arg2, unsigned long arg3,
pr_err("susfs: CMD_SUSFS_SHOW_ENABLED_FEATURES -> arg5 is not accessible\n"); pr_err("susfs: CMD_SUSFS_SHOW_ENABLED_FEATURES -> arg5 is not accessible\n");
return 0; return 0;
} }
#ifdef CONFIG_KSU_SUSFS_SUS_PATH error = susfs_get_enabled_features((char __user*)arg3, arg4);
enabled_features |= (1 << 0);
#endif
#ifdef CONFIG_KSU_SUSFS_SUS_MOUNT
enabled_features |= (1 << 1);
#endif
#ifdef CONFIG_KSU_SUSFS_AUTO_ADD_SUS_KSU_DEFAULT_MOUNT
enabled_features |= (1 << 2);
#endif
#ifdef CONFIG_KSU_SUSFS_AUTO_ADD_SUS_BIND_MOUNT
enabled_features |= (1 << 3);
#endif
#ifdef CONFIG_KSU_SUSFS_SUS_KSTAT
enabled_features |= (1 << 4);
#endif
#ifdef CONFIG_KSU_SUSFS_TRY_UMOUNT
enabled_features |= (1 << 5);
#endif
#ifdef CONFIG_KSU_SUSFS_AUTO_ADD_TRY_UMOUNT_FOR_BIND_MOUNT
enabled_features |= (1 << 6);
#endif
#ifdef CONFIG_KSU_SUSFS_SPOOF_UNAME
enabled_features |= (1 << 7);
#endif
#ifdef CONFIG_KSU_SUSFS_ENABLE_LOG
enabled_features |= (1 << 8);
#endif
#ifdef CONFIG_KSU_SUSFS_HIDE_KSU_SUSFS_SYMBOLS
enabled_features |= (1 << 9);
#endif
#ifdef CONFIG_KSU_SUSFS_SPOOF_CMDLINE_OR_BOOTCONFIG
enabled_features |= (1 << 10);
#endif
#ifdef CONFIG_KSU_SUSFS_OPEN_REDIRECT
enabled_features |= (1 << 11);
#endif
#ifdef CONFIG_KSU_SUSFS_HAS_MAGIC_MOUNT
enabled_features |= (1 << 12);
#endif
#ifdef CONFIG_KSU_SUSFS_SUS_SU
enabled_features |= (1 << 13);
#endif
error = copy_to_user((void __user*)arg3, (void*)&enabled_features, sizeof(enabled_features));
pr_info("susfs: CMD_SUSFS_SHOW_ENABLED_FEATURES -> ret: %d\n", error); pr_info("susfs: CMD_SUSFS_SHOW_ENABLED_FEATURES -> ret: %d\n", error);
if (copy_to_user((void __user*)arg5, &error, sizeof(error))) if (copy_to_user((void __user*)arg5, &error, sizeof(error)))
pr_info("susfs: copy_to_user() failed\n"); pr_info("susfs: copy_to_user() failed\n");