Skip to content

Commit

Permalink
review cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bigbrett committed Apr 16, 2024
1 parent 192fa01 commit 144d1ca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
21 changes: 15 additions & 6 deletions src/wh_server_dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@ static int _checkAddrAgainstAllowList(const whServerDmaAddrList allowList, void*
uintptr_t startAddr = (uintptr_t)addr;
uintptr_t endAddr = startAddr + size;

if (0 == size) {
return WH_ERROR_BADARGS;
}

/* Check if the address range is fully within a allowlist entry */
for (int i = 0; i < WH_DMA_ADDR_ALLOWLIST_SIZE; i++) {
uintptr_t allowlistStartAddr = (uintptr_t)allowList[i].addr;
uintptr_t allowlistEndAddr = allowlistStartAddr + allowList[i].size;
for (int i = 0; i < WH_DMA_ADDR_ALLOWLIST_COUNT; i++) {
uintptr_t allowListStartAddr = (uintptr_t)allowList[i].addr;
uintptr_t allowListEndAddr = allowListStartAddr + allowList[i].size;

if (startAddr >= allowlistStartAddr && endAddr <= allowlistEndAddr) {
if (0 == allowList[i].size) {
continue;
}

if (startAddr >= allowListStartAddr && endAddr <= allowListEndAddr) {
return WH_ERROR_OK;
}
}
Expand Down Expand Up @@ -70,7 +78,7 @@ int wh_Server_DmaRegisterCb64(whServerContext* server, whServerDmaClientMem64Cb
return WH_ERROR_OK;
}

int wh_Server_DmaRegisterAllowList(whServerContext* server,
int wh_Server_DmaRegisterAllowList(whServerContext* server,
const whServerDmaAddrAllowList* allowlist)
{
if (NULL == server || NULL == allowlist) {
Expand All @@ -86,7 +94,8 @@ int wh_Server_DmaRegisterAllowList(whServerContext* server,
int wh_Server_DmaProcessClientAddress32(whServerContext* server,
uint32_t clientAddr,
void** xformedCliAddr, uint32_t len,
whServerDmaOper oper, whServerDmaFlags flags)
whServerDmaOper oper,
whServerDmaFlags flags)
{
int rc = WH_ERROR_OK;

Expand Down
4 changes: 2 additions & 2 deletions wolfhsm/wh_server_dma.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "wolfhsm/wh_server.h"

#define WH_DMA_ADDR_ALLOWLIST_SIZE (10)
#define WH_DMA_ADDR_ALLOWLIST_COUNT (10)

struct whServerContext_t;

Expand Down Expand Up @@ -48,7 +48,7 @@ typedef struct {
size_t size;
} whServerDmaAddr;

typedef whServerDmaAddr whServerDmaAddrList[WH_DMA_ADDR_ALLOWLIST_SIZE];
typedef whServerDmaAddr whServerDmaAddrList[WH_DMA_ADDR_ALLOWLIST_COUNT];

/* Holds allowable client read/write addresses */
typedef struct {
Expand Down

0 comments on commit 144d1ca

Please sign in to comment.