Skip to content

Commit e822345

Browse files
authored
Merge pull request #9605 from wlepera/alloc_bucket_overflow_check
Check for allocator bucket overflow
2 parents a9e0c77 + d23c734 commit e822345

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

.mailmap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,5 @@ Samuel K. Gutierrez <samuel@lanl.gov> <samuelkgutierrez@users.noreply.github.com
126126
Samuel K. Gutierrez <samuel@lanl.gov> <samuel@lanl.gov>
127127

128128
Tomislav Janjusic <tomislavj@nvidia.com> Tomislavj Janjusic <tomislavj@nvidia.com>
129+
130+
William P. LePera <lepera@us.ibm.com>

opal/mca/allocator/bucket/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
# $HEADER$
1919
#
2020

21+
dist_opaldata_DATA = help-mca-allocator-bucket.txt
22+
2123
sources = \
2224
allocator_bucket.c \
2325
allocator_bucket_alloc.c \

opal/mca/allocator/bucket/allocator_bucket_alloc.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "opal_config.h"
2121
#include "opal/mca/allocator/bucket/allocator_bucket_alloc.h"
2222
#include "opal/constants.h"
23+
#include "opal/util/show_help.h"
24+
2325
/**
2426
* The define controls the size in bytes of the 1st bucket and hence every one
2527
* afterwards.
@@ -31,6 +33,8 @@
3133
*/
3234
#define MCA_ALLOCATOR_BUCKET_1_BITSHIFTS 3
3335

36+
static int max_bucket_idx;
37+
3438
/*
3539
* Initializes the mca_allocator_bucket_options_t data structure for the passed
3640
* parameters.
@@ -47,6 +51,9 @@ mca_allocator_bucket_init(mca_allocator_base_module_t *mem, int num_buckets,
4751
if (num_buckets <= 0) {
4852
num_buckets = 30;
4953
}
54+
55+
max_bucket_idx = num_buckets - 1;
56+
5057
/* initialize the array of buckets */
5158
size = sizeof(mca_allocator_bucket_bucket_t) * num_buckets;
5259
mem_options->buckets = (mca_allocator_bucket_bucket_t *) malloc(size);
@@ -89,6 +96,13 @@ void *mca_allocator_bucket_alloc(mca_allocator_base_module_t *mem, size_t size)
8996
bucket_size <<= 1;
9097
}
9198

99+
if( bucket_num > max_bucket_idx ) {
100+
size_t sz_bucket = MCA_ALLOCATOR_BUCKET_1_SIZE;
101+
opal_show_help ("help-mca-allocator-bucket.txt", "buffer too large", size, sz_bucket << max_bucket_idx,
102+
"allocator_bucket_num_buckets", bucket_num + 1);
103+
return (NULL);
104+
}
105+
92106
/* now that we know what bucket it will come from, we must get the lock */
93107
OPAL_THREAD_LOCK(&(mem_options->buckets[bucket_num].lock));
94108
/* see if there is already a free chunk */
@@ -191,6 +205,14 @@ void *mca_allocator_bucket_alloc_align(mca_allocator_base_module_t *mem, size_t
191205
bucket_size >>= 1;
192206
bucket_num++;
193207
}
208+
209+
if( bucket_num > max_bucket_idx ) {
210+
size_t sz_bucket = MCA_ALLOCATOR_BUCKET_1_SIZE;
211+
opal_show_help ("help-mca-allocator-bucket.txt", "aligned buffer too large", allocated_size, sz_bucket << max_bucket_idx,
212+
"allocator_bucket_num_buckets", bucket_num + 1);
213+
return (NULL);
214+
}
215+
194216
bucket_size = 1;
195217
bucket_size <<= MCA_ALLOCATOR_BUCKET_1_BITSHIFTS + bucket_num;
196218

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# -*- text -*-
2+
#
3+
# Copyright (c) 2021 IBM Corporation. All rights reserved
4+
# $COPYRIGHT$
5+
#
6+
# Additional copyrights may follow
7+
#
8+
# $HEADER$
9+
#
10+
# This is the US/English help file for Open MPI's allocator bucket support
11+
#
12+
[buffer too large]
13+
ERROR: Requested buffer size %zu exceeds limit of %zu
14+
Consider setting "%s" to %d
15+
#
16+
[aligned buffer too large]
17+
ERROR: Requested aligned buffer size %zu exceeds limit of %zu
18+
Consider setting "%s" to %d
19+
#

0 commit comments

Comments
 (0)