kernel: add close_fd helper, debloat dmesg log
Signed-off-by: fc5b87cf <rissu.ntk@gmail.com>
This commit is contained in:
@@ -436,7 +436,7 @@ void persistent_allow_list(void)
|
||||
goto put_task;
|
||||
}
|
||||
cb->func = do_persistent_allow_list;
|
||||
ksu_task_work_add(tsk, cb, TWA_RESUME);
|
||||
task_work_add(tsk, cb, TWA_RESUME);
|
||||
|
||||
put_task:
|
||||
put_task_struct(tsk);
|
||||
|
||||
@@ -81,6 +81,7 @@ static long ksu_sys_setns(int fd, int flags)
|
||||
PT_REGS_PARM1(®s) = fd;
|
||||
PT_REGS_PARM2(®s) = flags;
|
||||
|
||||
// TODO: arm support
|
||||
#if (defined(__aarch64__) || defined(__x86_64__))
|
||||
return SYS_SETNS_SYMBOL(®s);
|
||||
#else
|
||||
@@ -180,13 +181,7 @@ static void setup_mount_namespace(int32_t ns_mode)
|
||||
if (ret) {
|
||||
pr_warn("sys_setns failed: %ld\n", ret);
|
||||
}
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 11, 0)
|
||||
close_fd(fd);
|
||||
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 17, 0)
|
||||
ksys_close(fd);
|
||||
#else
|
||||
sys_close(fd);
|
||||
#endif
|
||||
do_close_fd(fd);
|
||||
}
|
||||
|
||||
if (ns_mode == 2) {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <linux/fs.h>
|
||||
#include <linux/version.h>
|
||||
#include <linux/task_work.h>
|
||||
#include <linux/fdtable.h>
|
||||
#include "ss/policydb.h"
|
||||
#include "linux/key.h"
|
||||
|
||||
@@ -69,16 +70,21 @@ extern struct key *init_session_keyring;
|
||||
|
||||
// Linux >= 5.7
|
||||
// task_work_add (struct, struct, enum)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 7, 0)
|
||||
#define ksu_task_work_add(tsk, cb, notify) task_work_add(tsk, cb, notify)
|
||||
#else
|
||||
// Linux pre-5.7
|
||||
// task_work_add (struct, struct, bool)
|
||||
#define ksu_task_work_add(tsk, cb, notify) task_work_add(tsk, cb, notify)
|
||||
// Decoy, so it wouldn't complain.
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 7, 0)
|
||||
#ifndef TWA_RESUME
|
||||
#define TWA_RESUME true
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static inline int do_close_fd(unsigned int fd)
|
||||
{
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)
|
||||
return close_fd(fd);
|
||||
#else
|
||||
return __close_fd(current->files, fd);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -198,7 +198,7 @@ int ksu_handle_umount(uid_t old_uid, uid_t new_uid)
|
||||
tw->old_cred = get_current_cred();
|
||||
tw->cb.func = umount_tw_func;
|
||||
|
||||
int err = ksu_task_work_add(current, &tw->cb, TWA_RESUME);
|
||||
int err = task_work_add(current, &tw->cb, TWA_RESUME);
|
||||
if (err) {
|
||||
if (tw->old_cred) {
|
||||
put_cred(tw->old_cred);
|
||||
|
||||
@@ -254,7 +254,7 @@ first_app_process:
|
||||
rcu_read_lock();
|
||||
init_task = rcu_dereference(current->real_parent);
|
||||
if (init_task) {
|
||||
ksu_task_work_add(init_task, &on_post_fs_data_cb,
|
||||
task_work_add(init_task, &on_post_fs_data_cb,
|
||||
TWA_RESUME);
|
||||
}
|
||||
rcu_read_unlock();
|
||||
|
||||
@@ -669,11 +669,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, 11, 0)
|
||||
close_fd(fd);
|
||||
#else
|
||||
ksys_close(fd);
|
||||
#endif
|
||||
do_close_fd(fd);
|
||||
}
|
||||
|
||||
kfree(tw);
|
||||
@@ -699,7 +695,7 @@ static int reboot_handler_pre(struct kprobe *p, struct pt_regs *regs)
|
||||
tw->outp = (int __user *)arg4;
|
||||
tw->cb.func = ksu_install_fd_tw_func;
|
||||
|
||||
if (ksu_task_work_add(current, &tw->cb, TWA_RESUME)) {
|
||||
if (task_work_add(current, &tw->cb, TWA_RESUME)) {
|
||||
kfree(tw);
|
||||
pr_warn("install fd add task_work failed\n");
|
||||
}
|
||||
@@ -730,13 +726,7 @@ int ksu_handle_sys_reboot(int magic1, int magic2, unsigned int cmd,
|
||||
// downstream: dereference all arg usage!
|
||||
if (copy_to_user((void __user *)*arg, &fd, sizeof(fd))) {
|
||||
pr_err("install ksu fd reply err\n");
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 11, 0)
|
||||
close_fd(fd);
|
||||
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 17, 0)
|
||||
ksys_close(fd);
|
||||
#else
|
||||
sys_close(fd);
|
||||
#endif
|
||||
do_close_fd(fd);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -842,8 +832,10 @@ int ksu_install_fd(void)
|
||||
// Install fd
|
||||
fd_install(fd, filp);
|
||||
|
||||
#ifdef CONFIG_KSU_DEBUG
|
||||
pr_info("ksu fd[%d] installed for %s/%d\n", fd, current->comm,
|
||||
current->pid);
|
||||
#endif
|
||||
|
||||
return fd;
|
||||
}
|
||||
Reference in New Issue
Block a user