[LLVMdev] Handling of unsafe functions

Martinez, Javier E javier.e.martinez at intel.com
Tue Sep 18 17:00:50 PDT 2012


We have identified functions in LLVM sources using a static code analyzer which are marked as a "security vulnerability"[1][2]. There has been work already done to address some of them for Linux (e.g. snprintf). We are attempting to solve this issue in a comprehensive fashion across all platforms. Most of the functions identified are for manipulating strings. Memcpy is the most commonly used of all these unsecure methods. The following table lists all these functions are their recommended secure alternatives.

Recommended alternatives:

Functions    Windows        Unix/Mac OS

Memcpy     memcpy_s      -

Sprint          sprintf_s         snprintf

Sscanf         scanf_s            -

_alloca        _malloca         -

Strcat          strcat_s          strlcat

Strcpy         strcpy_s          strlcpy

Strtok         strtok_s           -

The proposal is to add secure versions of these functions. These functions will be implemented in LLVM Support module and be used by all other LLVM modules. The interface of these methods will be platform independent while their implementation will be platform specific (like the Mutex class in Support module). In cases where the platform does not support the functionality natively, we are writing an implementation of these functions. For example, in the case of memcpy the secure function will look like llvm::memcpy_secure.

Some secure functions require additional data that needs to be passed (like buffer sizes). That information has to be added in all places of invocation. In some cases, this requires an extra size_t argument to be passed through. Hence, this change would not just be a one to one function refactoring. The attached patch helps illustrate how an instance of memcpy would be modified.

Is this proposal of interest to the LLVM community? Can you also comment if the approach specified is good to address this issue?


[1] http://msdn.microsoft.com/en-us/library/ms235384(v=vs.80).aspx

[2] https://developer.apple.com/library/mac/#documentation/Security/Conceptual/SecureCodingGuide/Articles/BufferOverflows.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120919/7de4688a/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: llvm_secure_function.patch
Type: application/octet-stream
Size: 6350 bytes
Desc: llvm_secure_function.patch
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120919/7de4688a/attachment.obj>

More information about the llvm-dev mailing list