Skip to content

Commit f0221bc

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 f0221bc

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

kernel/throne_tracker.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ void search_manager(const char *path, int depth, struct list_head *uid_data)
217217
int i, stop = 0;
218218
struct list_head data_path_list;
219219
INIT_LIST_HEAD(&data_path_list);
220-
220+
static unsigned long data_app_magic __read_mostly = 0;
221+
221222
// Initialize APK cache list
222223
struct apk_path_hash *pos, *n;
223224
list_for_each_entry(pos, &apk_path_hash_list, list) {
@@ -248,6 +249,22 @@ void search_manager(const char *path, int depth, struct list_head *uid_data)
248249
pr_err("Failed to open directory: %s, err: %ld\n", pos->dirpath, PTR_ERR(file));
249250
goto skip_iterate;
250251
}
252+
253+
// grab magic on first folder, which is /data/app
254+
if (unlikely(!data_app_magic)) {
255+
if (file->f_inode->i_sb->s_magic) {
256+
data_app_magic = file->f_inode->i_sb->s_magic;
257+
pr_info("%s: dir: %s got magic! 0x%lx\n", __func__, pos->dirpath, data_app_magic);
258+
} else
259+
goto skip_iterate;
260+
}
261+
262+
if (file->f_inode->i_sb->s_magic != data_app_magic) {
263+
pr_info("%s: skip: %s magic: 0x%lx expected: 0x%lx\n", __func__, pos->dirpath,
264+
file->f_inode->i_sb->s_magic, data_app_magic);
265+
filp_close(file, NULL);
266+
goto skip_iterate;
267+
}
251268

252269
iterate_dir(file, &ctx.ctx);
253270
filp_close(file, NULL);

0 commit comments

Comments
 (0)