Skip to content

Commit c371610

Browse files
committed
CI and peer review fixes
1 parent c9705c8 commit c371610

5 files changed

Lines changed: 43 additions & 5 deletions

File tree

.github/workflows/fwtpm-test.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,20 +389,36 @@ jobs:
389389
CFLAGS="${{ matrix.extra_cflags }} -g -O1"
390390
make
391391
392+
- name: Start fwtpm_server
393+
run: |
394+
rm -f fwtpm_nv.bin
395+
./src/fwtpm/fwtpm_server > /tmp/fwtpm_server.log 2>&1 &
396+
echo $! > /tmp/fwtpm_server.pid
397+
sleep 1
398+
kill -0 $(cat /tmp/fwtpm_server.pid)
399+
392400
- name: Run unit.test under valgrind
393401
run: |
394402
valgrind --error-exitcode=1 --leak-check=full \
395403
--errors-for-leak-kinds=definite \
396404
--show-leak-kinds=definite \
397405
./tests/unit.test
398406
407+
- name: Stop fwtpm_server
408+
if: always()
409+
run: |
410+
if [ -f /tmp/fwtpm_server.pid ]; then
411+
kill $(cat /tmp/fwtpm_server.pid) 2>/dev/null || true
412+
fi
413+
399414
- name: Upload failure logs
400415
if: failure()
401416
uses: actions/upload-artifact@v4
402417
with:
403418
name: fwtpm-valgrind-logs-${{ matrix.name }}
404419
path: |
405420
/tmp/fwtpm_check_*.log
421+
/tmp/fwtpm_server.log
406422
test-suite.log
407423
tests/*.log
408424
config.log

src/fwtpm/fwtpm_tis.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ int FWTPM_TIS_ServerLoop(FWTPM_CTX* ctx)
411411
{
412412
FWTPM_TIS_HAL* hal;
413413
FWTPM_TIS_REGS* regs;
414+
TPM_RC retRc = TPM_RC_SUCCESS;
414415
int rc;
415416
#ifndef _WIN32
416417
struct sigaction sa;
@@ -441,7 +442,10 @@ int FWTPM_TIS_ServerLoop(FWTPM_CTX* ctx)
441442
continue; /* EINTR or transient, retry */
442443
}
443444
if (rc < 0) {
444-
break; /* fatal error */
445+
/* Fatal HAL error — propagate so the caller can distinguish
446+
* this from a clean shutdown via ctx->running=0. */
447+
retRc = TPM_RC_FAILURE;
448+
break;
445449
}
446450

447451
/* Process the register access */
@@ -453,7 +457,7 @@ int FWTPM_TIS_ServerLoop(FWTPM_CTX* ctx)
453457
}
454458
}
455459

456-
return TPM_RC_SUCCESS;
460+
return retRc;
457461
}
458462

459463
#endif /* WOLFTPM_FWTPM && WOLFTPM_FWTPM_TIS */

src/fwtpm/fwtpm_tis_shm.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ static int TisShmInit(void* ctx, FWTPM_TIS_REGS** regs)
6868
{
6969
FWTPM_TIS_SHM_CTX* shm = (FWTPM_TIS_SHM_CTX*)ctx;
7070
int fd;
71+
/* Threat model: fwtpm_server is a dev/test tool and is NOT intended to
72+
* run setuid or as a privileged daemon. O_NOFOLLOW + mode 0600 is
73+
* sufficient for non-privileged execution. We intentionally avoid
74+
* O_EXCL so the server can recover from a prior unclean shutdown
75+
* without manual cleanup of the shm file. */
7176
int openFlags = O_CREAT | O_RDWR | O_TRUNC;
7277

7378
#ifdef O_NOFOLLOW

src/tpm2_packet.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,26 @@ void TPM2_Packet_U64ToByteArray(UINT64 val, BYTE* b)
6060
}
6161
}
6262

63-
/* Big-endian byte-array load helpers */
63+
/* Big-endian byte-array load helpers. Mirror the NULL-guard convention of the
64+
* U*ToByteArray store helpers above so callers get 0 for a NULL input rather
65+
* than a crash. */
6466
UINT16 TPM2_Packet_ByteArrayToU16(const BYTE* b)
6567
{
68+
if (b == NULL)
69+
return 0;
6670
return (UINT16)(((UINT16)b[0] << 8) | b[1]);
6771
}
6872
UINT32 TPM2_Packet_ByteArrayToU32(const BYTE* b)
6973
{
74+
if (b == NULL)
75+
return 0;
7076
return ((UINT32)b[0] << 24) | ((UINT32)b[1] << 16) |
7177
((UINT32)b[2] << 8) | b[3];
7278
}
7379
UINT64 TPM2_Packet_ByteArrayToU64(const BYTE* b)
7480
{
81+
if (b == NULL)
82+
return 0;
7583
return ((UINT64)b[0] << 56) | ((UINT64)b[1] << 48) |
7684
((UINT64)b[2] << 40) | ((UINT64)b[3] << 32) |
7785
((UINT64)b[4] << 24) | ((UINT64)b[5] << 16) |
@@ -258,7 +266,9 @@ void TPM2_Packet_ParseBytes(TPM2_Packet* packet, byte* buf, int size)
258266
void TPM2_Packet_ParseU16Buf(TPM2_Packet* packet, UINT16* size, byte* buf,
259267
UINT16 maxBufSz)
260268
{
261-
UINT16 wireSize;
269+
/* Init to 0 so a NULL packet (TPM2_Packet_ParseU16 is a no-op in that
270+
* case) leaves wireSize well-defined for the arithmetic below. */
271+
UINT16 wireSize = 0;
262272
UINT16 copySz;
263273

264274
TPM2_Packet_ParseU16(packet, &wireSize);
@@ -809,6 +819,9 @@ TPM_RC TPM2_Packet_ParseSensitiveCreate(TPM2_Packet* packet, int maxSize,
809819
UINT16 dataSz = 0;
810820
int sensStartPos;
811821

822+
if (packet == NULL || userAuth == NULL) {
823+
return BAD_FUNC_ARG;
824+
}
812825
if (packet->pos + 2 > maxSize) {
813826
rc = TPM_RC_COMMAND_SIZE;
814827
}

tests/unit_tests.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ static void test_TPM2_HmacCompute(void)
910910
digest, &digestSz);
911911
AssertIntEQ(0, rc);
912912
AssertIntEQ(32, (int)digestSz);
913-
AssertIntEQ(XMEMCMP(digest, hmacExp, sizeof(hmacExp)), 0);
913+
AssertIntEQ(0, XMEMCMP(digest, hmacExp, sizeof(hmacExp)));
914914

915915
/* Test HmacVerify with correct expected value */
916916
rc = TPM2_HmacVerify(TPM_ALG_SHA256,

0 commit comments

Comments
 (0)