Skip to contentSkip to conversation

Fix too early argv freeing when registering DNS

PATCH In review Domagoj Pensa 3 participants 5 messages Dec 15, 2020 – Dec 17, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix too early argv freeing when registering DNS

When registering DNS on Windows, argv is freed after being used in first ipconfig command (/flushdns).

Then same argv is used uninitialized in next ipconfig command (/registerdns) causing heap exception and subprocess crash.

As a consequence second command is never executed and locked netcmd semaphore is not cleanly released.

Removing argv freeing between ipconfig calls solves the problem.

This issue was introduced in commit 870e240 (argv: do fewer memory re-allocations). After a quick glance at commit no similar problem was spotted in rest of the argv related changes.

---
 src/openvpn/tun.c | 1 -
 1 file changed, 1 deletion(-)
src/openvpn/tun.c +0 -1
index 400a50ca..2b227bb6 100644
@@ -5235,7 +5235,6 @@ ipconfig_register_dns(const struct env_set *es)
                 WIN_IPCONFIG_PATH_SUFFIX);
     argv_msg(D_TUNTAP_INFO, &argv);
     openvpn_execve_check(&argv, es, 0, err);
-    argv_free(&argv);
 
     argv_printf(&argv, "%s%s /registerdns",
                 get_win_sys_path(),
Signature · 1 line
2.29.2
Acked-by on v1 1/1
#1 lore raw

Hi,

Quoted 10 lines · Domagoj Pensa

When registering DNS on Windows, argv is freed after being used in first ipconfig command (/flushdns).

Then same argv is used uninitialized in next ipconfig command (/registerdns) causing heap exception and subprocess crash.

As a consequence second command is never executed and locked netcmd semaphore is not cleanly released.

Removing argv freeing between ipconfig calls solves the problem.

Oh! Yes, now with your patch, this is very obvious - there is a trac ticket (so when I merge this, I'll add the trac ticket number to the commit message) but it sort of puzzled Selva and me, because the code "looked sane".

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#2 lore raw

Hi

Quoted 13 lines · Gert Doering

Hi,

Quoted 4 lines · Domagoj Pensa

When registering DNS on Windows, argv is freed after being used in first ipconfig command (/flushdns).

Then same argv is used uninitialized in next ipconfig command

(/registerdns)

Quoted 5 lines

causing heap exception and subprocess crash.

As a consequence second command is never executed and locked netcmd semaphore is not cleanly released.

Quoted 7 lines
Quoted 1 line

Removing argv freeing between ipconfig calls solves the problem.

Oh! Yes, now with your patch, this is very obvious - there is a trac ticket (so when I merge this, I'll add the trac ticket number to the commit message) but it sort of puzzled Selva and me, because the code "looked sane".

Indeed, I went looking at wrong places.

Thanks,

Selva

#3 lore raw
In reply to Domagoj Pensa

Thanks. As already said, all of a sudden it is very obvious why it is crashing here... somewhat annoying that this wasn't noticed before 2.5.0 release, though.

I've stared-at-code, and tested this on Win10 (ubuntu 18 / mingw build) with a config with --register-dns. Without the patch, crash, with the patch, it just works.

Testing is not fully straightforward, as you can not "just run" such a config, but you need to either run openvpn-gui as admin, or run openvpn from a admin-cmd.exe - and it never OOMs for me, just never proceeeds after "ipconfig.exe /flushdns".

Thanks :-)

Your patch has been applied to the master and release/2.5 branch.

commit ab4688e3bd78d010ccc96adec66ab552bd009328 (master) commit 2f2df474158b6c24325a47334fc8b5eb77a69b85 (release/2.5)

Author: Domagoj Pensa
Date:   Tue Dec 15 18:16:00 2020 +0100
     Fix too early argv freeing when registering DNS

     Signed-off-by: Domagoj Pensa <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/search?l=mid&[email protected]...
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#4 lore raw

Hi!

You're welcome.
I'm glad that it helps.
Even if it is just one line of code removed. :)

Best regards,
Domagoj

Quoted 36 lines · Gert Doering

Thanks. As already said, all of a sudden it is very obvious why it is crashing here... somewhat annoying that this wasn't noticed before 2.5.0 release, though.

I've stared-at-code, and tested this on Win10 (ubuntu 18 / mingw build) with a config with --register-dns. Without the patch, crash, with the patch, it just works.

Testing is not fully straightforward, as you can not "just run" such a config, but you need to either run openvpn-gui as admin, or run openvpn from a admin-cmd.exe - and it never OOMs for me, just never proceeeds after "ipconfig.exe /flushdns".

Thanks :-)

Your patch has been applied to the master and release/2.5 branch.

commit ab4688e3bd78d010ccc96adec66ab552bd009328 (master) commit 2f2df474158b6c24325a47334fc8b5eb77a69b85 (release/2.5)

Author: Domagoj Pensa
Date:   Tue Dec 15 18:16:00 2020 +0100
     Fix too early argv freeing when registering DNS

     Signed-off-by: Domagoj Pensa <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/search?l=mid&[email protected]...
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering