Skip to content

Security Fixes - #475

Open
keerthimuvva52 wants to merge 2 commits into
masterfrom
outbound_fixes
Open

Security Fixes#475
keerthimuvva52 wants to merge 2 commits into
masterfrom
outbound_fixes

Conversation

@keerthimuvva52

Copy link
Copy Markdown

No description provided.

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.

Pull request overview

Note

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

This PR adds defenses against malformed/forged serialized databases by validating critical engine offsets and IDs during database load, and by hardening runtime dispatch in FDR execution.

Changes:

  • Added FDR_ENGINE_COUNT to define the valid range for serialized FDR engineID values.
  • Added runtime bounds/null checks around FDR dispatch table indexing in fdrExec and fdrExecStreaming.
  • Added multiple database-load validation passes for mcsheng successor tables, FDR engine IDs, Tamarama subengine offsets, and LimEx reach map values.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
src/fdr/fdr.h Introduces a shared constant for the FDR dispatch-table size used by validation code.
src/fdr/fdr.c Adds defensive checks to prevent out-of-bounds/NULL dispatch function calls from forged engineID.
src/database.c Adds database integrity validations to reject serialized databases that could trigger OOB reads at scan time.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/database.c
Comment on lines +633 to +672
if (!isNfaType(nfa->type)) {
continue;
}

if (unlikely(ni->nfaOffset + nfa->length > rose_size)) {
return HS_INVALID;
}

if (unlikely(nfa->length <= sizeof(struct NFA))) {
return HS_INVALID;
}

const char *limex_base = (const char *)getImplNfa(nfa);
u32 limex_len = nfa->length - (u32)sizeof(struct NFA);

/* Ensure we can read reachMap[256] and reachSize. */
const u32 reach_prefix_end =
(u32)(N_CHARS + sizeof(u32)); /* reachMap + reachSize */
if (unlikely(limex_len < reach_prefix_end)) {
DEBUG_PRINTF("LimEx[%u] too small for reachMap\n", qi);
return HS_INVALID;
}

const struct LimExNFA32 *limex =
(const struct LimExNFA32 *)limex_base;
const u32 reachSize = limex->reachSize;

if (unlikely(reachSize == 0)) {
DEBUG_PRINTF("LimEx[%u] reachSize is zero\n", qi);
return HS_INVALID;
}

/* Validate every reachMap entry is within bounds. */
for (u32 i = 0; i < N_CHARS; i++) {
if (unlikely(limex->reachMap[i] >= reachSize)) {
DEBUG_PRINTF("LimEx[%u] reachMap[%u]=%u >= reachSize=%u\n",
qi, i, limex->reachMap[i], reachSize);
return HS_INVALID;
}
}
Comment thread src/database.c
Comment on lines +369 to +371

u32 as = m->alphaShift;
u32 alpha_size = 1U << as;
Comment thread src/database.c
Comment on lines +584 to +591
/* Verify child NFA body fits within the Tamarama image */
const struct NFA *child =
(const struct NFA *)(tama_base + child_off);
if (unlikely(child_off + child->length > tama_len)) {
DEBUG_PRINTF("Tamarama[%u] sub[%u] child body overflows\n",
qi, i);
return HS_INVALID;
}
Comment thread src/fdr/fdr.c
Comment on lines +848 to 853
assert(fdr->engineID < ARRAY_LENGTH(funcs));
if (unlikely(fdr->engineID >= ARRAY_LENGTH(funcs)) || !funcs[fdr->engineID]) {
return HWLM_SUCCESS; /* reject: forged engineID */
}
assert(funcs[fdr->engineID]);
return funcs[fdr->engineID](fdr, &a, groups);
Comment thread src/fdr/fdr.h
Comment on lines +39 to +41
/** Number of entries in the fdrExec dispatch table (funcs[]). Any serialized
* FDR engineID must be strictly less than this value. */
#define FDR_ENGINE_COUNT 19
Comment thread src/database.c
Comment on lines +905 to +914
/* Validate LimEx NFA reachMap entries (CWE-125). */
if (unlikely(db_validate_limex_reach_map(rose, rose_size) != HS_SUCCESS)) {
DEBUG_PRINTF("LimEx reachMap validation failed\n");
return HS_INVALID;
}
/* Validate Tamarama subengine offsets (CWE-125). */
if (unlikely(db_validate_tamarama_offsets(rose, rose_size) != HS_SUCCESS)) {
DEBUG_PRINTF("Tamarama subengine offset validation failed\n");
return HS_INVALID;
}
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