Don t Create SharedWritable Segments

Don't Create Shared/Writable Segments

The damage potential is high if your application supports shared and writable data segments, but this is not a common problem. Although these segments are supported in Microsoft Windows as a 16-bit application legacy, their use is highly discouraged. A shared/writable memory block is declared in a DLL and is shared among all applications that load the DLL. The problem is that the memory block is unprotected, and any rogue application can load the DLL and write data to the memory segment.

You can produce binaries that support these memory sections. In the examples below, .dangersec is the name of the shared memory section. Your code is insecure if you have any declarations like the following.

In a .def File

SECTIONS .dangersec READ WRITE SHARED

In a .h* or .c* File

#pragma comment(linker, "/section:.dangersec, rws")

On the Linker Command Line

-SECTION:.dangersec, rws

Unfortunately, a Knowledge Base article outlines how to create such insecure memory sections: Q125677, HOWTO: Share Data Between Different Mappings of a DLL.

You can create a more secure alternative, file mappings, by using the CreateFileMapping function and applying a reasonable access control list (ACL) to the object.



Writing Secure Code
Writing Secure Code, Second Edition
ISBN: 0735617228
EAN: 2147483647
Year: 2001
Pages: 286

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net