C and C++ Binaries


MISC.MEM.PROT : Memory Protection Removal

Summary

A function is passed an input parameter that will result in a permissive memory protection setting.

Properties

Class Name Memory Protection Removal
Significance security
Mnemonic MISC.MEM.PROT
Categories
OWASP-2017 OWASP-2017:A6 Security misconfiguration
OWASP-2021 OWASP-2021:A5 Security misconfiguration
Availability Available for C and C++.
Enabling Checks for this warning class are disabled by default. To enable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += allow class="Memory Protection Removal"

Example

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/mman.h>

int map_memory (int infd, void *mybuf)
{
    char *src, *dst;
    struct stat statbuf;

    if (fstat (infd, &statbuf) < 0) return -1;
    src = mmap (mybuf,  /* Memory Protection Removal warning issued here */
                statbuf.st_size, 
                PROT_READ | PROT_WRITE | PROT_EXEC, 
                MAP_SHARED, 
                infd, 
                0);
    if (src == MAP_FAILED) return -1;
    exit(0);
}

Triggers

CodeSonar ships with library models that allow it to recognize functions such as libc mmap() and Win32 VirtualAlloc() that can set memory permission. If one of these functions is called with a problematic value in the relevant parameter position, a warning will be issued.

If you have created a custom library model for some function f() in terms of one of these existing models, calls to f() will also be capable of triggering Memory Protection Removal warnings.

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.