VirtualBox

Ignore:
Timestamp:
Mar 3, 2019 8:07:01 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
129148
Message:

Runtime/fuzz: Updates, add a target state recording mechanism to record changes in target behavior caused by mutated inputs. This allows to decide which mutated input gets added to the input corpus and which one gets discarded. Currently this is only able to record the stdout/stderr channels of the fuzzed process but other sources to detect changed behvior will get added in the future

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/fuzz/fuzz.cpp

    r77514 r77544  
    190190    /** Size of the mutation dependent data. */
    191191    size_t                      cbMutation;
     192    /** Flag whether the mutation is contained in the tree of the context. */
     193    bool                        fInTree;
    192194    /** Mutation dependent data, variable in size. */
    193195    uint8_t                     abMutation[1];
     
    471473
    472474/**
     475 * Destroys the given mutation.
     476 *
     477 * @returns nothing.
     478 * @param   pMutation           The mutation to destroy.
     479 */
     480static void rtFuzzMutationDestroy(PRTFUZZMUTATION pMutation)
     481{
     482    rtFuzzCtxMemoryFree(pMutation->pFuzzer, pMutation);
     483}
     484
     485
     486/**
    473487 * Retains an external reference to the given mutation.
    474488 *
     
    479493{
    480494    uint32_t cRefs = ASMAtomicIncU32(&pMutation->cRefs);
    481     AssertMsg(cRefs > 1 && cRefs < _1M, ("%#x %p\n", cRefs, pMutation));
     495    AssertMsg(   (   cRefs > 1
     496                  || pMutation->fInTree)
     497              && cRefs < _1M, ("%#x %p\n", cRefs, pMutation));
    482498    return cRefs;
    483499}
    484500
    485501
    486 #if 0 /* unused */
    487502/**
    488503 * Releases an external reference from the given mutation.
     
    495510    uint32_t cRefs = ASMAtomicDecU32(&pMutation->cRefs);
    496511    AssertMsg(cRefs < _1M, ("%#x %p\n", cRefs, pMutation));
     512    if (cRefs == 0 && !pMutation->fInTree)
     513        rtFuzzMutationDestroy(pMutation);
    497514    return cRefs;
    498515}
    499 #endif
    500516
    501517
     
    519535    AssertRC(rc); RT_NOREF(rc);
    520536
     537    pMutation->fInTree = true;
    521538    return rc;
    522539}
     
    531548static PRTFUZZMUTATION rtFuzzCtxMutationPickRnd(PRTFUZZCTXINT pThis)
    532549{
    533     uint64_t idxMutation = RTRandAdvU64Ex(pThis->hRand, 0, ASMAtomicReadU64(&pThis->cMutations));
     550    uint64_t idxMutation = RTRandAdvU64Ex(pThis->hRand, 1, ASMAtomicReadU64(&pThis->cMutations));
    534551
    535552    int rc = RTSemRWRequestRead(pThis->hSemRwMutations, RT_INDEFINITE_WAIT);
     
    575592        pMutation->pMutationParent = pMutationParent;
    576593        pMutation->cbMutation      = cbAdditional;
     594        pMutation->fInTree         = false;
    577595
    578596        if (pMutationParent)
     
    583601
    584602    return pMutation;
    585 }
    586 
    587 
    588 /**
    589  * Destroys the given mutation.
    590  *
    591  * @returns nothing.
    592  * @param   pMutation           The mutation to destroy.
    593  */
    594 static void rtFuzzMutationDestroy(PRTFUZZMUTATION pMutation)
    595 {
    596     rtFuzzCtxMemoryFree(pMutation->pFuzzer, pMutation);
    597603}
    598604
     
    888894        rtFuzzCtxMemoryFree(pFuzzer, pThis->u.Blob.pvInput);
    889895
     896    rtFuzzMutationRelease(pThis->pMutationTop);
    890897    rtFuzzCtxMemoryFree(pFuzzer, pThis);
    891898    RTFuzzCtxRelease(pFuzzer);
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette