Skip to content

Commit 7b47f32

Browse files
committed
kernel: 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. This supercedes `throne_tracker: avoid cross fs access (tiann#2626)` - upstream tiann@0b6998b Signed-off-by: backslashxx <[email protected]>
1 parent 28ca0c8 commit 7b47f32

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
@@ -212,6 +212,8 @@ FILLDIR_RETURN_TYPE my_actor(struct dir_context *ctx, const char *name,
212212
return FILLDIR_ACTOR_CONTINUE;
213213
}
214214

215+
static unsigned long data_app_magic = 0; // its not like /data/app magic changes duh
216+
215217
void search_manager(const char *path, int depth, struct list_head *uid_data)
216218
{
217219
int i, stop = 0;
@@ -248,6 +250,22 @@ void search_manager(const char *path, int depth, struct list_head *uid_data)
248250
pr_err("Failed to open directory: %s, err: %ld\n", pos->dirpath, PTR_ERR(file));
249251
goto skip_iterate;
250252
}
253+
254+
// grab magic on first folder, which is /data/app
255+
if (!data_app_magic) {
256+
if (file->f_inode->i_sb->s_magic) {
257+
data_app_magic = file->f_inode->i_sb->s_magic;
258+
pr_info("%s: dir: %s got magic! 0x%lx\n", __func__, pos->dirpath, data_app_magic);
259+
} else
260+
goto skip_iterate;
261+
}
262+
263+
if (file->f_inode->i_sb->s_magic != data_app_magic) {
264+
pr_info("%s: skip: %s magic: 0x%lx expected: 0x%lx\n", __func__, pos->dirpath,
265+
file->f_inode->i_sb->s_magic, data_app_magic);
266+
filp_close(file, NULL);
267+
goto skip_iterate;
268+
}
251269

252270
iterate_dir(file, &ctx.ctx);
253271
filp_close(file, NULL);

0 commit comments

Comments
 (0)