Skip to content

Commit

Permalink
return to variable length arrays until someone finds out how to avoid…
Browse files Browse the repository at this point in the history
… these properly
  • Loading branch information
neusdan committed Jul 22, 2015
1 parent 5e0f2f5 commit 1ff54a5
Showing 1 changed file with 51 additions and 51 deletions.
102 changes: 51 additions & 51 deletions grub-core/tpm/i386/pc/tpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@

GRUB_MOD_LICENSE ("GPLv3+");

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wvla"


/* TPM_ENTITY_TYPE values */
static const grub_uint16_t TPM_ET_SRK = 0x0004;
Expand Down Expand Up @@ -88,15 +91,6 @@ typedef struct {
grub_uint32_t bytesRequested;
} GRUB_PACKED GetRandomIncoming;

/* TPM_GetRandom Outgoing Operand */
typedef struct {
grub_uint16_t tag;
grub_uint32_t paramSize;
grub_uint32_t returnCode;
grub_uint32_t randomBytesSize;
grub_uint8_t randomBytes[1];
} GRUB_PACKED GetRandomOutgoing;

/* TPM_OIAP Incoming Operand */
typedef struct {
grub_uint16_t tag;
Expand Down Expand Up @@ -141,38 +135,6 @@ typedef struct tdTCG_PCClientPCREventStruc {
grub_uint8_t event[1];
} GRUB_PACKED TCG_PCClientPCREvent;

/* TPM_UNSEAL Incoming Operand */
typedef struct {
grub_uint16_t tag;
grub_uint32_t paramSize;
grub_uint32_t ordinal;
grub_uint32_t parentHandle;
grub_uint8_t sealedData[1];
grub_uint32_t authHandle;
grub_uint8_t nonceOdd[TPM_NONCE_SIZE];
grub_uint8_t continueAuthSession;
grub_uint8_t parentAuth[TPM_AUTHDATA_SIZE];
grub_uint32_t dataAuthHandle;
grub_uint8_t dataNonceOdd[TPM_NONCE_SIZE];
grub_uint8_t continueDataSession;
grub_uint8_t dataAuth[TPM_AUTHDATA_SIZE];
} GRUB_PACKED UNSEAL_Incoming;

/* TPM_UNSEAL Outgoing Operand */
typedef struct {
grub_uint16_t tag;
grub_uint32_t paramSize;
grub_uint32_t returnCode;
grub_uint32_t secretSize;
grub_uint8_t unsealedData[1];
grub_uint8_t nonceEven[TPM_NONCE_SIZE];
grub_uint8_t continueAuthSession;
grub_uint8_t resAuth[TPM_AUTHDATA_SIZE];
grub_uint8_t dataNonceEven[TPM_NONCE_SIZE];
grub_uint8_t continueDataSession;
grub_uint8_t dataAuth[TPM_AUTHDATA_SIZE];
} GRUB_PACKED UNSEAL_Outgoing;

/* grub_fatal() on error */
static void
grub_TPM_readpcr( const unsigned long index, grub_uint8_t* result ) {
Expand Down Expand Up @@ -469,10 +431,17 @@ grub_TPM_getRandom( const unsigned long randomBytesRequested, grub_uint8_t* resu
PassThroughToTPM_InputParamBlock* passThroughInput = NULL;
grub_uint16_t inputlen = sizeof( *passThroughInput ) - sizeof( passThroughInput->TPMOperandIn ) + sizeof( *getRandomInput );

GetRandomOutgoing* getRandomOutput = NULL;
/* TPM_GetRandom Outgoing Operand */
struct {
grub_uint16_t tag;
grub_uint32_t paramSize;
grub_uint32_t returnCode;
grub_uint32_t randomBytesSize;
grub_uint8_t randomBytes[randomBytesRequested];
} GRUB_PACKED *getRandomOutput;

PassThroughToTPM_OutputParamBlock* passThroughOutput = NULL;
grub_uint16_t outputlen = sizeof( *passThroughOutput ) - sizeof( passThroughOutput->TPMOperandOut ) + sizeof( *getRandomOutput ) + randomBytesRequested;
grub_uint16_t outputlen = sizeof( *passThroughOutput ) - sizeof( passThroughOutput->TPMOperandOut ) + sizeof( *getRandomOutput );

passThroughInput = grub_zalloc( inputlen );
if( ! passThroughInput ) {
Expand All @@ -497,7 +466,7 @@ grub_TPM_getRandom( const unsigned long randomBytesRequested, grub_uint8_t* resu
tcg_passThroughToTPM( passThroughInput, passThroughOutput );
grub_free( passThroughInput );

getRandomOutput = (void *)passThroughOutput->TPMOperandOut;
getRandomOutput = (void *)passThroughOutput->TPMOperandOut;
grub_uint32_t tpm_getRandomReturnCode = grub_swap_bytes32( getRandomOutput->returnCode );

if( tpm_getRandomReturnCode != TPM_SUCCESS ) {
Expand All @@ -514,7 +483,7 @@ grub_TPM_getRandom( const unsigned long randomBytesRequested, grub_uint8_t* resu
grub_fatal( "grub_TPM_getRandom: tpmOutput->randomBytesSize != randomBytesRequested" );
}

grub_memcpy( result, getRandomOutput->randomBytes, (grub_uint32_t) randomBytesRequested );
grub_memcpy( result, &getRandomOutput->randomBytes[0], (grub_uint32_t) randomBytesRequested );

grub_free( passThroughOutput );
}
Expand Down Expand Up @@ -706,15 +675,43 @@ grub_TPM_unseal( const grub_uint8_t* sealedBuffer, const grub_size_t inputSize,
CHECK_FOR_NULL_ARGUMENT( sealedBuffer )
CHECK_FOR_NULL_ARGUMENT( resultSize)

UNSEAL_Incoming* unsealInput = NULL;
/* TPM_UNSEAL Incoming Operand */
struct {
grub_uint16_t tag;
grub_uint32_t paramSize;
grub_uint32_t ordinal;
grub_uint32_t parentHandle;
grub_uint8_t sealedData[inputSize];
grub_uint32_t authHandle;
grub_uint8_t nonceOdd[TPM_NONCE_SIZE];
grub_uint8_t continueAuthSession;
grub_uint8_t parentAuth[TPM_AUTHDATA_SIZE];
grub_uint32_t dataAuthHandle;
grub_uint8_t dataNonceOdd[TPM_NONCE_SIZE];
grub_uint8_t continueDataSession;
grub_uint8_t dataAuth[TPM_AUTHDATA_SIZE];
} GRUB_PACKED *unsealInput;

PassThroughToTPM_InputParamBlock *passThroughInput = NULL;
grub_uint16_t inputlen = sizeof( *passThroughInput ) - sizeof( passThroughInput->TPMOperandIn ) + sizeof( *unsealInput ) + inputSize;

UNSEAL_Outgoing* unsealOutput = NULL;
grub_uint16_t inputlen = sizeof( *passThroughInput ) - sizeof( passThroughInput->TPMOperandIn ) + sizeof( *unsealInput );

/* TPM_UNSEAL Outgoing Operand */
struct {
grub_uint16_t tag;
grub_uint32_t paramSize;
grub_uint32_t returnCode;
grub_uint32_t secretSize;
grub_uint8_t unsealedData[inputSize]; /* FIXME: what size to use here? */
grub_uint8_t nonceEven[TPM_NONCE_SIZE];
grub_uint8_t continueAuthSession;
grub_uint8_t resAuth[TPM_AUTHDATA_SIZE];
grub_uint8_t dataNonceEven[TPM_NONCE_SIZE];
grub_uint8_t continueDataSession;
grub_uint8_t dataAuth[TPM_AUTHDATA_SIZE];
} GRUB_PACKED *unsealOutput;

PassThroughToTPM_OutputParamBlock *passThroughOutput = NULL;
grub_uint16_t outputlen = sizeof( *passThroughOutput ) - sizeof( passThroughOutput->TPMOperandOut ) + sizeof( *unsealOutput ) + inputSize ;
grub_uint16_t outputlen = sizeof( *passThroughOutput ) - sizeof( passThroughOutput->TPMOperandOut ) + sizeof( *unsealOutput );

passThroughInput = grub_zalloc( inputlen );
if( ! passThroughInput ) {
Expand Down Expand Up @@ -829,7 +826,7 @@ grub_TPM_unseal( const grub_uint8_t* sealedBuffer, const grub_size_t inputSize,
grub_fatal( "grub_TPM_unseal: memory allocation failed" );
}

grub_memcpy( *result, unsealOutput->unsealedData, *resultSize );
grub_memcpy( *result, &unsealOutput->unsealedData[0], *resultSize );

grub_free( passThroughOutput );
}
Expand Down Expand Up @@ -1027,4 +1024,7 @@ GRUB_MOD_FINI(tpm)
#endif

}

#pragma GCC diagnostic pop

/* End TCG extension */

0 comments on commit 1ff54a5

Please sign in to comment.