You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As I already asked, I want to understand, how can I track alias to detect use after free vulnerability? Are there any libraries, which can help track such CWEs? Here some examples:
#include<stdlib.h>
#include<time.h>intmain() {
char *a = (char *)malloc(sizeof(char)); // Memory allocationchar *b = a;
if (a != NULL) {
free(a); // Free allocated memory
}
*b = 'b'; // Use after freereturn0;
}
I want to track malloc function and then find all alias (start tracking them). After that I want to make all arguments of free become sources and make them about alias. How is it can be shown?
For now I have code, that find only CWEs that are related only to the function argument:
/** * @name Use after free * @kind path-problem * @id cpp/use-after-free */import cpp
import semmle.code.cpp.dataflow.DataFlow
import semmle.code.cpp.dataflow.TaintTracking
import Configs::PathGraph
module Config implements DataFlow::ConfigSig{predicateisSource(DataFlow::Nodearg){exists(FunctionCallcall|arg.asDefiningArgument()=call.getArgument(0)andcall.getTarget().hasGlobalOrStdName("free"))}predicateisSink(DataFlow::Nodesink){exists(PointerDereferenceExprstar|star.getOperand()=sink.asExpr())orexists(FormattingFunctionCallcall|call.getArgument(0)=sink.asExpr())}}module Configs = TaintTracking::Global<Config>;
from Configs::PathNodesource, Configs::PathNodesinkwhere Configs::hasFlowPath(source,sink)selectsink,source,sink,"Memory is freed here and used here, causing a potential vulnerability.",source,"freed here",sink,"used here"
Maybe is it possible to track this nit by arg.asDefiningArgument() = call.getArgument(0), but as relation to the memory? So, that I could somehow track memory, not argument?
Can isAdditionalFlowStep help?
The text was updated successfully, but these errors were encountered:
There are no libraries available for this. I sketched out a solution for you here already: #18771 (comment). I understand that the solution there might not be easy to implement, but you must somehow observe that the aliasing occurred, and that information is not contained in the call to free somehow.
As I already asked, I want to understand, how can I track alias to detect use after free vulnerability? Are there any libraries, which can help track such CWEs? Here some examples:
I want to track
malloc
function and then find all alias (start tracking them). After that I want to make all arguments offree
becomesources
and make them about alias. How is it can be shown?For now I have code, that find only CWEs that are related only to the function argument:
Maybe is it possible to track this nit by
arg.asDefiningArgument() = call.getArgument(0)
, but as relation to the memory? So, that I could somehow track memory, not argument?Can
isAdditionalFlowStep
help?The text was updated successfully, but these errors were encountered: