mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 23:36:04 +00:00
fix(ddsession): keep path and status buffers off the wrapper fast path (#3071)
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>
This commit is contained in:
1 parent
7d942367fd
commit
7630173b24
3 files changed
+74
-19
No files matched your search
@@ -0,0 +1,39 @@
|
||||
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()
|
||||
Reference in new issue
Block a user