Skip to content

Commit c4ab77e

Browse files
committed
fix: memory leak and use-after-free in APatch Zygiskd code
This commit fixes a memory leak and a user-after-free vulnerability in APatch code of Zygiskd.
1 parent 135ebbb commit c4ab77e

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

zygiskd/src/root_impl/apatch.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,18 @@ bool apatch_uid_granted_root(uid_t uid) {
140140
}
141141

142142
for (size_t i = 0; i < config.size; i++) {
143-
if (config.configs[i].uid == uid) {
144-
_apatch_free_package_config(&config);
143+
if (config.configs[i].uid != uid) continue;
145144

146-
return config.configs[i].root_granted;
147-
}
145+
/* INFO: This allow us to copy the information to avoid use-after-free */
146+
bool root_granted = config.configs[i].root_granted;
147+
148+
_apatch_free_package_config(&config);
149+
150+
return root_granted;
148151
}
149152

153+
_apatch_free_package_config(&config);
154+
150155
return false;
151156
}
152157

@@ -159,11 +164,14 @@ bool apatch_uid_should_umount(uid_t uid) {
159164
}
160165

161166
for (size_t i = 0; i < config.size; i++) {
162-
if (config.configs[i].uid == uid) {
163-
_apatch_free_package_config(&config);
167+
if (config.configs[i].uid != uid) continue;
164168

165-
return config.configs[i].umount_needed;
166-
}
169+
/* INFO: This allow us to copy the information to avoid use-after-free */
170+
bool umount_needed = config.configs[i].umount_needed;
171+
172+
_apatch_free_package_config(&config);
173+
174+
return umount_needed;
167175
}
168176

169177
_apatch_free_package_config(&config);

0 commit comments

Comments
 (0)