Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 719bfcc

Browse files
janvorliAnipik
authored andcommitted
Port to 3.1 - Fix out of range access in GetRecycleMemoryInfo (#27959)
Ports change #26873 to release 3.1 branch. On OpenVZ virtualized linux, GetCurrentProcessorNumber which uses sched_getcpu() can return a value greater than the number of processors reported by sched_getaffinity with CPU_COUNT or sysconf(_SC_NPROCESSORS_ONLN). For example, taskset -c 2,3 ./MyApp will make CPU_COUNT be 2 but sched_getcpu() can return 2 or 3, and OpenVZ kernel can make sysconf(_SC_NPROCESSORS_ONLN) return a limited cpu count but sched_getcpu() still report the real processor number. Example of affinity vs current CPU id on OpenVZ: nproc: 8 nprocOnline: 1 affinity: 1, 0, 0, 0, 0, 0, 0, 0, cpuid: 2 affinity: 1, 0, 0, 0, 0, 0, 0, 0, cpuid: 2 affinity: 1, 0, 0, 0, 0, 0, 0, 0, cpuid: 2 affinity: 1, 0, 0, 0, 0, 0, 0, 0, cpuid: 2 affinity: 1, 0, 0, 0, 0, 0, 0, 0, cpuid: 2 affinity: 1, 0, 0, 0, 0, 0, 0, 0, cpuid: 5 affinity: 1, 0, 0, 0, 0, 0, 0, 0, cpuid: 5
1 parent b72ff3b commit 719bfcc

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/vm/win32threadpool.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,9 @@ class ThreadpoolMgr
749749
#else // !FEATURE_PAL
750750
if (PAL_HasGetCurrentProcessorNumber())
751751
{
752-
processorNumber = GetCurrentProcessorNumber();
752+
// On linux, GetCurrentProcessorNumber which uses sched_getcpu() can return a value greater than the number
753+
// of processors reported by sysconf(_SC_NPROCESSORS_ONLN) when using OpenVZ kernel.
754+
processorNumber = GetCurrentProcessorNumber()%NumberOfProcessors;
753755
}
754756
#endif // !FEATURE_PAL
755757
return pRecycledListPerProcessor[processorNumber][memType];

0 commit comments

Comments
 (0)