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

Commit

Permalink
Port to 3.1 - Fix out of range access in GetRecycleMemoryInfo (#27959)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
janvorli authored and Anipik committed Jan 14, 2020
1 parent b72ff3b commit 719bfcc
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/vm/win32threadpool.h
Expand Up @@ -749,7 +749,9 @@ class ThreadpoolMgr
#else // !FEATURE_PAL
if (PAL_HasGetCurrentProcessorNumber())
{
processorNumber = GetCurrentProcessorNumber();
// On linux, GetCurrentProcessorNumber which uses sched_getcpu() can return a value greater than the number
// of processors reported by sysconf(_SC_NPROCESSORS_ONLN) when using OpenVZ kernel.
processorNumber = GetCurrentProcessorNumber()%NumberOfProcessors;
}
#endif // !FEATURE_PAL
return pRecycledListPerProcessor[processorNumber][memType];
Expand Down

0 comments on commit 719bfcc

Please sign in to comment.