I'm working on below process control issue reported by fortify which is described here.
The function load() in filename.c calls dlopen() on line 3. The call loads a library without specifying an absolute path. It could result in the program using a malicious library supplied by an attacker.
I have below function which is getting invoked in different places of code.
void* load(char* name)
{
void* handle;
handle = dlopen(name, RTLD_LAZY | RTLD_GLOBAL);
return(handle);
}
void somefunc()
{
void *login_module_handle = load("/home/myuser/load_this_shared_lib.so");
}
Here I'm already using absolute path, but don't understand why Fortify still reports the error.
The possible recommendation from Fortify is as shown below.
- Whenever possible, libraries should be controlled by the application and executed using an absolute path.
- In cases where the path is not known at compile time, such as for cross-platform applications, an absolute path should be constructed from known values during execution.
Any suggestion would be helpful.
The
loadfunction could in theory be called someplace else that doesn't pass a full path or, even worse, a variable populated by the user that isn't properly checked.loadmight better be implemented as a macro in this case:Then when the substitution happens,
dlopenis actually given a string constant specifying an absolute path that Fortify should be able to see.