Skip to content
This repository was archived by the owner on Feb 12, 2026. It is now read-only.

Add new KernelSU method support#14

Merged
ThePedroo merged 8 commits intoThePedroo:masterfrom
frknkrc44:add_ioctl
Nov 21, 2025
Merged

Add new KernelSU method support#14
ThePedroo merged 8 commits intoThePedroo:masterfrom
frknkrc44:add_ioctl

Conversation

@frknkrc44
Copy link
Collaborator

Note that this PR keeps the old version support while adding the new one.

Copy link
Owner

@ThePedroo ThePedroo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though not critical, ksu_fd will leak here. It is best to close it if it exists, if anything.

Copy link
Owner

@ThePedroo ThePedroo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, some more

};

struct ksu_uid_should_umount_cmd {
__u32 uid; // Input: target UID to check
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use uint32_t instead


return umount;
LOGD("KernelSU fd found, using the new method");
struct ksu_uid_should_umount_cmd cmd = {};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

= {
.uid = app_uid
}:

cmd.uid = app_uid;
syscall(SYS_ioctl, ksu_fd, KSU_IOCTL_UID_SHOULD_UMOUNT, &cmd);
LOGD("KernelSU new method, should umount for %d: %d", app_uid, cmd.should_umount);
return !!cmd.should_umount;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use new lines to separate groups of code, like the log from syscall and return, as it is unrelated

int version = 0;
int reply_ok = 0;

LOGD("KSU existence: try with old method");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto (new line separation)


if (prepare_ksu_fd()) {
LOGD("KSU existence: try with new method");
struct ksu_get_info_cmd g_version {};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto (new line separation). Moreover, no need of the {}

);

LOGD("Prepare KSU fd: KSU fd: %x", ksu_fd);
return ksu_fd >= 0;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto (new line separation)

static int ksu_fd = -1;

static bool prepare_ksu_fd() {
LOGD("Prepare KSU fd: enter");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to move it after the if, no?

Comment on lines +151 to +157
if (!prepare_ksu_fd()) {
LOGD("KernelSU fd not found, falling back to the old method");
bool umount = false;
int reply_ok = 0;
prctl((signed int)KERNEL_SU_OPTION, KERNELSU_CMD_UID_SHOULD_UMOUNT, app_uid, &umount, &reply_ok);
LOGD("KernelSU old method, should umount for %d: %d", app_uid, umount);
return umount;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto (new line separation)

@fatalcoder524
Copy link
Collaborator

It still has debug logs and

#define KERNEL_SU_OPTION (int)0xdeadbeef
#define KERNELSU_CMD_GET_VERSION 2
#define KERNELSU_CMD_UID_SHOULD_UMOUNT 13

Its better we move to ksu.h

@ThePedroo
Copy link
Owner

It still has debug logs and

#define KERNEL_SU_OPTION (int)0xdeadbeef
#define KERNELSU_CMD_GET_VERSION 2
#define KERNELSU_CMD_UID_SHOULD_UMOUNT 13

Its better we move to ksu.h

I don't think so. I originally made this so that is is similar to ReZygisk's code, it is unnecessary to have a new file for such small thing, as we only need 2 CMDs for ioctl and 2 for prctl.

@fatalcoder524 fatalcoder524 marked this pull request as draft November 10, 2025 04:25
@frknkrc44 frknkrc44 marked this pull request as ready for review November 13, 2025 00:58
@ThePedroo ThePedroo merged commit 6646dfc into ThePedroo:master Nov 21, 2025
1 check passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants