Skip to content

Fix SEC shard count integer overflow (#2892) - #2967

Merged
guangli-dai merged 1 commit into
jemalloc:devfrom
NITIN9181:dev
Jul 28, 2026
Merged

guangli-dai merged 1 commit into
jemalloc:devfrom
NITIN9181:dev

Conversation

@NITIN9181

Copy link
Copy Markdown
Contributor

Fixes #2892

Description:
The Small Extent Cache (SEC) configuration allowed the nshards to be configured with any size_t value. However, the internal functions that select and cache shard identifiers (like sec_shard_pick) use a uint8_t. If nshards exceeded 255, the shard IDs silently wrapped around. Furthermore, an unbounded nshards triggered a multiplication integer overflow when allocating the internal SEC metadata arrays.

This PR introduces two safety nets:

  1. hpa_sec_nshards and experimental_pac_sec_nshards in src/conf.c now use CONF_CHECK_MAX with a maximum limit of 255. Any configuration values greater than 255 will automatically be clipped safely.
  2. sec_init() in src/sec.c now asserts opts->nshards <= 255 to guarantee no oversized configurations can trigger a buffer overflow or wrap-around programmatically.

Limit hpa_sec_nshards and experimental_pac_sec_nshards to 255 to prevent uint8_t overflow and multiplication overflow during initialization.
@guangli-dai
guangli-dai merged commit 2b63cdb into jemalloc:dev Jul 28, 2026
162 checks passed
@guangli-dai

Copy link
Copy Markdown
Contributor

Thank you for the patch! @NITIN9181

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LLM audit

2 participants