T09 · Insecure Skill Coding Practices
- Location
scripts/office/soffice.py:53- Finding
Predictable LD_PRELOAD Library Enables Local Code Execution
- Content
View full analysis
dict: env = os.environ.copy() if platform.system() == "Linux": env["SAL_USE_VCLPLUGIN"] = "svp" if _needs_shim(): shim = _ensure_shim() env["LD_PRELOAD"] = str(shim) return env _SHIM_SO = Path(tempfile.gettempdir()) / "lo_socket_shim.so" def _needs_shim() -> bool: # AF_UNIX / LD_PRELOAD shim is Linux-only; skip on Windows and macOS if not hasattr(socket, "AF_UNIX"): return False try: s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) s.close() return False except OSError: return True def _ensure_shim() -> Path: if _SHIM_SO.exists(): return _SHIM_SO src = Path(tempfile.gettempdir()) / "lo_socket_shim.c" src.write_text(_SHIM_SOURCE) subprocess.run( ["gcc", "-shared", "-fPIC", "-o", str(_SHIM_SO), str(src), "-ldl"], check=True, capture_output=True, ) src.unlink() return _SHIM_SO ``` ### Technical Analysis The code stores a native shared library at the fixed, predictable path `/tmp/lo_socket_shim.so`. When that path already exists, `_ensure_shim()` returns it without verifying: - File ownership - File type - Whether it is a symbolic link - File permissions - Integrity or cryptographic hash - Whether it was generated from the embedded source - Whether another process replaced it between validation and use The returned file is subsequently assigned to `LD_PRELOAD` and loaded into the LibreOffice process. Native shared libraries can define constructor functions that execute immediately when the process starts. Therefore, trusting an existing library at a shared temporary path creates a direct arbitrary-code-execution primiti ...[truncated 1812 chars]- Remediation
View remediation
