Skip to content

Commit d5fdb97

Browse files
RonjaPonjaawesomekling
authored andcommitted
Kernel: Fix integer overflow in KCOV_SETBUFSIZE ioctl
1 parent 4857943 commit d5fdb97

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

Kernel/Devices/KCOVInstance.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ KCOVInstance::KCOVInstance(ProcessID pid)
1717

1818
KResult KCOVInstance::buffer_allocate(size_t buffer_size_in_entries)
1919
{
20+
if (buffer_size_in_entries < 2 || buffer_size_in_entries > KCOV_MAX_ENTRIES)
21+
return EINVAL;
22+
2023
// first entry contains index of last PC
2124
this->m_buffer_size_in_entries = buffer_size_in_entries - 1;
2225
this->m_buffer_size_in_bytes = page_round_up(buffer_size_in_entries * KCOV_ENTRY_SIZE);

Kernel/Devices/KCOVInstance.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace Kernel {
1414
// Note: These need to be kept in sync with Userland/Libraries/LibC/sys/kcov.h
1515
typedef volatile u64 kcov_pc_t;
1616
#define KCOV_ENTRY_SIZE sizeof(kcov_pc_t)
17+
#define KCOV_MAX_ENTRIES (10 * 1024 * 1024)
1718

1819
/*
1920
* One KCOVInstance is allocated per process, when the process opens /dev/kcov

0 commit comments

Comments
 (0)