Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>2022-09-02 19:43:06 +0300
committerGitHub <noreply@github.com>2022-09-02 19:43:06 +0300
commit060479834209ed7384d8cb9671924d6759cfcae5 (patch)
tree78514fa7acfe2615fdff14fc96954d5aaf3f5fc5
parent519c93d7ce3c426a90e27d7c145e80546ec06f9f (diff)
Fix buffer overruns in GC code (#74974)
Co-authored-by: Anton Lapounov <antonl@microsoft.com>
-rw-r--r--src/coreclr/gc/gc.cpp21
-rw-r--r--src/coreclr/gc/windows/gcenv.windows.cpp2
2 files changed, 14 insertions, 9 deletions
diff --git a/src/coreclr/gc/gc.cpp b/src/coreclr/gc/gc.cpp
index bfba24d3fc4..2bdc7b513d8 100644
--- a/src/coreclr/gc/gc.cpp
+++ b/src/coreclr/gc/gc.cpp
@@ -6085,20 +6085,22 @@ public:
uint16_t proc_no[MAX_SUPPORTED_CPUS];
uint16_t node_no[MAX_SUPPORTED_CPUS];
uint16_t max_node_no = 0;
- for (uint16_t i = 0; i < n_heaps; i++)
+ uint16_t heap_num;
+ for (heap_num = 0; heap_num < n_heaps; heap_num++)
{
- if (!GCToOSInterface::GetProcessorForHeap (i, &proc_no[i], &node_no[i]))
+ if (!GCToOSInterface::GetProcessorForHeap (heap_num, &proc_no[heap_num], &node_no[heap_num]))
break;
- if (!do_numa || node_no[i] == NUMA_NODE_UNDEFINED)
- node_no[i] = 0;
- max_node_no = max(max_node_no, node_no[i]);
+ assert(proc_no[heap_num] < MAX_SUPPORTED_CPUS);
+ if (!do_numa || node_no[heap_num] == NUMA_NODE_UNDEFINED)
+ node_no[heap_num] = 0;
+ max_node_no = max(max_node_no, node_no[heap_num]);
}
// Pass 2: assign heap numbers by numa node
int cur_heap_no = 0;
for (uint16_t cur_node_no = 0; cur_node_no <= max_node_no; cur_node_no++)
{
- for (int i = 0; i < n_heaps; i++)
+ for (int i = 0; i < heap_num; i++)
{
if (node_no[i] != cur_node_no)
continue;
@@ -44828,7 +44830,9 @@ HRESULT GCHeap::Initialize()
nhp_from_config = static_cast<uint32_t>(GCConfig::GetHeapCount());
- g_num_active_processors = GCToEEInterface::GetCurrentProcessCpuCount();
+ // The CPU count may be overriden by the user. Ensure that we create no more than g_num_processors
+ // heaps as that is the number of slots we have allocated for handle tables.
+ g_num_active_processors = min (GCToEEInterface::GetCurrentProcessCpuCount(), g_num_processors);
if (nhp_from_config)
{
@@ -44937,6 +44941,7 @@ HRESULT GCHeap::Initialize()
#endif //USE_REGIONS
#ifdef MULTIPLE_HEAPS
+ assert (nhp <= g_num_processors);
gc_heap::n_heaps = nhp;
hr = gc_heap::initialize_gc (seg_size, large_seg_size, pin_seg_size, nhp);
#else
@@ -44971,7 +44976,7 @@ HRESULT GCHeap::Initialize()
int available_mem_th = 10;
if (gc_heap::total_physical_mem >= ((uint64_t)80 * 1024 * 1024 * 1024))
{
- int adjusted_available_mem_th = 3 + (int)((float)47 / (float)(GCToOSInterface::GetTotalProcessorCount()));
+ int adjusted_available_mem_th = 3 + (int)((float)47 / (float)g_num_processors);
available_mem_th = min (available_mem_th, adjusted_available_mem_th);
}
diff --git a/src/coreclr/gc/windows/gcenv.windows.cpp b/src/coreclr/gc/windows/gcenv.windows.cpp
index d8675e5e106..be521a5946e 100644
--- a/src/coreclr/gc/windows/gcenv.windows.cpp
+++ b/src/coreclr/gc/windows/gcenv.windows.cpp
@@ -1190,7 +1190,7 @@ bool GCToOSInterface::GetProcessorForHeap(uint16_t heap_number, uint16_t* proc_n
// Locate heap_number-th available processor
uint16_t procIndex = 0;
size_t cnt = heap_number;
- for (uint16_t i = 0; i < GCToOSInterface::GetTotalProcessorCount(); i++)
+ for (uint16_t i = 0; i < MAX_SUPPORTED_CPUS; i++)
{
if (g_processAffinitySet.Contains(i))
{