Commit 8ec0573
committed
FAPI: validate eventlog size before first dereference in parse_eventlog
parse_eventlog dereferences event->eventType (offset 4 of TCG_EVENT)
before validating that the input buffer is at least sizeof(TCG_EVENT)
bytes. Any caller that passes a buffer shorter than 8 bytes triggers
a heap OOB read on the first field access, including the empty-buffer
case.
Public Fapi_GetEventLog is currently safe because file_to_buffer always
calloc(1, UINT16_MAX) and the offset-4 read lands on zero padding, but
the function-level invariant is wrong: parse_eventlog accepts a (buffer,
size) pair and uses size correctly later (for foreach_event2,
specid_event), only the first dereference skips the precondition check.
Add the up-front size check, matching the bound-check convention already
used throughout this file (lines 117, 124, 232, 250, 256, 269, 280, ...).
Reproduction (direct call into ifapi_tcg_eventlog_serialize with a
4-byte malloc, ASAN):
==ERROR: AddressSanitizer: heap-buffer-overflow ... READ of size 4
#0 parse_eventlog ifapi_eventlog_system.c:698
#1 ifapi_tcg_eventlog_serialize ifapi_json_eventlog_serialize.c:921
located 0 bytes after 4-byte region
Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>1 parent a54a27d commit 8ec0573
1 file changed
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
695 | 695 | | |
696 | 696 | | |
697 | 697 | | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
698 | 703 | | |
699 | 704 | | |
700 | 705 | | |
| |||
0 commit comments