What changed, and why it matters
This commit adds Linux-only support for 'transparent huge pages' in the XMRig cryptocurrency miner. Transparent huge pages are a normal Linux performance feature that can speed up memory-heavy mining work. The change only calls the standard Linux madvise() system call with MADV_HUGEPAGE when regular huge-page allocation fails, and does nothing on Windows. There is no direct security vulnerability visible in the diff, but enabling huge pages can sometimes make certain advanced memory-based side-channel attacks slightly easier in very specific scenarios. That is a general property of huge pages, not a flaw introduced by this commit.
No immediate security action is required. Operators who are concerned about the small theoretical side-channel risk of transparent huge pages can disable them at the OS level (e.g., echo never > /sys/kernel/mm/transparent_hugepage/enabled). Reviewers may verify that the new VirtualMemory constructor argument is always supplied and that adviseLargePages failures are handled gracefully.
Security signals we found
Use of madvise with MADV_HUGEPAGE (Linux-only performance hardening/fallback)
No input validation changes around size or pointer
No privilege escalation, injection, or memory corruption pattern in diff
General industry knowledge: huge pages can marginally increase risk of certain rowhammer/cache side-channel research, but no CVE or exploit is present in the commit
Evidence from the diff
The patch extends VirtualMemory with an adviseLargePages() helper. On Linux it invokes madvise(p, size, MADV_HUGEPAGE); on Windows it returns false. When a large aligned allocation succeeds, the constructor now advises the kernel to promote the range to transparent huge pages. If the aligned allocation fails, it falls back to a 64-byte aligned allocation and still advises. Constructors gain an extra huge-page-size parameter (kDefaultHugePageSize) propagated from callers. No bounds checking, pointer validation, or privilege handling changes are introduced beyond the new madvise call.
Changed components
src/crypto/common/VirtualMemory.cppsrc/crypto/common/VirtualMemory_unix.cppsrc/crypto/common/VirtualMemory_win.cppsrc/crypto/common/VirtualMemory.hsrc/backend/cpu/CpuWorker.cppsrc/crypto/common/MemoryPool.cppsrc/crypto/rx/RxDataset.cppsrc/net/JobResults.cppInspect captured patch +32 / −5
diff --git a/src/backend/cpu/CpuWorker.cpp b/src/backend/cpu/CpuWorker.cpp
index bef2e89..cba7e88 100644
--- a/src/backend/cpu/CpuWorker.cpp
+++ b/src/backend/cpu/CpuWorker.cpp
@@ -87,14 +87,14 @@ xmrig::CpuWorker<N>::CpuWorker(size_t id, const CpuLaunchData &data) :
if (!cn_heavyZen3Memory) {
// Round up number of threads to the multiple of 8
const size_t num_threads = ((m_threads + 7) / 8) * 8;
- cn_heavyZen3Memory = new VirtualMemory(m_algorithm.l3() * num_threads, data.hugePages, false, false, node());
+ cn_heavyZen3Memory = new VirtualMemory(m_algorithm.l3() * num_threads, data.hugePages, false, false, node(), VirtualMemory::kDefaultHugePageSize);
}
m_memory = cn_heavyZen3Memory;
}
else
# endif
{
- m_memory = new VirtualMemory(m_algorithm.l3() * N, data.hugePages, false, true, node());
+ m_memory = new VirtualMemory(m_algorithm.l3() * N, data.hugePages, false, true, node(), VirtualMemory::kDefaultHugePageSize);
}
# ifdef XMRIG_ALGO_GHOSTRIDER
diff --git a/src/crypto/common/MemoryPool.cpp b/src/crypto/common/MemoryPool.cpp
index e99757e..0e80912 100644
--- a/src/crypto/common/MemoryPool.cpp
+++ b/src/crypto/common/MemoryPool.cpp
@@ -49,7 +49,7 @@ xmrig::MemoryPool::MemoryPool(size_t size, bool hugePages, uint32_t node)
constexpr size_t alignment = 1 << 24;
- m_memory = new VirtualMemory(size * pageSize + alignment, hugePages, false, false, node);
+ m_memory = new VirtualMemory(size * pageSize + alignment, hugePages, false, false, node, VirtualMemory::kDefaultHugePageSize);
m_alignOffset = (alignment - (((size_t)m_memory->scratchpad()) % alignment)) % alignment;
}
diff --git a/src/crypto/common/VirtualMemory.cpp b/src/crypto/common/VirtualMemory.cpp
index e425750..d7d3a54 100644
--- a/src/crypto/common/VirtualMemory.cpp
+++ b/src/crypto/common/VirtualMemory.cpp
@@ -75,6 +75,16 @@ xmrig::VirtualMemory::VirtualMemory(size_t size, bool hugePages, bool oneGbPages
}
m_scratchpad = static_cast<uint8_t*>(_mm_malloc(m_size, alignSize));
+
+ // Huge pages failed to allocate, but try to enable transparent huge pages for the range
+ if (alignSize >= kDefaultHugePageSize) {
+ if (m_scratchpad) {
+ adviseLargePages(m_scratchpad, m_size);
+ }
+ else {
+ m_scratchpad = static_cast<uint8_t*>(_mm_malloc(m_size, 64));
+ }
+ }
}
diff --git a/src/crypto/common/VirtualMemory.h b/src/crypto/common/VirtualMemory.h
index 3056cba..2edd3ae 100644
--- a/src/crypto/common/VirtualMemory.h
+++ b/src/crypto/common/VirtualMemory.h
@@ -65,6 +65,7 @@ public:
static void *allocateExecutableMemory(size_t size, bool hugePages);
static void *allocateLargePagesMemory(size_t size);
static void *allocateOneGbPagesMemory(size_t size);
+ static bool adviseLargePages(void *p, size_t size);
static void destroy();
static void flushInstructionCache(void *p, size_t size);
static void freeLargePagesMemory(void *p, size_t size);
diff --git a/src/crypto/common/VirtualMemory_unix.cpp b/src/crypto/common/VirtualMemory_unix.cpp
index fa9a3cc..471c9cf 100644
--- a/src/crypto/common/VirtualMemory_unix.cpp
+++ b/src/crypto/common/VirtualMemory_unix.cpp
@@ -276,6 +276,16 @@ bool xmrig::VirtualMemory::allocateOneGbPagesMemory()
}
+bool xmrig::VirtualMemory::adviseLargePages(void *p, size_t size)
+{
+# ifdef XMRIG_OS_LINUX
+ return (madvise(p, size, MADV_HUGEPAGE) == 0);
+# else
+ return false;
+# endif
+}
+
+
void xmrig::VirtualMemory::freeLargePagesMemory()
{
if (m_flags.test(FLAG_LOCK)) {
diff --git a/src/crypto/common/VirtualMemory_win.cpp b/src/crypto/common/VirtualMemory_win.cpp
index acf8119..28f515b 100644
--- a/src/crypto/common/VirtualMemory_win.cpp
+++ b/src/crypto/common/VirtualMemory_win.cpp
@@ -260,6 +260,12 @@ bool xmrig::VirtualMemory::allocateOneGbPagesMemory()
}
+bool xmrig::VirtualMemory::adviseLargePages(void *p, size_t size)
+{
+ return false;
+}
+
+
void xmrig::VirtualMemory::freeLargePagesMemory()
{
freeLargePagesMemory(m_scratchpad, m_size);
diff --git a/src/crypto/rx/RxDataset.cpp b/src/crypto/rx/RxDataset.cpp
index 9c41dd4..3495d7b 100644
--- a/src/crypto/rx/RxDataset.cpp
+++ b/src/crypto/rx/RxDataset.cpp
@@ -215,7 +215,7 @@ void xmrig::RxDataset::allocate(bool hugePages, bool oneGbPages)
return;
}
- m_memory = new VirtualMemory(maxSize(), hugePages, oneGbPages, false, m_node);
+ m_memory = new VirtualMemory(maxSize(), hugePages, oneGbPages, false, m_node, VirtualMemory::kDefaultHugePageSize);
if (m_memory->isOneGbPages()) {
m_scratchpadOffset = maxSize() + RANDOMX_CACHE_MAX_SIZE;
diff --git a/src/net/JobResults.cpp b/src/net/JobResults.cpp
index 19a1dc4..57e4a8d 100644
--- a/src/net/JobResults.cpp
+++ b/src/net/JobResults.cpp
@@ -115,7 +115,7 @@ static inline void checkHash(const JobBundle &bundle, std::vector<JobResult> &re
static void getResults(JobBundle &bundle, std::vector<JobResult> &results, uint32_t &errors, bool hwAES)
{
const auto &algorithm = bundle.job.algorithm();
- auto memory = new VirtualMemory(algorithm.l3(), false, false, false);
+ auto memory = new VirtualMemory(algorithm.l3(), false, false, false, 0, VirtualMemory::kDefaultHugePageSize);
alignas(16) uint8_t hash[32]{ 0 };
if (algorithm.family() == Algorithm::RANDOM_X) {
Why this scored 21/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.