Bug 13334 – [infoleak] DMD always places module paths in data segment
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-08-19T16:12:38Z
Last change time
2018-02-16T06:41:47Z
Keywords
betterC, performance
Assigned to
No Owner
Creator
Vladimir Panteleev
Comments
Comment #0 by dlang-bugzilla — 2014-08-19T16:12:38Z
Consider the following minimalistic Win32 executable program:
/////////////// winmain.d //////////////
import win32.windows;
extern(Windows) void ExitProcess(DWORD);
void start() { ExitProcess(0); }
pragma(startaddress, start);
pragma(lib, "kernel32");
////////////////////////////////////////
If the program is compiled, then the EXE passed through the standard `strings` utility, the output is as follows:
ExitProcess
KERNEL32.dll
C:\Soft\dmd2d\windows\bin\..\..\import\druntime\object.di
C:\Soft\dmd2d\windows\bin\..\..\import\win32\w32api.d
C:\Soft\dmd2d\windows\bin\..\..\import\win32\windef.d
C:\Soft\dmd2d\windows\bin\..\..\import\win32\basetsd.d
C:\Soft\dmd2d\windows\bin\..\..\import\win32\winbase.d
C:\Soft\dmd2d\windows\bin\..\..\import\win32\winuser.d
C:\Soft\dmd2d\windows\bin\..\..\import\win32\mmsystem.d
C:\Soft\dmd2d\windows\bin\..\..\import\win32\winsock2.d
C:\Soft\dmd2d\windows\bin\..\..\import\win32\ws2tcpip.d
The executable contains an unused (unreferenced) string containing the path of each module of the program.
These strings are present even if the program is compiled with -release -betterC!
These strings seem to be generated by the Module::genhelpers function in mars.c. This function generates functions to handle range check errors, assertion failures, and unittest failures. Now, the functions themselves are generated each in a separate section, and as they are not used by the program, they are ultimately stripped by the linker. However, the strings are not stripped, because they are emitted directly to the object file's data segment.
I can see two solutions:
1) Do not generate these helper functions or strings when -betterC is specified.
2) Emit the strings to a separate segment, so that they can be stripped away by the linker as well.
Comment #1 by dlang-bugzilla — 2014-08-20T01:24:00Z
Correction. There are two separate issues here:
1. DMD leaks information about the source code in a way that can't be turned off with compiler switches.
2. DMD emits information that is useless to certain programs.
The first solution above only applies to the second problem. The first problem touches a much bigger subject with several approaches, e.g. a set of compiler switches to strip or obfuscate file names, class names, __FILE__/__LINE__ expansions throughout Phobos, etc.
Comment #2 by dlang-bugzilla — 2014-08-24T16:44:31Z