Skip to content

libibverbs: Validate log_ind_tbl_size in create_rwq_ind_table - #1812

Open
ez-lbz wants to merge 1 commit into
linux-rdma:masterfrom
ez-lbz:fix/rwq-ind-tbl-size
Open

ez-lbz wants to merge 1 commit into
linux-rdma:masterfrom
ez-lbz:fix/rwq-ind-tbl-size

Conversation

@ez-lbz

@ez-lbz ez-lbz commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

The indirection table creation helper sizes a stack allocation from the
caller's log_ind_tbl_size and then indexes the caller's array with the same
count. Neither is checked against IB_USER_VERBS_MAX_LOG_IND_TBL_SIZE, the
largest value the kernel interface accepts, so a larger value either exhausts
the thread stack or reads past the caller's array.

The change rejects a size the kernel would not accept before any of the size
arithmetic is performed, so a rejected request never touches ind_tbl. It is
confined to libibverbs/cmd.c.

Reproduction: call ibv_create_rwq_ind_table() through a provider entry point
with log_ind_tbl_size set to 14 or above, built with AddressSanitizer and
UBSan. Before the change this reports a dynamic-stack-buffer overflow at the
alloca() and, for larger values, a shift that exceeds the width of the
operand. Values up to the documented maximum behave as before.

ibv_cmd_create_rwq_ind_table() derives the size of a stack allocation from
the caller's log_ind_tbl_size without checking it against the limit the
kernel interface defines:

    num_tbl_entries = 1 << init_attr->log_ind_tbl_size;
    cmd_size = sizeof(*cmd) + num_tbl_entries * sizeof(cmd->wq_handles[0]);
    cmd_size = (cmd_size + 7) / 8 * 8;
    cmd = alloca(cmd_size);

IB_USER_VERBS_MAX_LOG_IND_TBL_SIZE is the largest value the kernel accepts,
but it is never consulted.  A larger value makes the alloca() consume the
thread stack, and the loop that fills the message reads past the caller's
ind_tbl array:

    for (i = 0; i < num_tbl_entries; i++)
        cmd->wq_handles[i] = init_attr->ind_tbl[i]->handle;

Reject a size the kernel would not accept before computing anything.

Fixes: 0672e79 ("Introduce Receive Work Queue indirection table and its verbs")
Signed-off-by: Li Bingzhuo <lbz2770828522@gmail.com>
Copilot AI balanced review requested due to automatic review settings October 4, 2026 14:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

2 participants