Synchronise some modifications
Co-authored-by: Ylarod <me@ylarod.cn> Co-authored-by: 5ec1cff <56485584+5ec1cff@users.noreply.github.com> Co-authored-by: backslashxx <118538522+backslashxx@users.noreply.github.com> Co-authored-by: u9521 <63995396+u9521@users.noreply.github.com> Co-authored-by: Wang Han <416810799@qq.com> Co-authored-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com> Co-authored-by: Faris <rissu.ntk@gmail.com>
This commit is contained in:
@@ -421,64 +421,74 @@ static int do_set_feature(void __user *arg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int do_get_wrapper_fd(void __user *arg) {
|
||||
if (!ksu_file_sid) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
struct ksu_get_wrapper_fd_cmd cmd;
|
||||
int ret;
|
||||
|
||||
if (copy_from_user(&cmd, arg, sizeof(cmd))) {
|
||||
pr_err("get_wrapper_fd: copy_from_user failed\n");
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
struct file* f = fget(cmd.fd);
|
||||
if (!f) {
|
||||
return -EBADF;
|
||||
}
|
||||
|
||||
struct ksu_file_wrapper *data = ksu_create_file_wrapper(f);
|
||||
if (data == NULL) {
|
||||
ret = -ENOMEM;
|
||||
goto put_orig_file;
|
||||
}
|
||||
|
||||
// kcompat for older kernel
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 12, 0)
|
||||
#define getfd_secure anon_inode_create_getfd
|
||||
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0)
|
||||
#elif defined(KSU_HAS_GETFD_SECURE)
|
||||
#define getfd_secure anon_inode_getfd_secure
|
||||
#else
|
||||
#define getfd_secure anon_inode_getfd
|
||||
// technically not a secure inode, but, this is the only way so.
|
||||
#define getfd_secure(name, ops, data, flags, __unused) \
|
||||
anon_inode_getfd(name, ops, data, flags)
|
||||
#endif
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0)
|
||||
ret = getfd_secure("[ksu_fdwrapper]", &data->ops, data, f->f_flags, NULL);
|
||||
|
||||
static int do_get_wrapper_fd(void __user *arg)
|
||||
{
|
||||
if (!ksu_file_sid) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
struct ksu_get_wrapper_fd_cmd cmd;
|
||||
int ret;
|
||||
|
||||
if (copy_from_user(&cmd, arg, sizeof(cmd))) {
|
||||
pr_err("get_wrapper_fd: copy_from_user failed\n");
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
struct file *f = fget(cmd.fd);
|
||||
if (!f) {
|
||||
return -EBADF;
|
||||
}
|
||||
|
||||
struct ksu_file_wrapper *data = ksu_create_file_wrapper(f);
|
||||
if (data == NULL) {
|
||||
ret = -ENOMEM;
|
||||
goto put_orig_file;
|
||||
}
|
||||
|
||||
ret = getfd_secure("[ksu_fdwrapper]", &data->ops, data, f->f_flags,
|
||||
NULL);
|
||||
if (ret < 0) {
|
||||
pr_err("ksu_fdwrapper: getfd failed: %d\n", ret);
|
||||
goto put_wrapper_data;
|
||||
}
|
||||
struct file *pf = fget(ret);
|
||||
|
||||
struct inode *wrapper_inode = file_inode(pf);
|
||||
// copy original inode mode
|
||||
wrapper_inode->i_mode = file_inode(f)->i_mode;
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 1, 0) || \
|
||||
defined(KSU_OPTIONAL_SELINUX_INODE)
|
||||
struct inode_security_struct *sec = selinux_inode(wrapper_inode);
|
||||
#else
|
||||
ret = getfd_secure("[ksu_fdwrapper]", &data->ops, data, f->f_flags);
|
||||
struct inode_security_struct *sec =
|
||||
(struct inode_security_struct *)wrapper_inode->i_security;
|
||||
#endif
|
||||
if (ret < 0) {
|
||||
pr_err("ksu_fdwrapper: getfd failed: %d\n", ret);
|
||||
goto put_wrapper_data;
|
||||
}
|
||||
struct file* pf = fget(ret);
|
||||
|
||||
struct inode* wrapper_inode = file_inode(pf);
|
||||
// copy original inode mode
|
||||
wrapper_inode->i_mode = file_inode(f)->i_mode;
|
||||
struct inode_security_struct *sec = selinux_inode(wrapper_inode);
|
||||
if (sec) {
|
||||
sec->sid = ksu_file_sid;
|
||||
}
|
||||
if (sec) {
|
||||
sec->sid = ksu_file_sid;
|
||||
}
|
||||
|
||||
fput(pf);
|
||||
goto put_orig_file;
|
||||
fput(pf);
|
||||
goto put_orig_file;
|
||||
put_wrapper_data:
|
||||
ksu_delete_file_wrapper(data);
|
||||
ksu_delete_file_wrapper(data);
|
||||
put_orig_file:
|
||||
fput(f);
|
||||
fput(f);
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int do_manage_mark(void __user *arg)
|
||||
@@ -950,11 +960,7 @@ static void ksu_install_fd_tw_func(struct callback_head *cb)
|
||||
|
||||
if (copy_to_user(tw->outp, &fd, sizeof(fd))) {
|
||||
pr_err("install ksu fd reply err\n");
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)
|
||||
close_fd(fd);
|
||||
#else
|
||||
__close_fd(current->files, fd);
|
||||
#endif
|
||||
do_close_fd(fd);
|
||||
}
|
||||
|
||||
kfree(tw);
|
||||
|
||||
Reference in New Issue
Block a user