Skip to content

Commit e1367ce

Browse files
committed
Move client-address deny test after DMA callback is cleared to avoid out-of-bounds remap
1 parent 7784ff2 commit e1367ce

1 file changed

Lines changed: 15 additions & 13 deletions

File tree

test/wh_test_clientserver.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -351,19 +351,6 @@ static int _testDma(whServerContext* server, whClientContext* client)
351351
WH_TEST_ASSERT_RETURN(0 == memcmp(testMem.srvBufAllow, testMem.cliBuf,
352352
sizeof(testMem.srvBufAllow)));
353353

354-
/* Check that out-of-allowlist client addresses are rejected */
355-
WH_TEST_ASSERT_RETURN(WH_ERROR_ACCESS == whServerDma_CopyFromClient(
356-
server, testMem.srvBufAllow,
357-
(uintptr_t)testMem.srvBufDeny,
358-
sizeof(testMem.srvBufAllow),
359-
(whServerDmaFlags){0}));
360-
WH_TEST_ASSERT_RETURN(WH_ERROR_ACCESS ==
361-
whServerDma_CopyToClient(
362-
server, (uintptr_t)testMem.srvBufDeny,
363-
testMem.srvBufAllow,
364-
sizeof(testMem.srvBufAllow),
365-
(whServerDmaFlags){0}));
366-
367354
/* Check that zero-sized copies fail, even from allowed addresses */
368355
WH_TEST_ASSERT_RETURN(WH_ERROR_BADARGS == whServerDma_CopyFromClient(
369356
server, testMem.srvBufAllow,
@@ -398,6 +385,21 @@ static int _testDma(whServerContext* server, whClientContext* client)
398385
testMem.srvRemapBufAllow,
399386
sizeof(testMem.srvBufAllow)));
400387

388+
/* Check that out-of-allowlist client addresses are rejected (done after
389+
* clearing the custom DMA callback to avoid the callback remapping the
390+
* deny address out of bounds) */
391+
WH_TEST_ASSERT_RETURN(WH_ERROR_ACCESS == whServerDma_CopyFromClient(
392+
server, testMem.srvBufAllow,
393+
(uintptr_t)testMem.srvBufDeny,
394+
sizeof(testMem.srvBufAllow),
395+
(whServerDmaFlags){0}));
396+
WH_TEST_ASSERT_RETURN(WH_ERROR_ACCESS ==
397+
whServerDma_CopyToClient(
398+
server, (uintptr_t)testMem.srvBufDeny,
399+
testMem.srvBufAllow,
400+
sizeof(testMem.srvBufAllow),
401+
(whServerDmaFlags){0}));
402+
401403
return rc;
402404
}
403405
#endif /* WOLFHSM_CFG_DMA && WOLFHSM_CFG_ENABLE_CLIENT && \

0 commit comments

Comments
 (0)