VirtualBox

Changeset 104829 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
May 31, 2024 3:17:46 PM (8 months ago)
Author:
vboxsync
Message:

Runtime/efi: Deduplicate signature DB after loading and after adding entries. bugref:10699

File:
1 edited

Legend:

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

    r98103 r104829  
    4848#include <iprt/mem.h>
    4949#include <iprt/sg.h>
     50#include <iprt/uuid.h>
    5051
    5152#include <iprt/formats/efi-signature.h>
     
    158159
    159160/**
    160  * Validates the given signature lsit header.
     161 * Validates the given signature list header.
    161162 *
    162163 * @returns Flag whether the list header is considered valid.
     
    266267
    267268/**
    268  * Variant for written a list of signatures where each signature gets its own signature list header
     269 * De-duplicate a signature database.
     270 *
     271 * @returns IPRT status code.
     272 * @param   pThis               The signature database instance.
     273 */
     274static int rtEfiSigDbDeduplicate(PRTEFISIGDBINT pThis)
     275{
     276    /** @todo This currently deduplicates list nodes as a whole, not looking into signature lists.
     277     * Good enough for the X.509 certificates which matter most to eliminate multiple enrollments. */
     278    for (uint32_t i = 0; i < RT_ELEMENTS(pThis->aLstSigTypes); i++)
     279    {
     280        PRTEFISIGNATURE pIt, pItNext;
     281        RTListForEachSafe(&pThis->aLstSigTypes[i], pIt, pItNext, RTEFISIGNATURE, NdLst)
     282        {
     283            PRTEFISIGNATURE pIt2;
     284            RTListForEach(&pThis->aLstSigTypes[i], pIt2, RTEFISIGNATURE, NdLst)
     285            {
     286                /* Compare up to element before pIt. */
     287                if (pIt == pIt2)
     288                    break;
     289                if (   pIt->cbSignature == pIt2->cbSignature
     290                    && !RTUuidCompare(&pIt->UuidOwner, &pIt2->UuidOwner)
     291                    && !memcmp(&pIt->abSignature[0], &pIt2->abSignature[0], pIt->cbSignature))
     292                {
     293                    RTListNodeRemove(&pIt->NdLst);
     294                    RTMemFree(pIt);
     295                    break;
     296                }
     297            }
     298        }
     299    }
     300
     301    return VINF_SUCCESS;
     302}
     303
     304
     305/**
     306 * Variant for writing a list of signatures where each signature gets its own signature list header
    269307 * (for types where each signature can differ in size like X.509).
    270308 *
     
    456494    }
    457495
     496    int rc2 = rtEfiSigDbDeduplicate(pThis);
     497    if (RT_SUCCESS(rc))
     498        rc = rc2;
     499
    458500    return rc;
    459501}
     
    492534    }
    493535
     536    int rc2 = rtEfiSigDbDeduplicate(pThis);
     537    if (RT_SUCCESS(rc))
     538        rc = rc2;
     539
    494540    return rc;
    495541}
     
    523569        rc = VERR_INVALID_PARAMETER;
    524570
     571    int rc2 = rtEfiSigDbDeduplicate(pThis);
     572    if (RT_SUCCESS(rc))
     573        rc = rc2;
     574
    525575    return rc;
    526576}
Note: See TracChangeset for help on using the changeset viewer.

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