Skip to content

UAF not flagged #15806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tardigrade-9 opened this issue Mar 5, 2024 · 2 comments
Open

UAF not flagged #15806

tardigrade-9 opened this issue Mar 5, 2024 · 2 comments
Assignees
Labels
C++ question Further information is requested

Comments

@tardigrade-9
Copy link

tardigrade-9 commented Mar 5, 2024

I borrowed the query from UseAfterFree.ql present in CodeQL repo and modified to include a custom free function, but the query is not flagging UAF.

import cpp
import semmle.code.cpp.dataflow.new.DataFlow
import semmle.code.cpp.ir.IR
import semmle.code.cpp.security.flowafterfree.FlowAfterFree
import semmle.code.cpp.security.flowafterfree.UseAfterFree
import UseAfterFreeTrace::PathGraph

module UseAfterFreeParam implements FlowFromFreeParamSig {
  predicate isSink = isUse/2;

  predicate isExcluded = isExcludedMmFreePageFromMdl/2;

  predicate sourceSinkIsRelated = defaultSourceSinkIsRelated/2;
}

import UseAfterFreeParam

module UseAfterFreeTrace = FlowFromFree<UseAfterFreeParam>;

class FreeAddrInfo extends DeallocationExpr,FunctionCall {
   
    FreeAddrInfo() {
        this.getTarget().hasGlobalName("freeaddrinfo")
    }

    override Expr getFreedExpr(){
        result = this.getArgument(0)
    }
}


from UseAfterFreeTrace::PathNode source, UseAfterFreeTrace::PathNode sink, FreeAddrInfo dealloc
where
  UseAfterFreeTrace::flowPath(source, sink) and
  isFree(source.getNode(), _, _, dealloc)
select sink.getNode(), source, sink, "Memory may have been previously freed by $@.", dealloc,
  dealloc.toString()

I'm trying to analyse https://nvd.nist.gov/vuln/detail/CVE-2021-38383

@tardigrade-9 tardigrade-9 added the question Further information is requested label Mar 5, 2024
@sidshank sidshank added the C++ label Mar 7, 2024
@Malikrehman00107
Copy link

Verify that freeaddrinfo is correctly identified and matches the signature expected by the UseAfterFree query. Ensure that the function call this.getTarget().hasGlobalName("freeaddrinfo") correctly identifies the freeaddrinfo function.

@mbg
Copy link
Member

mbg commented Apr 12, 2024

Hi @tardigrade-9 👋

Sorry for the late reply, your question seems to have fallen through the cracks last month.

Do you have a minimal code example where you would expect your query to find a result, but it doesn't?

Have you checked (e.g. by using the quick eval feature in the VSCode extension) that FreeAddrInfo can find the call to freeaddrinfo in your test database?

@mbg mbg self-assigned this Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants