Skip to content

Reject excessively long dst, src, and localip ACL parameters - #2478

Open
k-furman wants to merge 4 commits into
squid-cache:masterfrom
k-furman:fix-buffer-overflow-in-ip.cc
Open

k-furman wants to merge 4 commits into
squid-cache:masterfrom
k-furman:fix-buffer-overflow-in-ip.cc

Conversation

@k-furman

@k-furman k-furman commented Aug 20, 2026

Copy link
Copy Markdown

This change fixes buffer overflows when acl_ip_data::FactoryParse() is
given malformed dst, src, and localip ACL configuration parameters
with values exceeding 255 characters. Squid now also detects (and
rejects) trailing parameter garbage in more cases.

FactoryParse() sscanf() calls were writing raw input into 256-byte
buffers without checking input size. This change adds these limits:

  • IPv6 input patterns: 39 bytes per address and 3 bytes for the mask.
  • IPv4 input patterns: 15 bytes per address and 15 bytes for the mask.
  • Non-IP input patterns: 255 per address and 255 for the mask.

@squid-anubis squid-anubis added the M-failed-description https://github.com/measurement-factory/anubis#pull-request-labels label Aug 20, 2026
@squid-anubis

This comment was marked as resolved.

@squid-anubis squid-anubis removed the M-failed-description https://github.com/measurement-factory/anubis#pull-request-labels label Aug 20, 2026
@rousskov rousskov changed the title Fix possible buffer-overflow in acl_ip_data::FactoryParse Reject excessively long dst, src, and localip ACL parameters Aug 20, 2026

@rousskov rousskov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for posting this PR. It needs a few corrections, but nothing major AFAICT. Please let me know if you want me to do any of the suggested changes.

Please check the adjusted PR title/description. They will become a commit message when this PR is merged. I edited them to focus the title on admin-visible effects and to avoid retelling what the diff clearly says. I also wanted to clarify the scope of the proposed trailing garbage checks.

Finally, please add the author line from the first PR branch commit (or, if needed, an alternative entry) to CONTRIBUTORS. Our CI tests will check for that automatically. If you do not want any such entry, please let me know, and we will take care of that manually.

Comment thread src/acl/Ip.cc
Comment thread src/acl/Ip.cc
Comment thread src/acl/Ip.cc
Comment thread src/acl/Ip.cc Outdated
Comment thread src/acl/Ip.cc Outdated
Comment thread src/acl/Ip.cc Outdated
Comment thread src/acl/Ip.cc Outdated
@rousskov rousskov added the S-waiting-for-author author action is expected (and usually required) label Aug 20, 2026
This change fixes buffer overflows when acl_ip_data::FactoryParse() is
given malformed dst, src, and localip ACL configuration parameters
with values exceeding 255 characters. Squid now also detects (and
rejects) trailing parameter garbage in more cases.

FactoryParse() sscanf() calls were writing raw input into 256-byte
buffers without checking input size. This change adds these limits:

- IPv6 input patterns: 39 bytes per address and 3 bytes for the mask.
- IPv4 input patterns: 15 bytes per address and 15 bytes for the mask.
- Non-IP input patterns: 255 per address and 255 for the mask.

We now also extend trailing garbage checks to all of the above patterns.
@k-furman
k-furman force-pushed the fix-buffer-overflow-in-ip.cc branch from 15309af to c72b844 Compare August 21, 2026 12:53
@k-furman

Copy link
Copy Markdown
Author

Many thanks for detailed answer!

I fixed all things you suggested, squash commits, change commit message and head as in PR, and force-pushed it.

Also, I add a line with my name in CONTRIBUTORS, as you tell.

@k-furman
k-furman requested a review from rousskov August 21, 2026 16:35
Comment thread src/acl/Ip.cc
Comment thread src/acl/Ip.cc Outdated
#define SCAN_ACL2_6 "%[0123456789ABCDEFabcdef:]-%[0123456789ABCDEFabcdef:]%c"
#define SCAN_ACL3_6 "%[0123456789ABCDEFabcdef:]/%[0123456789]"
#define SCAN_ACL4_6 "%[0123456789ABCDEFabcdef:]/%c"
#define SCAN_ACL1_6 "%39[0123456789ABCDEFabcdef:]-%39[0123456789ABCDEFabcdef:]/%3[0123456789]%c"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
#define SCAN_ACL1_6 "%39[0123456789ABCDEFabcdef:]-%39[0123456789ABCDEFabcdef:]/%3[0123456789]%c"
const char* SCAN_ACL1_6 = "%39[0123456789ABCDEFabcdef:]-%39[0123456789ABCDEFabcdef:]/%3[0123456789]%c";

and the same for all others

There should be no harm from using the type system

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we are going to use the "type system" in this PR, we should use AAA:

Suggested change
#define SCAN_ACL1_6 "%39[0123456789ABCDEFabcdef:]-%39[0123456789ABCDEFabcdef:]/%3[0123456789]%c"
const auto SCAN_ACL1_6 = "%39[0123456789ABCDEFabcdef:]-%39[0123456789ABCDEFabcdef:]/%3[0123456789]%c";

Also, these variables would have to be moved to the function using them.

IMO, we should keep this polishing outside this PR scope to make the diff as clear as possible. IIRC, diff clarity is what allowed us to spot several serious problems in the earlier variations of this PR.

Comment thread src/acl/Ip.cc

@rousskov rousskov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I removed "We now also extend trailing garbage checks to all of the above patterns" from PR description to keep it up to date with the recent change.

Comment thread src/acl/Ip.cc Outdated
Comment thread src/acl/Ip.cc Outdated
debugs(28, 9, "aclIpParseIpData: '" << t << "' matched: SCAN1-v4: " << SCAN_ACL1_4);
iptype=AF_INET;
} else if (sscanf(t, SCAN_ACL2_4, addr1, addr2, &c) >= 2) {
} else if (sscanf(t, SCAN_ACL2_4, addr1, addr2, &c) == 2) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If my analysis at #2478 (review) is correct, then the >= 2 condition in the official code is buggy. Given the associated discussion, if possible, please preserve that and several other similar bugs instead of trying to fix them. In other words, if possible, please restrict this PR to what Amos called "adding the field length details". We will fix the other bugs in another/dedicated PR.

If these conditions must be changed when adding field lengths, please remind me why.

Also, return correct number of written vars in
sscanf func
@k-furman
k-furman force-pushed the fix-buffer-overflow-in-ip.cc branch from 15ff5f7 to f5b9bd8 Compare September 17, 2026 11:32
Comment thread src/acl/Ip.cc
Comment on lines +364 to +366
} else {
delete q;
throw TextException(ToSBuf("Excessively long ACL parameter value: ", t), Here());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We are almost done, I hope. AFAICT, we should now remove this new code as unreachable and adjust PR title to replace the specific "reject" claim with something vague like "Improve handling of long dst, src, and localip ACL parameters".

Suggested change
} else {
delete q;
throw TextException(ToSBuf("Excessively long ACL parameter value: ", t), Here());

If the above is correct, please remove the no-longer-necessary #include "sbuf/Stream.h" addition as well.

@rousskov

Copy link
Copy Markdown
Contributor

@k-furman, just FYI: No need to squash commits and/or rebase, especially when there are no merge conflicts. Our merge bot will squash automatically.

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

Labels

S-waiting-for-author author action is expected (and usually required)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants