Skip to content

Tun (valgrind and route issue)#1302

Merged
DimitriPapadopoulos merged 7 commits into
adrienverge:tunfrom
caeies:tun
Dec 22, 2025
Merged

Tun (valgrind and route issue)#1302
DimitriPapadopoulos merged 7 commits into
adrienverge:tunfrom
caeies:tun

Conversation

@caeies
Copy link
Copy Markdown
Contributor

@caeies caeies commented Sep 1, 2025

This PR add some various fixes:

  • most important: fixes a wrong call to route setup after the tun_setup.
  • fixes several issues from valgrind (memory leaks, use after free, garbage writting).
  • add a sleep after login failure in the persistent != 0 case to avoid locking the account on wrong password (should we reask password or force exit in such case ?).

Targeted to enhance #1048 .

NOTE: still missing:

  • compilation flags to allow MacOS and BSD compilation (without the tun interface).
  • still some leaks due to RC are laying around, investigation still in progress.: remaining leaks are due to the way the shutdown is processed. So we can probably ignore them as they are not happening during the running time.

@DimitriPapadopoulos
Copy link
Copy Markdown
Collaborator

Could you rebase to solve conflicts? Probably caused by Coverity fixes, sorry about it.

@caeies
Copy link
Copy Markdown
Contributor Author

caeies commented Sep 1, 2025

Could you rebase to solve conflicts? Probably caused by Coverity fixes, sorry about it.

Done. But take care your last coverity fix adds a warning on (and I'm with a -Werror build):

diff --git a/src/userinput.c b/src/userinput.c
index 7e54c32..8af3e10 100644
--- a/src/userinput.c
+++ b/src/userinput.c
@@ -370,7 +370,6 @@ void read_password(const char *pinentry, const char *hint,
 char *read_from_stdin(size_t count)
 {
        char *buf;
-       char *output;
        ssize_t bytes_read;
 
        assert(count < SIZE_MAX - 1);

@caeies
Copy link
Copy Markdown
Contributor Author

caeies commented Sep 1, 2025

And by the way, I confirm that there's a race condition between the ppp set route and the WARN: Removing wrong route to vpn server... sometime the INFO: Interface pppVPN is UP is triggered without it, leaving the tunnel stuck forever (which is curious because the echo request should trigger the tunnel down.

Best regards.

Comment thread src/http.c Outdated
Comment thread src/tunnel.c Outdated
Comment thread src/io.c
Comment thread src/config.h Outdated
Comment thread src/io.c Outdated
@DimitriPapadopoulos
Copy link
Copy Markdown
Collaborator

I would rather move 2c5c9a8 to a new PR against the master branch, to discuss this separately.

Do any of the commits here, especially the Valgrind findings, apply to the master branch, or only to the tun branch? Again, I would rather move those that apply to the master branch to a separate PR against the master branch. and release a new version before merging the tun branch.

@caeies
Copy link
Copy Markdown
Contributor Author

caeies commented Sep 3, 2025

I would rather move 2c5c9a8 to a new PR against the master branch, to discuss this separately.

Do any of the commits here, especially the Valgrind findings, apply to the master branch, or only to the tun branch? Again, I would rather move those that apply to the master branch to a separate PR against the master branch. and release a new version before merging the tun branch.

Yeah agreed. see #1306 #1305 and #1304 . thanks.

Comment thread src/io.c Outdated
memcpy(hdlc_buffer, pkt_data(packet) + 2, packet->len - 2);
} else {
hdlc_bufsize = estimated_encoded_size(packet->len);
ssize_t hdlc_bufsize = estimated_encoded_size(packet->len);
Copy link
Copy Markdown
Collaborator

@DimitriPapadopoulos DimitriPapadopoulos Sep 7, 2025

Choose a reason for hiding this comment

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

Make it a size_t instead of a ssize_t, since packet->len is also a size_t?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

well they are negative operations on these values (because hdlc_bufsize and len (not packet->len) are of the same type) , so not sure it is 100% safe in the current code to do so.

At minimum it would require to check the size of the output packet in pppd_read function and drop all packets of a size < 2 if I get it correctly.

And honestly speaking this is present in the whole file, because most of the time these values contains the return value of the read operations like (for example look at pppd_read around lines 1112).

So let me check more deeply if it is "easily" doable or not :) (and I'm not sure this has to be present in this branch anyway, as this code was the previous one and I just moved it "like this" as it was done in previous patch).

Best regards.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, as I have reduced the scope of the variable, it's easy to do, so I did it. But clearly, the whole code should be reviewed to handle this properly in all parts...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

by the way, take care that the tun branch is far behind the current master (so I rebased this one on the coverity_scan instead of the origin/tun one).

 * Thanks valgrind for pinning this out.
 * Thanks valgrind for pinning this out.
 * Thanks valgrind for pinning this out.
 * NOTE: this might not works if we don't have the
 remote idea of our ip.
 * Let's try it with a fake local ip.
 * credits goes to coverity for this one.
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