Skip to content

Commit cfda678

Browse files
committed
process tagging bullshit
for: tiann#3378 ref: https://elixir.bootlin.com/linux/v4.14.1/source/kernel/signal.c#L1974 https://elixir.bootlin.com/linux/v4.14.1/source/include/linux/sched/signal.h#L231 [ 38.584868] KernelSU: sys_execve su->ksud! [ 38.591293] KernelSU: ksu_bprm_check: ksu managed task found with pid: 4681 comm: ksud [ 38.811241] KernelSU: sys_execve su->ksud! [ 38.816113] KernelSU: ksu_bprm_check: ksu managed task found with pid: 4707 comm: ksud [ 38.972612] KernelSU: sys_execve su->ksud! [ 38.998849] KernelSU: ksu_bprm_check: ksu managed task found with pid: 4724 comm: ksud [ 39.513940] KernelSU: sys_execve su->ksud! [ 39.530293] KernelSU: ksu_bprm_check: ksu managed task found with pid: 4774 comm: ksud [ 39.534300] KernelSU: sys_execve su->ksud! [ 39.539604] KernelSU: ksu_bprm_check: ksu managed task found with pid: 4779 comm: ksud [ 51.405629] KernelSU: newfstatat su->sh!
1 parent 4a0f5c1 commit cfda678

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

kernel/hook/core_hook.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,21 @@ LSM_HANDLER_TYPE ksu_handle_rename(struct dentry *old_dentry, struct dentry *new
4444
return 0;
4545
}
4646

47+
// https://elixir.bootlin.com/linux/v7.0-rc6/source/include/linux/sched/signal.h#L94
48+
// its free real estate
49+
#define SIGNAL_KSU_MANAGED 0x01000000
50+
#define SIGNAL_KSU_BIT25 0x02000000
51+
#define SIGNAL_KSU_BIT26 0x04000000
52+
#define SIGNAL_KSU_BIT27 0x08000000
53+
#define SIGNAL_KSU_BIT28 0x10000000
54+
#define SIGNAL_KSU_BIT29 0x20000000
55+
#define SIGNAL_KSU_BIT30 0x40000000
56+
#define SIGNAL_KSU_BIT31 0x80000000
57+
58+
// so we can clear everything all at once
59+
// FF XX XX XX
60+
#define SIGNAL_KSU_MASK (0xFF000000)
61+
4762
LSM_HANDLER_TYPE ksu_handle_setuid(struct cred *new, const struct cred *old)
4863
{
4964
if (!new || !old) {
@@ -63,10 +78,20 @@ LSM_HANDLER_TYPE ksu_handle_setuid(struct cred *new, const struct cred *old)
6378
disable_seccomp();
6479
pr_info("install fd for: %d\n", new_uid);
6580
ksu_install_fd(); // install fd for ksu manager
81+
82+
spin_lock_irq(&current->sighand->siglock);
83+
current->signal->flags |= SIGNAL_KSU_MANAGED;
84+
spin_unlock_irq(&current->sighand->siglock);
85+
6686
}
6787

6888
if (unlikely(ksu_is_allow_uid_for_current(new_uid))) {
6989
disable_seccomp();
90+
91+
spin_lock_irq(&current->sighand->siglock);
92+
current->signal->flags |= SIGNAL_KSU_MANAGED;
93+
spin_unlock_irq(&current->sighand->siglock);
94+
7095
return 0;
7196
}
7297

@@ -80,6 +105,21 @@ LSM_HANDLER_TYPE ksu_bprm_check(struct linux_binprm *bprm)
80105
ksu_sulog_emit_bprm((const char *)bprm->filename);
81106
#endif
82107

108+
if (unlikely(current->signal->flags & SIGNAL_KSU_MANAGED)) {
109+
pr_info("%s: ksu managed task found with pid: %d comm: %s \n", __func__, current->pid, current->comm);
110+
111+
// untag if needed
112+
// actually not needed, when process dies, this shit is freed anyway
113+
// atleast if we need to wipe shit we can do this
114+
// TODO: might actually be better to use this check in sucompat's gate?
115+
// depending on what upstream does
116+
spin_lock_irq(&current->sighand->siglock);
117+
current->signal->flags &= ~SIGNAL_KSU_MASK;
118+
spin_unlock_irq(&current->sighand->siglock);
119+
120+
return 0;
121+
}
122+
83123
if (likely(!ksu_execveat_hook))
84124
return 0;
85125

0 commit comments

Comments
 (0)