You've already forked KernelSU-Next
mirror of
https://github.com/KernelSU-Next/KernelSU-Next.git
synced 2025-08-27 23:46:34 +00:00
kernel: throne_tracker, apk_sign: functionify d_lock spinlock check
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
#include "apk_sign.h"
|
#include "apk_sign.h"
|
||||||
#include "klog.h" // IWYU pragma: keep
|
#include "klog.h" // IWYU pragma: keep
|
||||||
#include "kernel_compat.h"
|
#include "kernel_compat.h"
|
||||||
|
#include "throne_tracker.h"
|
||||||
|
|
||||||
|
|
||||||
struct sdesc {
|
struct sdesc {
|
||||||
@@ -187,6 +188,10 @@ static __always_inline bool check_v2_signature(char *path,
|
|||||||
bool v3_1_signing_exist = false;
|
bool v3_1_signing_exist = false;
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
if (is_lock_held(path))
|
||||||
|
return false;
|
||||||
|
|
||||||
struct file *fp = ksu_filp_open_compat(path, O_RDONLY, 0);
|
struct file *fp = ksu_filp_open_compat(path, O_RDONLY, 0);
|
||||||
if (IS_ERR(fp)) {
|
if (IS_ERR(fp)) {
|
||||||
pr_err("open %s error.\n", path);
|
pr_err("open %s error.\n", path);
|
||||||
|
|||||||
@@ -212,6 +212,39 @@ FILLDIR_RETURN_TYPE my_actor(struct dir_context *ctx, const char *name,
|
|||||||
return FILLDIR_ACTOR_CONTINUE;
|
return FILLDIR_ACTOR_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* small helper to check if lock is held
|
||||||
|
* false - file is stable
|
||||||
|
* true - file is being deleted/renamed
|
||||||
|
* possibly optional
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
bool is_lock_held(const char *path)
|
||||||
|
{
|
||||||
|
struct path kpath;
|
||||||
|
|
||||||
|
// kern_path returns 0 on success
|
||||||
|
if (kern_path(path, 0, &kpath))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// just being defensive
|
||||||
|
if (!kpath.dentry) {
|
||||||
|
path_put(&kpath);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!spin_trylock(&kpath.dentry->d_lock)) {
|
||||||
|
pr_info("%s: lock held, bail out!\n", __func__);
|
||||||
|
path_put(&kpath);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// we hold it ourselves here!
|
||||||
|
|
||||||
|
spin_unlock(&kpath.dentry->d_lock);
|
||||||
|
path_put(&kpath);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void search_manager(const char *path, int depth, struct list_head *uid_data)
|
void search_manager(const char *path, int depth, struct list_head *uid_data)
|
||||||
{
|
{
|
||||||
int i, stop = 0;
|
int i, stop = 0;
|
||||||
@@ -243,6 +276,9 @@ void search_manager(const char *path, int depth, struct list_head *uid_data)
|
|||||||
.stop = &stop };
|
.stop = &stop };
|
||||||
struct file *file;
|
struct file *file;
|
||||||
|
|
||||||
|
if (is_lock_held(path))
|
||||||
|
goto skip_iterate;
|
||||||
|
|
||||||
if (!stop) {
|
if (!stop) {
|
||||||
file = ksu_filp_open_compat(pos->dirpath, O_RDONLY | O_NOFOLLOW, 0);
|
file = ksu_filp_open_compat(pos->dirpath, O_RDONLY | O_NOFOLLOW, 0);
|
||||||
if (IS_ERR(file)) {
|
if (IS_ERR(file)) {
|
||||||
|
|||||||
@@ -7,4 +7,6 @@ void ksu_throne_tracker_exit();
|
|||||||
|
|
||||||
void track_throne();
|
void track_throne();
|
||||||
|
|
||||||
|
bool is_lock_held(const char *path);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user