VirtualBox

Changeset 103532 in vbox


Ignore:
Timestamp:
Feb 22, 2024 2:05:31 PM (11 months ago)
Author:
vboxsync
Message:

VBoxManage: Add subcommand for enabling UEFI secure boot (and show the status in the VM infos).
Main/NVRAMStore+UefiVariableStore: Tweaks to allow reading the UEFI secure boot state when the VM isn't mutable.
doc/manual: Update VBoxManage manpage.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/manual/en_US/man_VBoxManage-modifynvram.xml

    r99513 r103532  
    9191      <arg>--owner-uuid=<replaceable>uuid</replaceable></arg>
    9292    </cmdsynopsis>
     93    <cmdsynopsis id="synopsis-vboxmanage-modifynvram-secureboot">
     94      <command>VBoxManage modifynvram</command>
     95      <group choice="req">
     96        <arg choice="plain"><replaceable>uuid</replaceable></arg>
     97        <arg choice="plain"><replaceable>vmname</replaceable></arg>
     98      </group>
     99      <arg choice="plain">secureboot</arg>
     100      <group choice="req">
     101        <arg choice="plain">--enable</arg>
     102        <arg choice="plain">--disable</arg>
     103      </group>
     104    </cmdsynopsis>
    93105    <cmdsynopsis id="synopsis-vboxmanage-modifynvram-listvars">
    94106      <command>VBoxManage modifynvram</command>
     
    194206          <term><option>--owner-uuid=<replaceable>uuid</replaceable></option></term>
    195207          <listitem><para>The UUID identifying the owner of the platform key.</para>
     208          </listitem>
     209        </varlistentry>
     210      </variablelist>
     211    </refsect2>
     212
     213    <refsect2 id="vboxmanage-modifynvram-secureboot">
     214      <title>modifynvram secureboot</title>
     215      <remark role="help-copy-synopsis"/>
     216      <para>
     217        Enables or disables UEFI secure boot.
     218      </para>
     219      <variablelist>
     220        <varlistentry>
     221          <term><option>--enable></option></term>
     222          <listitem><para>Enables UEFI secure boot if the state of the key
     223            enrolment permits.</para>
     224          </listitem>
     225        </varlistentry>
     226        <varlistentry>
     227          <term><option>--disable></option></term>
     228          <listitem><para>Disables UEFI secure boot.</para>
    196229          </listitem>
    197230        </varlistentry>
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageInfo.cpp

    r101125 r103532  
    14141414    if (bstrNVRAMFile.isNotEmpty())
    14151415        SHOW_BSTR_STRING("BIOS NVRAM File", Info::tr("BIOS NVRAM File:"), bstrNVRAMFile);
     1416    if (   firmwareType == FirmwareType_EFI || firmwareType == FirmwareType_EFI32
     1417        || firmwareType == FirmwareType_EFI64 || firmwareType == FirmwareType_EFIDUAL)
     1418    {
     1419        ComPtr<IUefiVariableStore> uefiVarStore;
     1420        CHECK_ERROR_RET(nvramStore, COMGETTER(UefiVariableStore)(uefiVarStore.asOutParam()), hrc);
     1421        SHOW_BOOLEAN_PROP(uefiVarStore, SecureBootEnabled, "SecureBoot", Info::tr("UEFI Secure Boot:"));
     1422    }
    14161423    SHOW_BOOLEAN_PROP_EX(platform,   RTCUseUTC, "rtcuseutc", Info::tr("RTC:"), "UTC", Info::tr("local time"));
    14171424
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageModifyNvram.cpp

    r98988 r103532  
    6464static RTEXITCODE handleModifyNvramInitUefiVarStore(HandlerArg *a, ComPtr<INvramStore> &nvramStore)
    6565{
    66     RT_NOREF(a);
     66    if (a->argc != 2)
     67        return errorTooManyParameters(&a->argv[1]);
    6768
    6869    CHECK_ERROR2I_RET(nvramStore, InitUefiVariableStore(0 /*aSize*/), RTEXITCODE_FAILURE);
     
    7980static RTEXITCODE handleModifyNvramEnrollMsSignatures(HandlerArg *a, ComPtr<INvramStore> &nvramStore)
    8081{
    81     RT_NOREF(a);
     82    if (a->argc != 2)
     83        return errorTooManyParameters(&a->argv[1]);
    8284
    8385    ComPtr<IUefiVariableStore> uefiVarStore;
     
    252254static RTEXITCODE handleModifyNvramEnrollOraclePlatformKey(HandlerArg *a, ComPtr<INvramStore> &nvramStore)
    253255{
    254     RT_NOREF(a);
     256    if (a->argc != 2)
     257        return errorTooManyParameters(&a->argv[1]);
    255258
    256259    ComPtr<IUefiVariableStore> uefiVarStore;
     
    263266
    264267/**
     268 * Handles the 'modifynvram myvm secureboot' sub-command.
     269 * @returns Exit code.
     270 * @param   a               The handler argument package.
     271 * @param   nvram           Reference to the NVRAM store interface.
     272 */
     273static RTEXITCODE handleModifyNvramSecureBoot(HandlerArg *a, ComPtr<INvramStore> &nvramStore)
     274{
     275    static const RTGETOPTDEF s_aOptions[] =
     276    {
     277        /* common options */
     278        { "--enable",       'e', RTGETOPT_REQ_NOTHING },
     279        { "--disable",      'd', RTGETOPT_REQ_NOTHING }
     280    };
     281
     282    int enable = -1;
     283
     284    RTGETOPTSTATE GetState;
     285    int vrc = RTGetOptInit(&GetState, a->argc - 2, &a->argv[2], s_aOptions, RT_ELEMENTS(s_aOptions), 0, 0);
     286    AssertRCReturn(vrc, RTEXITCODE_FAILURE);
     287
     288    int c;
     289    RTGETOPTUNION ValueUnion;
     290    while ((c = RTGetOpt(&GetState, &ValueUnion)) != 0)
     291    {
     292        switch (c)
     293        {
     294            case 'e':   // --enable
     295                if (enable >= 0)
     296                    return errorSyntax(Nvram::tr("You can specify either --enable or --disable once."));
     297                enable = 1;
     298                break;
     299
     300            case 'd':   // --disable
     301                if (enable >= 0)
     302                    return errorSyntax(Nvram::tr("You can specify either --enable or --disable once."));
     303                enable = 0;
     304                break;
     305
     306            default:
     307                return errorGetOpt(c, &ValueUnion);
     308        }
     309    }
     310
     311    if (enable < 0)
     312        return errorSyntax(Nvram::tr("You have to specify either --enable or --disable."));
     313
     314    ComPtr<IUefiVariableStore> uefiVarStore;
     315    CHECK_ERROR2I_RET(nvramStore, COMGETTER(UefiVariableStore)(uefiVarStore.asOutParam()), RTEXITCODE_FAILURE);
     316
     317    CHECK_ERROR2I_RET(uefiVarStore, COMSETTER(SecureBootEnabled((BOOL)enable)), RTEXITCODE_FAILURE);
     318    return RTEXITCODE_SUCCESS;
     319}
     320
     321
     322/**
    265323 * Handles the 'modifynvram myvm listvars' sub-command.
    266324 * @returns Exit code.
     
    270328static RTEXITCODE handleModifyNvramListUefiVars(HandlerArg *a, ComPtr<INvramStore> &nvramStore)
    271329{
    272     RT_NOREF(a);
     330    if (a->argc != 2)
     331        return errorTooManyParameters(&a->argv[1]);
    273332
    274333    ComPtr<IUefiVariableStore> uefiVarStore;
     
    362421        }
    363422        else
    364            rcExit = RTMsgErrorExitFailure(Nvram::tr("Error opening '%s': %Rrc"), pszVarDataFilename, vrc);
     423            rcExit = RTMsgErrorExitFailure(Nvram::tr("Error opening '%s': %Rrc"), pszVarDataFilename, vrc);
    365424    }
    366425
     
    491550    }
    492551    else
    493        rcExit = RTMsgErrorExitFailure(Nvram::tr("Error opening '%s': %Rrc"), pszVarDataFilename, vrc);
     552        rcExit = RTMsgErrorExitFailure(Nvram::tr("Error opening '%s': %Rrc"), pszVarDataFilename, vrc);
    494553
    495554    return rcExit;
     
    548607        hrc = handleModifyNvramEnrollOraclePlatformKey(a, nvramStore) == RTEXITCODE_SUCCESS ? S_OK : E_FAIL;
    549608    }
     609    else if (!strcmp(a->argv[1], "secureboot"))
     610    {
     611        setCurrentSubcommand(HELP_SCOPE_MODIFYNVRAM_SECUREBOOT);
     612        hrc = handleModifyNvramSecureBoot(a, nvramStore) == RTEXITCODE_SUCCESS ? S_OK : E_FAIL;
     613    }
    550614    else if (!strcmp(a->argv[1], "listvars"))
    551615    {
     
    569633    }
    570634    else
    571         return errorUnknownSubcommand(a->argv[0]);
     635        return errorUnknownSubcommand(a->argv[1]);
    572636
    573637    /* commit changes */
  • trunk/src/VBox/Main/include/AutoStateDep.h

    r98263 r103532  
    7373              mRegistered(FALSE)
    7474        {
    75             Assert(aThat);
    76             mRC = aThat->i_addStateDependency(taDepType, &mMachineState,
    77                                             &mRegistered);
     75            if (RT_VALID_PTR(aThat))
     76                mRC = aThat->i_addStateDependency(taDepType, &mMachineState,
     77                                                  &mRegistered);
    7878        }
    7979        ~AutoStateDependency()
    8080        {
    81             if (SUCCEEDED(mRC))
     81            if (RT_VALID_PTR(mThat) && SUCCEEDED(mRC))
    8282                mThat->i_releaseStateDependency();
    8383        }
     
    8888        {
    8989            AssertReturnVoid(SUCCEEDED(mRC));
    90             mThat->i_releaseStateDependency();
     90            if (RT_VALID_PTR(mThat))
     91                mThat->i_releaseStateDependency();
    9192            mRC = E_FAIL;
    9293        }
     
    9899        {
    99100            AssertReturnVoid(!SUCCEEDED(mRC));
    100             mRC = mThat->i_addStateDependency(taDepType, &mMachineState,
    101                                             &mRegistered);
     101            if (RT_VALID_PTR(mThat))
     102                mRC = mThat->i_addStateDependency(taDepType, &mMachineState,
     103                                                  &mRegistered);
     104            else
     105                mRC = S_OK;
    102106        }
    103107
  • trunk/src/VBox/Main/src-all/NvramStoreImpl.cpp

    r99739 r103532  
    380380{
    381381#ifndef VBOX_COM_INPROC
    382     /* the machine needs to be mutable */
    383     AutoMutableStateDependency adep(m->pParent);
    384     if (FAILED(adep.hrc())) return adep.hrc();
    385 
    386382    Utf8Str strPath;
    387383    NvramStore::getNonVolatileStorageFile(strPath);
     
    418414    {
    419415        m->pUefiVarStore.queryInterfaceTo(aUefiVarStore.asOutParam());
    420 
    421         /* Mark the NVRAM store as potentially modified. */
    422         m->pParent->i_setModified(Machine::IsModified_NvramStore);
     416        /* The "modified" state is handled by i_retainUefiVarStore. */
    423417    }
    424418
     
    10661060HRESULT NvramStore::i_retainUefiVarStore(PRTVFS phVfs, bool fReadonly)
    10671061{
    1068     /* the machine needs to be mutable */
    1069     AutoMutableStateDependency adep(m->pParent);
     1062    /* the machine needs to be mutable unless fReadonly is set */
     1063    AutoMutableStateDependency adep(fReadonly ? NULL : m->pParent);
    10701064    if (FAILED(adep.hrc())) return adep.hrc();
    10711065
  • trunk/src/VBox/Main/src-server/UefiVariableStoreImpl.cpp

    r99739 r103532  
    152152HRESULT UefiVariableStore::getSecureBootEnabled(BOOL *pfEnabled)
    153153{
    154     /* the machine needs to be mutable */
    155     AutoMutableStateDependency adep(m->pMachine);
    156     if (FAILED(adep.hrc())) return adep.hrc();
    157 
    158154    HRESULT hrc = i_retainUefiVariableStore(true /*fReadonly*/);
    159155    if (FAILED(hrc)) return hrc;
     
    324320                                               std::vector<BYTE> &aData)
    325321{
    326     /* the machine needs to be mutable */
    327     AutoMutableStateDependency adep(m->pMachine);
    328     if (FAILED(adep.hrc())) return adep.hrc();
    329 
    330322    HRESULT hrc = i_retainUefiVariableStore(true /*fReadonly*/);
    331323    if (FAILED(hrc)) return hrc;
     
    370362                                          std::vector<com::Guid> &aOwnerUuids)
    371363{
    372     /* the machine needs to be mutable */
    373     AutoMutableStateDependency adep(m->pMachine);
    374     if (FAILED(adep.hrc())) return adep.hrc();
    375 
    376364    HRESULT hrc = i_retainUefiVariableStore(true /*fReadonly*/);
    377365    if (FAILED(hrc)) return hrc;
     
    522510HRESULT UefiVariableStore::enrollDefaultMsSignatures(void)
    523511{
     512    /* the machine needs to be mutable */
    524513    AutoMutableStateDependency adep(m->pMachine);
    525514    if (FAILED(adep.hrc())) return adep.hrc();
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