Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix off-by-one error when choosing access method candidates #5811

Merged
merged 1 commit into from
Feb 15, 2024

Conversation

MarkusPettersson98
Copy link
Contributor

@MarkusPettersson98 MarkusPettersson98 commented Feb 14, 2024

As the code comment says: get_next_inner will skip the start position, which means that by starting from the back of the available access methods we effectively look for candidates starting from index 0, i.e. the position of the direct access method. It's probably a good idea to not default users to bridges/proxies to reach the API.

Edit: The solution was found elsewhere. As it turns out, mullvad-api always forced a rotation of access methods whenever MullvadRestHandle was initialized, which means that get_next_inner/select_next_active was called twice at startup. This was subsequently solved by passing along an initial access method to the constructor of MullvadRestHandle, as is done with the tunnel state machine.


This change is Reviewable

Copy link
Member

@dlon dlon left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r1, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @MarkusPettersson98)


mullvad-daemon/src/api.rs line 250 at r1 (raw file):

            // by starting from the back of the available access methods we
            // effectively look for candidates starting from index 0.
            access_method_settings.cardinality() - 1,

Correct me if I'm wrong, but this seems to end up selecting the last method in the list if a method should be added before get_next is called.

I think a less clever solution might be better. Maybe by not setting an initial method at all, or not relying on get_next to select the "first" method.

But we could use this as a hotfix if we need one.

@MarkusPettersson98 MarkusPettersson98 force-pushed the fix/consider-direct-access-method-first branch from cc45d53 to cd31aed Compare February 14, 2024 15:45
Copy link
Contributor Author

@MarkusPettersson98 MarkusPettersson98 left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 9 files reviewed, 1 unresolved discussion (waiting on @dlon)


mullvad-daemon/src/api.rs line 250 at r1 (raw file):

Previously, dlon (David Lönnhager) wrote…

Correct me if I'm wrong, but this seems to end up selecting the last method in the list if a method should be added before get_next is called.

I think a less clever solution might be better. Maybe by not setting an initial method at all, or not relying on get_next to select the "first" method.

But we could use this as a hotfix if we need one.

Turns out that the solution in this module was very straightforward - the turned out to be somewhere else! See my updated PR comment for context 😊

Refactored get_next_inner (now select_next_active) to be more declarative and start looking for candidates starting from the start position, otherwise not much else has changed here.

@MarkusPettersson98 MarkusPettersson98 force-pushed the fix/consider-direct-access-method-first branch 4 times, most recently from 92f065f to 30cad4d Compare February 14, 2024 16:27
Copy link
Member

@dlon dlon left a comment

Choose a reason for hiding this comment

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

Reviewed 11 of 11 files at r2, 1 of 1 files at r3, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@MarkusPettersson98 MarkusPettersson98 force-pushed the fix/consider-direct-access-method-first branch 4 times, most recently from 8275764 to 74340a6 Compare February 15, 2024 07:41
@MarkusPettersson98 MarkusPettersson98 force-pushed the fix/consider-direct-access-method-first branch from 74340a6 to b226b8e Compare February 15, 2024 08:22
Copy link
Member

@dlon dlon left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 2 files at r4, 1 of 1 files at r5, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@MarkusPettersson98 MarkusPettersson98 merged commit 02240d6 into main Feb 15, 2024
38 checks passed
@MarkusPettersson98 MarkusPettersson98 deleted the fix/consider-direct-access-method-first branch February 15, 2024 09:22
@MarkusPettersson98 MarkusPettersson98 restored the fix/consider-direct-access-method-first branch February 15, 2024 10:46
@MarkusPettersson98 MarkusPettersson98 deleted the fix/consider-direct-access-method-first branch June 3, 2024 15:11
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