Skip to content

Commit 08892a2

Browse files
author
Jyri Sarha
committed
tools: probes: reject oversized data_size_bytes to prevent integer overflow
Add a sanity check in process_sync() to reject packets with data_size_bytes exceeding 16 MiB before performing the data_size_bytes + sizeof(uint64_t) addition used for realloc sizing. Without this check, a crafted probe dump with data_size_bytes near UINT32_MAX wraps the realloc size to a small value, then the subsequent data copy writes data_size_bytes into the undersized buffer. Signed-off-by: Jyri Sarha <jyri.sarha@intel.com>
1 parent ee82513 commit 08892a2

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

tools/probes/probes_demux.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#define APP_NAME "sof-probes"
2424

2525
#define PACKET_MAX_SIZE 4096 /**< Size limit for probe data packet */
26+
#define PACKET_DATA_SIZE_MAX (16u * 1024u * 1024u) /**< Sanity limit for packet data size */
2627
#define DATA_READ_LIMIT 4096 /**< Data limit for file read */
2728
#define FILES_LIMIT 32 /**< Maximum num of probe output files */
2829
#define FILE_PATH_LIMIT 128 /**< Path limit for probe output files */
@@ -194,6 +195,12 @@ int process_sync(struct dma_frame_parser *p)
194195
{
195196
struct probe_data_packet *temp_packet;
196197

198+
if (p->packet->data_size_bytes > PACKET_DATA_SIZE_MAX) {
199+
fprintf(stderr, "error: packet data size %u exceeds maximum %u\n",
200+
p->packet->data_size_bytes, PACKET_DATA_SIZE_MAX);
201+
return -EINVAL;
202+
}
203+
197204
/* request to copy data_size from probe packet and 64-bit checksum */
198205
p->total_data_to_copy = p->packet->data_size_bytes + sizeof(uint64_t);
199206

0 commit comments

Comments
 (0)