Skip to content

esp: improve spi and ip checks.#126

Open
philljj wants to merge 3 commits into
wolfSSL:masterfrom
philljj:misc_fixes
Open

esp: improve spi and ip checks.#126
philljj wants to merge 3 commits into
wolfSSL:masterfrom
philljj:misc_fixes

Conversation

@philljj
Copy link
Copy Markdown
Contributor

@philljj philljj commented Jun 2, 2026

Description

Add some improved checks to src/wolfesp.c:

  • Check for and reject all zero SPI (all 0x00).
  • Check ip->src and ip->dst match in esp wrap and unwrap.

Allow for configurable ip matching in ESP wrap / unwrap. E.g. an SA provisioned with 0 src address will allow matching any src address.

Fixes Fenrir 4780, 5737.

An all zero SPI is not valid per rfc4303, and practically it's used to mark an empty slot in the SA array.

Technically SPI values 1-255 are reserved by IANA for future use, but I don't think it's worth checking and restricting these. IMO we should allow any SPI as long as it's non-zero.

@philljj philljj self-assigned this Jun 2, 2026
Copilot AI review requested due to automatic review settings June 2, 2026 22:16
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Improves wolfIP’s ESP Security Association (SA) handling by rejecting invalid (all-zero) SPIs and tightening SA selection to require both source and destination IP address matches during ESP transport wrap/unwrap, aligning behavior with the PR’s stated RFC4303 constraints and SA-slot semantics.

Changes:

  • Introduces a shared zero_spi constant and adds esp_spi_valid() to reject all-zero SPIs for SA creation and inbound packet processing.
  • Updates inbound SA lookup to require (SPI, src, dst) match and outbound SA selection to require (src, dst) match.
  • Extends unit tests to cover SA creation failures when SPI is all zeros.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/wolfesp.c Adds SPI validation, strengthens SA matching on wrap/unwrap, and adjusts unknown-SPI logging text.
src/test/unit/unit_esp.c Adds negative test cases for all-zero SPI during SA creation.

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

Comment thread src/wolfesp.c Outdated
Comment thread src/wolfesp.c
Comment thread src/wolfesp.c Outdated
Comment thread src/wolfesp.c Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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

Comment thread src/wolfesp.c
Comment on lines 1368 to +1372
for (size_t i = 0; i < in_sa_num; ++i) {
if (memcmp(spi, in_sa_list[i].spi, sizeof(spi)) == 0) {
ESP_DEBUG("info: found sa: 0x%02x%02x%02x%02x\n",
spi[0], spi[1], spi[2], spi[3]);
esp_sa = &in_sa_list[i];
break;
if (esp_spi_valid(out_sa_list[i].spi) < 0) {
/* skip empty slots */
continue;
}
Comment thread src/wolfesp.c
Comment on lines 1598 to 1602
for (size_t i = 0; i < out_sa_num; ++i) {
if (ip->dst == ee32(out_sa_list[i].dst)) {
esp_sa = &out_sa_list[i];
ESP_DEBUG("info: found out sa: 0x%02x%02x%02x%02x\n",
esp_sa->spi[0], esp_sa->spi[1], esp_sa->spi[2],
esp_sa->spi[3]);
break;
if (esp_spi_valid(out_sa_list[i].spi) < 0) {
/* skip empty slots */
continue;
}
Comment thread src/wolfesp.c
Comment on lines +1604 to +1608
if (out_sa_list[i].dst != 0 &&
ip->dst != ee32(out_sa_list[i].dst)) {
/* SA ip dst is configured, and doesn't match */
continue;
}
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