Skip to content

Commit 1566b8b

Browse files
committed
throne_tracker: avoid cross-fs traversal using s_magic check
Skip directories that does NOT have the same magic as /data/app. This is to avoid scanning incfs and any other stacked filesystems. While this is way dumber, it's way cheaper. no kern_path(), no missable path_put(), no ref handling. This is a workaround for Ultra-Legacy kernels where upstream's method fails. Seems doing 50+ kern_path() calls is a bad meme. Replaces: `throne_tracker: avoid cross fs access` tiann#2626 Signed-off-by: backslashxx <[email protected]>
1 parent b2798b2 commit 1566b8b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

kernel/throne_tracker.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ FILLDIR_RETURN_TYPE my_actor(struct dir_context *ctx, const char *name,
220220
return FILLDIR_ACTOR_CONTINUE;
221221
}
222222

223+
static unsigned long data_app_magic = 0; // its not like /data/app magic changes duh
224+
223225
void search_manager(const char *path, int depth, struct list_head *uid_data)
224226
{
225227
int i, stop = 0;
@@ -271,6 +273,22 @@ void search_manager(const char *path, int depth, struct list_head *uid_data)
271273
pr_err("Failed to open directory: %s, err: %ld\n", pos->dirpath, PTR_ERR(file));
272274
goto skip_iterate;
273275
}
276+
277+
// grab magic on first folder, which is /data/app
278+
if (!data_app_magic) {
279+
if (file->f_inode->i_sb->s_magic) {
280+
data_app_magic = file->f_inode->i_sb->s_magic;
281+
pr_info("%s: dir: %s got magic! 0x%lx\n", __func__, pos->dirpath, data_app_magic);
282+
} else
283+
goto skip_iterate;
284+
}
285+
286+
if (file->f_inode->i_sb->s_magic != data_app_magic) {
287+
pr_info("%s: skip: %s magic: 0x%lx expected: 0x%lx\n", __func__, pos->dirpath,
288+
file->f_inode->i_sb->s_magic, data_app_magic);
289+
filp_close(file, NULL);
290+
goto skip_iterate;
291+
}
274292

275293
iterate_dir(file, &ctx.ctx);
276294
filp_close(file, NULL);

0 commit comments

Comments
 (0)