website/docs/guide: Enable KernelSU support (CONFIG_KSU) (#1274)

### enable CONFIG_KSU on the website documentation.

Added support for KernelSU by enabling CONFIG_KSU in the kernel
defconfig located at `arch/arm64/configs/vendor/your_defconfig`. Please
ensure to verify the correct location of the file. Note that on some
devices, the defconfig may be located in `arch/arm64/configs`.

---------

Signed-off-by: 明 <akariondev@gmail.com>
Signed-off-by: akari <akariondev@gmail.com>
This commit is contained in:
2024-01-08 03:42:17 -03:00
committed by GitHub
parent e9997a07c1
commit 2bab388bbf
2 changed files with 42 additions and 14 deletions

View File

@@ -34,7 +34,7 @@ Atualmente, apenas `arm64-v8a` e `x86_64` são suportados.
- [Site oficial](https://kernelsu.org/pt_BR/) - [Site oficial](https://kernelsu.org/pt_BR/)
## Tradução ## Tradução
Para contribuir com a tradução do KernelSU ou aprimorar traduções existentes, por favor, utilize o [Weblate](https://hosted.weblate.org/engage/kernelsu/). PR para a tradução do Gerenciador não são mais aceitas, pois podem entrar em conflito com o Weblate. Para contribuir com a tradução do KernelSU ou aprimorar traduções existentes, por favor, utilize o [Weblate](https://hosted.weblate.org/engage/kernelsu/). PR para a tradução do Gerenciador não são mais aceitos, pois podem entrar em conflito com o Weblate.
## Discussão ## Discussão

View File

@@ -62,10 +62,17 @@ curl -LSs "https://raw.githubusercontent.com/tiann/KernelSU/main/kernel/setup.sh
::: :::
Then, add KernelSU calls to the kernel source, here is a patch to refer: Keep in mind that on some devices, your defconfig may be in `arch/arm64/configs` or in other cases `arch/arm64/configs/vendor/your_defconfig`. For example in your defconfig, Enable `CONFIG_KSU` with y to enable, or n to disable. Your path will be something like:
`arch/arm64/configs/...`
```sh
+# KernelSU
+CONFIG_KSU=y
```
::: code-group ::: code-group
Then, add KernelSU calls to the kernel source, here is a patch to refer:
```diff[exec.c] ```diff[exec.c]
diff --git a/fs/exec.c b/fs/exec.c diff --git a/fs/exec.c b/fs/exec.c
index ac59664eaecf..bdd585e1d2cc 100644 index ac59664eaecf..bdd585e1d2cc 100644
@@ -75,20 +82,24 @@ index ac59664eaecf..bdd585e1d2cc 100644
return retval; return retval;
} }
+#ifdef CONFIG_KSU
+extern bool ksu_execveat_hook __read_mostly; +extern bool ksu_execveat_hook __read_mostly;
+extern int ksu_handle_execveat(int *fd, struct filename **filename_ptr, void *argv, +extern int ksu_handle_execveat(int *fd, struct filename **filename_ptr, void *argv,
+ void *envp, int *flags); + void *envp, int *flags);
+extern int ksu_handle_execveat_sucompat(int *fd, struct filename **filename_ptr, +extern int ksu_handle_execveat_sucompat(int *fd, struct filename **filename_ptr,
+ void *argv, void *envp, int *flags); + void *argv, void *envp, int *flags);
+#endif
static int do_execveat_common(int fd, struct filename *filename, static int do_execveat_common(int fd, struct filename *filename,
struct user_arg_ptr argv, struct user_arg_ptr argv,
struct user_arg_ptr envp, struct user_arg_ptr envp,
int flags) int flags)
{ {
+ #ifdef CONFIG_KSU
+ if (unlikely(ksu_execveat_hook)) + if (unlikely(ksu_execveat_hook))
+ ksu_handle_execveat(&fd, &filename, &argv, &envp, &flags); + ksu_handle_execveat(&fd, &filename, &argv, &envp, &flags);
+ else + else
+ ksu_handle_execveat_sucompat(&fd, &filename, &argv, &envp, &flags); + ksu_handle_execveat_sucompat(&fd, &filename, &argv, &envp, &flags);
+ #endif
return __do_execve_file(fd, filename, argv, envp, flags, NULL); return __do_execve_file(fd, filename, argv, envp, flags, NULL);
} }
``` ```
@@ -101,8 +112,10 @@ index 05036d819197..965b84d486b8 100644
return ksys_fallocate(fd, mode, offset, len); return ksys_fallocate(fd, mode, offset, len);
} }
+#ifdef CONFIG_KSU
+extern int ksu_handle_faccessat(int *dfd, const char __user **filename_user, int *mode, +extern int ksu_handle_faccessat(int *dfd, const char __user **filename_user, int *mode,
+ int *flags); + int *flags);
+#endif
/* /*
* access() needs to use the real uid/gid, not the effective uid/gid. * access() needs to use the real uid/gid, not the effective uid/gid.
* We do this by temporarily clearing all FS-related capabilities and * We do this by temporarily clearing all FS-related capabilities and
@@ -117,8 +130,9 @@ index 05036d819197..965b84d486b8 100644
struct vfsmount *mnt; struct vfsmount *mnt;
int res; int res;
unsigned int lookup_flags = LOOKUP_FOLLOW; unsigned int lookup_flags = LOOKUP_FOLLOW;
+ #ifdef CONFIG_KSU
+ ksu_handle_faccessat(&dfd, &filename, &mode, NULL); + ksu_handle_faccessat(&dfd, &filename, &mode, NULL);
+ #endif
if (mode & ~S_IRWXO) /* where's F_OK, X_OK, W_OK, R_OK? */ if (mode & ~S_IRWXO) /* where's F_OK, X_OK, W_OK, R_OK? */
return -EINVAL; return -EINVAL;
@@ -132,15 +146,18 @@ index 650fc7e0f3a6..55be193913b6 100644
} }
EXPORT_SYMBOL(kernel_read); EXPORT_SYMBOL(kernel_read);
+#ifdef CONFIG_KSU
+extern bool ksu_vfs_read_hook __read_mostly; +extern bool ksu_vfs_read_hook __read_mostly;
+extern int ksu_handle_vfs_read(struct file **file_ptr, char __user **buf_ptr, +extern int ksu_handle_vfs_read(struct file **file_ptr, char __user **buf_ptr,
+ size_t *count_ptr, loff_t **pos); + size_t *count_ptr, loff_t **pos);
+#endif
ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos) ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
{ {
ssize_t ret; ssize_t ret;
+ #ifdef CONFIG_KSU
+ if (unlikely(ksu_vfs_read_hook)) + if (unlikely(ksu_vfs_read_hook))
+ ksu_handle_vfs_read(&file, &buf, &count, &pos); + ksu_handle_vfs_read(&file, &buf, &count, &pos);
+ #endif
+ +
if (!(file->f_mode & FMODE_READ)) if (!(file->f_mode & FMODE_READ))
return -EBADF; return -EBADF;
@@ -155,7 +172,9 @@ index 376543199b5a..82adcef03ecc 100644
} }
EXPORT_SYMBOL(vfs_statx_fd); EXPORT_SYMBOL(vfs_statx_fd);
+#ifdef CONFIG_KSU
+extern int ksu_handle_stat(int *dfd, const char __user **filename_user, int *flags); +extern int ksu_handle_stat(int *dfd, const char __user **filename_user, int *flags);
+#endif
+ +
/** /**
* vfs_statx - Get basic and extra attributes by filename * vfs_statx - Get basic and extra attributes by filename
@@ -164,7 +183,9 @@ index 376543199b5a..82adcef03ecc 100644
int error = -EINVAL; int error = -EINVAL;
unsigned int lookup_flags = LOOKUP_FOLLOW | LOOKUP_AUTOMOUNT; unsigned int lookup_flags = LOOKUP_FOLLOW | LOOKUP_AUTOMOUNT;
+ #ifdef CONFIG_KSU
+ ksu_handle_stat(&dfd, &filename, &flags); + ksu_handle_stat(&dfd, &filename, &flags);
+ #endif
if ((flags & ~(AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT | if ((flags & ~(AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT |
AT_EMPTY_PATH | KSTAT_QUERY_FLAGS)) != 0) AT_EMPTY_PATH | KSTAT_QUERY_FLAGS)) != 0)
return -EINVAL; return -EINVAL;
@@ -198,8 +219,9 @@ index 068fdbcc9e26..5348b7bb9db2 100644
@@ -94,6 +96,8 @@ int vfs_fstatat(int dfd, const char __user *filename, struct kstat *stat, @@ -94,6 +96,8 @@ int vfs_fstatat(int dfd, const char __user *filename, struct kstat *stat,
int error = -EINVAL; int error = -EINVAL;
unsigned int lookup_flags = 0; unsigned int lookup_flags = 0;
+ #ifdef CONFIG_KSU
+ ksu_handle_stat(&dfd, &filename, &flag); + ksu_handle_stat(&dfd, &filename, &flag);
+ #endif
+ +
if ((flag & ~(AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT | if ((flag & ~(AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT |
AT_EMPTY_PATH)) != 0) AT_EMPTY_PATH)) != 0)
@@ -217,8 +239,10 @@ index 2ff887661237..e758d7db7663 100644
return error; return error;
} }
+#ifdef CONFIG_KSU
+extern int ksu_handle_faccessat(int *dfd, const char __user **filename_user, int *mode, +extern int ksu_handle_faccessat(int *dfd, const char __user **filename_user, int *mode,
+ int *flags); + int *flags);
+#endif
+ +
/* /*
* access() needs to use the real uid/gid, not the effective uid/gid. * access() needs to use the real uid/gid, not the effective uid/gid.
@@ -226,8 +250,9 @@ index 2ff887661237..e758d7db7663 100644
@@ -370,6 +373,8 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode) @@ -370,6 +373,8 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
int res; int res;
unsigned int lookup_flags = LOOKUP_FOLLOW; unsigned int lookup_flags = LOOKUP_FOLLOW;
+ #ifdef CONFIG_KSU
+ ksu_handle_faccessat(&dfd, &filename, &mode, NULL); + ksu_handle_faccessat(&dfd, &filename, &mode, NULL);
+ #endif
+ +
if (mode & ~S_IRWXO) /* where's F_OK, X_OK, W_OK, R_OK? */ if (mode & ~S_IRWXO) /* where's F_OK, X_OK, W_OK, R_OK? */
return -EINVAL; return -EINVAL;
@@ -248,16 +273,19 @@ index 45306f9ef247..815091ebfca4 100755
return disposition; return disposition;
} }
+#ifdef CONFIG_KSU
+extern bool ksu_input_hook __read_mostly; +extern bool ksu_input_hook __read_mostly;
+extern int ksu_handle_input_handle_event(unsigned int *type, unsigned int *code, int *value); +extern int ksu_handle_input_handle_event(unsigned int *type, unsigned int *code, int *value);
+#endif
+ +
static void input_handle_event(struct input_dev *dev, static void input_handle_event(struct input_dev *dev,
unsigned int type, unsigned int code, int value) unsigned int type, unsigned int code, int value)
{ {
int disposition = input_get_disposition(dev, type, code, &value); int disposition = input_get_disposition(dev, type, code, &value);
+ + #ifdef CONFIG_KSU
+ if (unlikely(ksu_input_hook)) + if (unlikely(ksu_input_hook))
+ ksu_handle_input_handle_event(&type, &code, &value); + ksu_handle_input_handle_event(&type, &code, &value);
+ #endif
if (disposition != INPUT_IGNORE_EVENT && type != EV_SYN) if (disposition != INPUT_IGNORE_EVENT && type != EV_SYN)
add_input_randomness(type, code, value); add_input_randomness(type, code, value);