Skip to content

Commit 0b6998b

Browse files
authored
throne_tracker: avoid cross fs access (#2626)
Files in /data/app may be stacked on incremental fs, if user installs big apps from play store or adb shell. Performing I/O operation on it may results in long-time blocking. As KSU won't get installed in those ways, just avoid cross fs access. Authored-by: 5ec1cff <ewtqyqyewtqyqy@gmail.com> Signed-off-by: Wang Han <416810799@qq.com>
1 parent a278786 commit 0b6998b

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

kernel/throne_tracker.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <linux/string.h>
66
#include <linux/types.h>
77
#include <linux/version.h>
8+
#include <linux/namei.h>
89

910
#include "allowlist.h"
1011
#include "klog.h" // IWYU pragma: keep
@@ -115,6 +116,7 @@ struct my_dir_context {
115116
void *private_data;
116117
int depth;
117118
int *stop;
119+
struct super_block* root_sb;
118120
};
119121
// https://docs.kernel.org/filesystems/porting.html
120122
// filldir_t (readdir callbacks) calling conventions have changed. Instead of returning 0 or -E... it returns bool now. false means "no more" (as -E... used to) and true - "keep going" (as 0 in old calling conventions). Rationale: callers never looked at specific -E... values anyway. -> iterate_shared() instances require no changes at all, all filldir_t ones in the tree converted.
@@ -135,6 +137,8 @@ FILLDIR_RETURN_TYPE my_actor(struct dir_context *ctx, const char *name,
135137
struct my_dir_context *my_ctx =
136138
container_of(ctx, struct my_dir_context, ctx);
137139
char dirpath[DATA_PATH_LEN];
140+
int err;
141+
struct path path;
138142

139143
if (!my_ctx) {
140144
pr_err("Invalid context\n");
@@ -161,6 +165,18 @@ FILLDIR_RETURN_TYPE my_actor(struct dir_context *ctx, const char *name,
161165
return FILLDIR_ACTOR_CONTINUE;
162166
}
163167

168+
err = kern_path(dirpath, 0, &path);
169+
170+
if (err) {
171+
pr_err("get dirpath %s err: %d\n", dirpath, err);
172+
return FILLDIR_ACTOR_CONTINUE;
173+
}
174+
175+
if (my_ctx->root_sb != path.dentry->d_inode->i_sb) {
176+
pr_info("skip cross fs: %s", dirpath);
177+
return FILLDIR_ACTOR_CONTINUE;
178+
}
179+
164180
if (d_type == DT_DIR && my_ctx->depth > 0 &&
165181
(my_ctx->stop && !*my_ctx->stop)) {
166182
struct data_path *data = kmalloc(sizeof(struct data_path), GFP_ATOMIC);
@@ -210,10 +226,19 @@ FILLDIR_RETURN_TYPE my_actor(struct dir_context *ctx, const char *name,
210226

211227
void search_manager(const char *path, int depth, struct list_head *uid_data)
212228
{
213-
int i, stop = 0;
229+
int i, stop = 0, err;
214230
struct list_head data_path_list;
231+
struct path kpath;
232+
struct super_block* root_sb;
215233
INIT_LIST_HEAD(&data_path_list);
216234

235+
err = kern_path(path, 0, &kpath);
236+
237+
if (err) {
238+
pr_err("get search root %s err: %d\n", path, err);
239+
return;
240+
}
241+
217242
// Initialize APK cache list
218243
struct apk_path_hash *pos, *n;
219244
list_for_each_entry(pos, &apk_path_hash_list, list) {
@@ -226,6 +251,8 @@ void search_manager(const char *path, int depth, struct list_head *uid_data)
226251
data.depth = depth;
227252
list_add_tail(&data.list, &data_path_list);
228253

254+
root_sb = kpath.dentry->d_inode->i_sb;
255+
229256
for (i = depth; i >= 0; i--) {
230257
struct data_path *pos, *n;
231258

@@ -235,7 +262,8 @@ void search_manager(const char *path, int depth, struct list_head *uid_data)
235262
.parent_dir = pos->dirpath,
236263
.private_data = uid_data,
237264
.depth = pos->depth,
238-
.stop = &stop };
265+
.stop = &stop,
266+
.root_sb = root_sb };
239267
struct file *file;
240268

241269
if (!stop) {

0 commit comments

Comments
 (0)