fix compile on nongki branch (#602)

* fix compile

* revert some edits
This commit is contained in:
F640
2025-11-18 22:07:00 +07:00
committed by GitHub
parent 7782c00275
commit 2aa0034695
5 changed files with 40 additions and 1 deletions

View File

@@ -123,3 +123,27 @@ long ksu_strncpy_from_user_nofault(char *dst, const void __user *unsafe_addr,
return ret; return ret;
} }
#endif #endif
long ksu_copy_from_user_nofault(void *dst, const void __user *src, size_t size)
{
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0)
return copy_from_user_nofault(dst, src, size);
#else
// https://elixir.bootlin.com/linux/v5.8/source/mm/maccess.c#L205
long ret = -EFAULT;
mm_segment_t old_fs = get_fs();
set_fs(USER_DS);
// tweaked to use ksu_access_ok
if (ksu_access_ok(src, size)) {
pagefault_disable();
ret = __copy_from_user_inatomic(dst, src, size);
pagefault_enable();
}
set_fs(old_fs);
if (ret)
return -EFAULT;
return 0;
#endif
}

View File

@@ -5,6 +5,7 @@
#include <linux/err.h> #include <linux/err.h>
#include "klog.h" // IWYU pragma: keep #include "klog.h" // IWYU pragma: keep
#include "ksud.h"
#include "kernel_compat.h" #include "kernel_compat.h"
#include "setuid_hook.h" #include "setuid_hook.h"

View File

@@ -15,6 +15,10 @@
#include <linux/sched.h> #include <linux/sched.h>
#endif #endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 1, 0) && !KSU_OPTIONAL_SELINUX_INODE
#include "objsec.h"
#endif // import inode_security_struct
#include "allowlist.h" #include "allowlist.h"
#include "feature.h" #include "feature.h"
#include "klog.h" // IWYU pragma: keep #include "klog.h" // IWYU pragma: keep

View File

@@ -371,10 +371,15 @@ static int do_get_wrapper_fd(void __user *arg) {
goto put_orig_file; goto put_orig_file;
} }
// kcompat for older kernel
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 12, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 12, 0)
#define getfd_secure anon_inode_create_getfd #define getfd_secure anon_inode_create_getfd
#else #elif defined(KSU_HAS_GETFD_SECURE)
#define getfd_secure anon_inode_getfd_secure #define getfd_secure anon_inode_getfd_secure
#else
// 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 #endif
ret = getfd_secure("[ksu_fdwrapper]", &data->ops, data, f->f_flags, NULL); ret = getfd_secure("[ksu_fdwrapper]", &data->ops, data, f->f_flags, NULL);
if (ret < 0) { if (ret < 0) {
@@ -386,7 +391,11 @@ static int do_get_wrapper_fd(void __user *arg) {
struct inode* wrapper_inode = file_inode(pf); struct inode* wrapper_inode = file_inode(pf);
// copy original inode mode // copy original inode mode
wrapper_inode->i_mode = file_inode(f)->i_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); struct inode_security_struct *sec = selinux_inode(wrapper_inode);
#else
struct inode_security_struct *sec = (struct inode_security_struct *)wrapper_inode->i_security;
#endif
if (sec) { if (sec) {
sec->sid = ksu_file_sid; sec->sid = ksu_file_sid;
} }

View File

@@ -8,6 +8,7 @@
#ifdef CONFIG_KPM #ifdef CONFIG_KPM
#include "kpm/kpm.h" #include "kpm/kpm.h"
#endif #endif
#include "ksu.h"
// Magic numbers for reboot hook to install fd // Magic numbers for reboot hook to install fd
#define KSU_INSTALL_MAGIC1 0xDEADBEEF #define KSU_INSTALL_MAGIC1 0xDEADBEEF