Skip to content

Commit

Permalink
kernel: replace devpts kprobe
Browse files Browse the repository at this point in the history
  • Loading branch information
tiann committed May 16, 2024
1 parent d36e365 commit 31653b1
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions kernel/sucompat.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ int ksu_handle_devpts(struct inode *inode)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 1, 0)
struct inode_security_struct *sec = selinux_inode(inode);
#else
struct inode_security_struct *sec = (struct inode_security_struct *) inode->i_security;
struct inode_security_struct *sec =
(struct inode_security_struct *)inode->i_security;
#endif
if (sec) {
sec->sid = ksu_devpts_sid;
Expand Down Expand Up @@ -319,22 +320,23 @@ static struct kprobe execve_kp = {
};
#endif

static int devpts_get_priv_pre(struct kprobe *p, struct pt_regs *regs)
static int pts_unix98_lookup_pre(struct kprobe *p, struct pt_regs *regs)
{
struct inode *inode;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0)
struct dentry *dentry = (struct dentry *)PT_REGS_PARM1(regs);
inode = dentry->d_inode;
struct file *file = (struct file *)PT_REGS_PARM2(regs);
inode = file->f_path.dentry->d_inode;
#else
inode = (struct inode *)PT_REGS_PARM1(regs);
inode = (struct inode *)PT_REGS_PARM2(regs);
#endif

return ksu_handle_devpts(inode);
}

static struct kprobe devpts_get_priv_kp = { .symbol_name = "devpts_get_priv",
.pre_handler =
devpts_get_priv_pre };
static struct kprobe pts_unix98_lookup_kp = { .symbol_name =
"pts_unix98_lookup",
.pre_handler =
pts_unix98_lookup_pre };

#endif

Expand All @@ -349,7 +351,7 @@ void ksu_sucompat_init()
pr_info("sucompat: newfstatat_kp: %d\n", ret);
ret = register_kprobe(&faccessat_kp);
pr_info("sucompat: faccessat_kp: %d\n", ret);
ret = register_kprobe(&devpts_get_priv_kp);
ret = register_kprobe(&pts_unix98_lookup_kp);
pr_info("sucompat: devpts_kp: %d\n", ret);
#endif
}
Expand All @@ -360,6 +362,6 @@ void ksu_sucompat_exit()
unregister_kprobe(&execve_kp);
unregister_kprobe(&newfstatat_kp);
unregister_kprobe(&faccessat_kp);
unregister_kprobe(&devpts_get_priv_kp);
unregister_kprobe(&pts_unix98_lookup_kp);
#endif
}

0 comments on commit 31653b1

Please sign in to comment.