Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/7.0] Fix buffer overruns in GC code #74974

Merged
merged 1 commit into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/coreclr/gc/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6085,20 +6085,22 @@ class heap_select
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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/gc/windows/gcenv.windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down