mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 23:36:04 +00:00
dd_descriptor_unlink, dd_descriptor_rmdir and dd_descriptor_rename put one or two PATH_MAX buffers on their own frame (12 KB, 24 KB), and dd_status_without_tracer put its 16 KB status buffer there, even on the common path that only calls through to libc. Threads with small stacks, such as .NET or Wine threads near their guard page, could overflow in an otherwise plain unlink, rename or open. The wrappers now do only the cheap checks and call the real function; the buffers live in noinline helpers that run only when the descriptor store or the status rewrite is actually needed. A test compiles both sources with -fstack-usage and keeps each wrapper frame under 1 KB. Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com>
40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
|
|
PRELOAD = Path(__file__).resolve().parents[1] / "linuxfs/preload"
|
|
LIMIT = 1024
|
|
WRAPPERS = {
|
|
"descriptor.c": ("dd_descriptor_unlink", "dd_descriptor_rmdir", "dd_descriptor_remove", "dd_descriptor_rename"),
|
|
"tracer.c": ("dd_status_without_tracer",),
|
|
}
|
|
|
|
|
|
def frames(source, build):
|
|
obj = build / (source + ".o")
|
|
subprocess.run(["cc", "-c", "-fPIC", "-O2", "-Wall", "-fstack-usage", "-o", str(obj), str(PRELOAD / source)],
|
|
check=True)
|
|
sizes = {}
|
|
for line in obj.with_suffix(".su").read_text().splitlines():
|
|
place, size, _ = line.split("\t")
|
|
sizes[place.rsplit(":", 1)[-1]] = int(size)
|
|
return sizes
|
|
|
|
|
|
@unittest.skipUnless(shutil.which("cc"), "needs a C compiler")
|
|
class PreloadWrapperStackTest(unittest.TestCase):
|
|
def test_wrappers_keep_path_buffers_off_their_frames(self):
|
|
with tempfile.TemporaryDirectory() as build:
|
|
for source, names in WRAPPERS.items():
|
|
sizes = frames(source, Path(build))
|
|
for name in names:
|
|
with self.subTest(function=name):
|
|
self.assertIn(name, sizes)
|
|
self.assertLess(sizes[name], LIMIT)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|