Commit fa9107b
fix: drop blocking /proc and root-shell reads from the DNS hot path
Measured on a rooted Android 13 device (SM-N986N) with Root Proxy mode
running, logcat showed findUidFromProcNet being walked end to end per DNS
query — 892, 408 and 168 "Cannot read /proc/net/udp: EACCES" lines in three
consecutive minutes, i.e. ~7 queries/sec sustained, each one:
- parsing /proc/net/udp and /proc/net/udp6 in full, twice, only to fail.
The old comment assumed SELinux merely narrowed these reads to our own
sockets; on this device they are flat EACCES, so the result is a
guaranteed miss.
- then running Shell.cmd("cat /proc/net/udp /proc/net/udp6").exec(), a
blocking libsu call. libsu serialises every command on one shared
shell, so DNS resolution queued behind these — and behind every
iptables call. That is issue #130's failure mode, which the
snapshotter was meant to have fixed. It didn't: a 100ms snapshot
interval cannot catch DNS sockets that live a few milliseconds, so
queries kept falling through to the shell.
On API 29+ the hot path now consults only the background snapshot, which is
what the existing comment already promised ("read this map without
blocking — no inline shell"). API < 29 keeps the direct /proc reads, where
they work without root and without SELinux denial. findUidFromProcNetRoot
is deleted rather than left unreachable.
What this costs is attribution, not filtering: a query whose socket the
snapshot missed is logged without an app name instead of with one. Blocking
decisions never consulted this UID.
Not yet measured after the change — reinstalling stopped the service, so
the post-fix logcat is empty for lack of traffic rather than for lack of
these calls. The pre-fix numbers above are real; the after is pending a
run with protection enabled.
SNAPSHOT_INTERVAL_MS stays at 100ms, so root mode still issues ~10 shell
commands/sec from the snapshotter itself. That is a separate cost, left
deliberately untouched here.
Refs #130, #226
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 6432a4d commit fa9107b
1 file changed
Lines changed: 22 additions & 71 deletions
Lines changed: 22 additions & 71 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | 43 | | |
47 | 44 | | |
48 | 45 | | |
| |||
145 | 142 | | |
146 | 143 | | |
147 | 144 | | |
148 | | - | |
149 | | - | |
| 145 | + | |
| 146 | + | |
150 | 147 | | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
161 | 167 | | |
162 | 168 | | |
163 | | - | |
164 | 169 | | |
165 | 170 | | |
166 | | - | |
167 | | - | |
| 171 | + | |
168 | 172 | | |
169 | 173 | | |
170 | | - | |
171 | | - | |
172 | 174 | | |
173 | 175 | | |
174 | 176 | | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | 177 | | |
183 | 178 | | |
184 | 179 | | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | 180 | | |
195 | 181 | | |
196 | 182 | | |
| |||
222 | 208 | | |
223 | 209 | | |
224 | 210 | | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | 211 | | |
261 | 212 | | |
262 | 213 | | |
| |||
0 commit comments