Skip to content

Conversation

@MegaManSec
Copy link
Contributor

@MegaManSec MegaManSec commented Sep 4, 2025

Detach IP from source list before reattaching to destination and
decrement ipcount. This prevents list corruption and counter mismatch.

Detach IP from source list before reattaching to destination,
and update ipcount correctly. Prevents list corruption and
counter underflow.
@squid-anubis

This comment was marked as resolved.

@squid-anubis squid-anubis added the M-failed-description https://github.com/measurement-factory/anubis#pull-request-labels label Sep 4, 2025
@MegaManSec
Copy link
Contributor Author

Note: It seems that here there may be a null pointer deref, and this code block will just continuously loop if it ever happens? (I do not see how from->ip_list.head will advance) (I also don't understand why new_ipdata is not removed from the list (afaict).)
I did not investigate further.

@rousskov rousskov self-requested a review September 4, 2025 21:13
@rousskov rousskov added the S-waiting-for-reviewer ready for review: Set this when requesting a (re)review using GitHub PR Reviewers box label Sep 4, 2025
@squid-anubis squid-anubis removed the M-failed-description https://github.com/measurement-factory/anubis#pull-request-labels label Sep 5, 2025
@yadij
Copy link
Contributor

yadij commented Sep 6, 2025

FWIW; these dlinkList need replacing with a std::list or more appropriate container. That conversion alone gets rid of a lot of risky logic.

yadij
yadij previously approved these changes Sep 7, 2025
Copy link
Contributor

@yadij yadij left a comment

Choose a reason for hiding this comment

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

"good enough for now".

@yadij yadij added the backport-to-v7 maintainer has approved these changes for v7 backporting label Sep 7, 2025
Copy link
Contributor

@rousskov rousskov left a comment

Choose a reason for hiding this comment

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

I agree that official code is buggy as claimed in the first paragraph of PR description. AFAICT, the ipcount increment bug originates in 2012 commit 742a021 while the list node moving bug goes all the way to 2010 commit 56a49fd.

I also share grave concerns expressed in #2194 (comment)

I can also add a speculation that the affected code never runs because if it were to run, ipcount would become inflated, and Auth::User::clearIp() would assert() during Auth::User object destruction.

In summary, both found and !found branches probably represent broken, untested, and currently unused code that will cause a lot of problems when/if it suddenly starts being used after some other code changes!

The absorb() method is called from src/auth/negotiate and src/auth/ntlm code. The calls only have cached_user as a precondition AFAICT. It may be very useful to know why this code never runs today (if it indeed never runs). @yadij, do you know whether this part of authentication code might run in some deployment environments today and, if not, why not?

PR description: Prevents ... and counter underflow.

@MegaManSec, did you mean "overflow" (from excessive increments)? Or perhaps there is both overflow and underflow here, depending on the corrupted list? Replace with "wrong ipcount levels" or something like that?

@rousskov rousskov added S-waiting-for-author author action is expected (and usually required) and removed S-waiting-for-reviewer ready for review: Set this when requesting a (re)review using GitHub PR Reviewers box labels Sep 7, 2025
@MegaManSec
Copy link
Contributor Author

PR description: Prevents ... and counter underflow.
@MegaManSec, did you mean "overflow" (from excessive increments)? Or perhaps there is both overflow and underflow here, depending on the corrupted list? Replace with "wrong ipcount levels" or something like that?
Indeed, I really meant an underflow here:

squid/src/auth/User.cc

Lines 150 to 152 in f9ba4e1

/* catch incipient underflow */
assert(ipcount);
-- ipcount;

I think "counter mismatch" is a better phrase. I will update.

Co-authored-by: Alex Rousskov <rousskov@measurement-factory.com>
@yadij
Copy link
Contributor

yadij commented Sep 8, 2025

@rousskov; I may have missed something, but AFAIK this code runs in all deployments using authentication. When the user logs in a second time it merges the second login details into the pre-existing details. That should be true even if the user-IP caching is disabled.

FWIW, I have now opened PR #2221 to replace this dlinkList entirely.

@yadij yadij added S-waiting-for-reviewer ready for review: Set this when requesting a (re)review using GitHub PR Reviewers box and removed S-waiting-for-author author action is expected (and usually required) labels Sep 8, 2025
squid-anubis pushed a commit that referenced this pull request Sep 8, 2025
Detach IP from source list before reattaching to destination, and
decrement ipcount. This prevents list corruption, and counter mismatch.
@squid-anubis squid-anubis added M-waiting-staging-checks https://github.com/measurement-factory/anubis#pull-request-labels M-passed-staging-checks https://github.com/measurement-factory/anubis#pull-request-labels and removed M-waiting-staging-checks https://github.com/measurement-factory/anubis#pull-request-labels M-passed-staging-checks https://github.com/measurement-factory/anubis#pull-request-labels labels Sep 8, 2025
@rousskov rousskov removed the S-waiting-for-reviewer ready for review: Set this when requesting a (re)review using GitHub PR Reviewers box label Sep 8, 2025
@rousskov
Copy link
Contributor

rousskov commented Sep 8, 2025

Amos: I may have missed something, but AFAIK this code runs in all deployments using authentication.

To me, it looks like this absorb() code is supposed to run in many deployments using NTML and negotiate authentication (other schemes do not call absorb() AFAICT). Your answer partially supports that theory AFAICT. However, the bugs and concerns discussed in this PR suggest (but do not guarantee) that at least some critical parts of this code never run at all (e.g., because they would trigger an infinite loop or assertions if they do run). This is a big red flag for accepting PRs that improve this code -- if this code does not run, then those improvements are effectively untested.

FWIW, I have now opened PR #2221 to replace this dlinkList entirely.

I will continue this discussion there. If my "NTML and negotiate authentication" assumption is correct, then the changes in this PR can go in without testing if you are OK with it -- just clear this PR for merging.

@rousskov rousskov added the S-waiting-for-reviewer ready for review: Set this when requesting a (re)review using GitHub PR Reviewers box label Sep 8, 2025
@rousskov rousskov changed the title auth: fix absorb() IP list transfer logic Fix Auth::User::absorb() IP list transfer logic Sep 8, 2025
@squid-anubis squid-anubis added M-waiting-staging-checks https://github.com/measurement-factory/anubis#pull-request-labels M-failed-staging-checks https://github.com/measurement-factory/anubis#pull-request-labels M-abandoned-staging-checks https://github.com/measurement-factory/anubis#pull-request-labels and removed M-waiting-staging-checks https://github.com/measurement-factory/anubis#pull-request-labels labels Oct 12, 2025
@yadij yadij removed M-failed-staging-checks https://github.com/measurement-factory/anubis#pull-request-labels M-abandoned-staging-checks https://github.com/measurement-factory/anubis#pull-request-labels labels Oct 21, 2025
@yadij
Copy link
Contributor

yadij commented Oct 21, 2025

Recheck now that our CI issues with OpenBSD are fixed.

squid-anubis pushed a commit that referenced this pull request Oct 21, 2025
Detach IP from source list before reattaching to destination and
decrement ipcount. This prevents list corruption and counter mismatch.
@squid-anubis squid-anubis added the M-waiting-staging-checks https://github.com/measurement-factory/anubis#pull-request-labels label Oct 21, 2025
@squid-anubis squid-anubis added M-merged https://github.com/measurement-factory/anubis#pull-request-labels and removed M-waiting-staging-checks https://github.com/measurement-factory/anubis#pull-request-labels M-cleared-for-merge https://github.com/measurement-factory/anubis#pull-request-labels labels Oct 21, 2025
@MegaManSec MegaManSec deleted the decr branch October 21, 2025 08:05
squidadm pushed a commit to squidadm/squid that referenced this pull request Oct 21, 2025
Detach IP from source list before reattaching to destination and
decrement ipcount. This prevents list corruption and counter mismatch.
yadij pushed a commit that referenced this pull request Oct 21, 2025
Detach IP from source list before reattaching to destination and
decrement ipcount. This prevents list corruption and counter mismatch.
@squidadm
Copy link
Collaborator

queued for backport to v7

5 similar comments
@squidadm
Copy link
Collaborator

queued for backport to v7

@squidadm
Copy link
Collaborator

queued for backport to v7

@squidadm
Copy link
Collaborator

queued for backport to v7

@squidadm
Copy link
Collaborator

queued for backport to v7

@squidadm
Copy link
Collaborator

queued for backport to v7

@MegaManSec
Copy link
Contributor Author

MegaManSec commented Oct 23, 2025

@yadij @rousskov i think the bot is broken

@yadij yadij removed the backport-to-v7 maintainer has approved these changes for v7 backporting label Oct 23, 2025
@rousskov
Copy link
Contributor

i think the bot is broken

I assume you are referring to software that left repeated "queued for backport to v7" comments. I do not disagree with your assessment but cannot help with software that leaves those comments, and there are serious disagreements over how backporting should be automated. Anubis (i.e. the merge bot I am responsible for) does not do backporting (yet?).

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

Labels

M-merged https://github.com/measurement-factory/anubis#pull-request-labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants