Skip to contentSkip to conversation

Do not skip ERROR:/SUCCESS: response from management interface

PATCH In review [email protected]... 3 participants 9 messages Jul 28, 2022 – Aug 23, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Do not skip ERROR:/SUCCESS: response from management interface

From: Selva Nair <[email protected]...>

Generally we expect a response of SUCCESS: or ERROR: to every command sent to the management interface. But, while in the management-hold state, sending "signal foo" returns only the following reply (with foo = SIGHUP, SIGUSR1 etc.):

Quoted 1 line

HOLD:Waiting for hold release:0

Fix by always responding

ERROR: signal 'foo' is currently ignored"
followed by the above line.

Though this is seldom seen in practice[*], such violation of the protocol could stall clients like the GUI. So fix it.

[*] One way this happens is with SIGHUP sent before the daemon is on hold state which it enters before the SIGHUP is received.

---
 src/openvpn/manage.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
src/openvpn/manage.c +1 -4
index 5d58c662..27aa49a8 100644
@@ -426,14 +426,11 @@ man_signal(struct management *man, const char *name)
         }
         else
         {
+            msg(M_CLIENT, "ERROR: signal '%s' is currently ignored", name);
             if (man->persist.special_state_msg)
             {
                 msg(M_CLIENT, "%s", man->persist.special_state_msg);
             }
-            else
-            {
-                msg(M_CLIENT, "ERROR: signal '%s' is currently ignored", name);
-            }
         }
     }
     else
Signature · 1 line
2.30.2
#1 lore raw

PATCH 2/2 Allow a few levels of recursion in virtual_output_callback()

From: Selva Nair <[email protected]...>

Without this, replies to commands from the management client are sometimes lost if the server is writing when a command comes in and leads to a recursive call to this function.

For some reason I've not been able to trigger this on Linux, but it does sometimes happen on Windows during intense write activity by openvpn.exe sending log lines to the management client.

---
 src/openvpn/manage.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
src/openvpn/manage.c +7 -2
index 27aa49a8..5670e594 100644
@@ -312,8 +312,7 @@ virtual_output_callback_func(void *arg, const unsigned int flags, const char *st
 
 #define AF_DID_PUSH  (1<<0)
 #define AF_DID_RESET (1<<1)
-
-    if (!recursive_level) /* don't allow recursion */
+    if (recursive_level < 5) /* limit recursion */
     {
         struct gc_arena gc = gc_new();
         struct log_entry e;
@@ -380,6 +379,12 @@ virtual_output_callback_func(void *arg, const unsigned int flags, const char *st
 
         --recursive_level;
     }
+    else
+    {
+        /* cannot use msg here */
+        printf("virtual_output: message to management interface "
+               "dropped due to recursion: <%s>\n", str);
+    }
 }
 
 /*
Signature · 1 line
2.30.2
Acked-by on v1 1/2
#7 lore raw
In reply to [email protected]...

Am 28.07.22 um 05:45 schrieb [email protected]...:

Quoted 11 lines

From: Selva Nair <[email protected]...>

Generally we expect a response of SUCCESS: or ERROR: to every command sent to the management interface. But, while in the management-hold state, sending "signal foo" returns only the following reply (with foo = SIGHUP, SIGUSR1 etc.):

Quoted 1 line

HOLD:Waiting for hold release:0

Fix by always responding

Quoted 9 lines

ERROR: signal 'foo' is currently ignored"
followed by the above line.

Though this is seldom seen in practice[*], such violation of the protocol could stall clients like the GUI. So fix it.

[*] One way this happens is with SIGHUP sent before the daemon is on hold state which it enters before the SIGHUP is received.

Acked-by Arne Schwabe
#8 lore raw
In reply to [email protected]...

I'm not sure I understand what is happening here, exactly, but since Arne understands management way better and ACKed this - in it goes :) (it *looks* harmless enough).

Since I understand this to be a bugfix, applied to 2.5 as well.

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

commit 579b78e22feab7fe7cc627355cbb270cd91aebb4 (master) commit e3c397b0edd86158b8c417f6d396920a7e2eae68 (release/2.5)

Author: Selva Nair
Date:   Wed Jul 27 23:45:07 2022 -0400
     Do not skip ERROR:/SUCCESS: response from management interface

     Signed-off-by: Selva Nair <[email protected]...>
     Acked-by: Arne Schwabe <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg24750.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

Acked-by on v1 2/2
#2 lore raw

[Openvpn-devel] [PATCH applied] Re: Allow a few levels of recursion in virtual_output_callback()

In reply to [email protected]...

I cannot test this (beyond "compile", but that is trivial) but the description in

https://www.mail-archive.com/[email protected]/msg24738.html

makes sense, so allowing "a limited amount" of recursion plus actually logging when this is hit should make management more robust against overlapping timing issues aka "race conditions".

Your patch has been applied to the master branch.

commit 4dfd592ff1ee18aa4859264c8a341dfa1a291988

Author: Selva Nair
Date:   Wed Jul 27 23:45:08 2022 -0400
     Allow a few levels of recursion in virtual_output_callback()

     Signed-off-by: Selva Nair <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg24751.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

author
#3 lore raw

Re: [Openvpn-devel] [PATCH applied] Re: Allow a few levels of recursion in virtual_output_callback()

Hi,

Quoted 6 lines · Gert Doering

I cannot test this (beyond "compile", but that is trivial) but the description in

Quoted 8 lines

https://www.mail-archive.com/[email protected]/msg24738.html

makes sense, so allowing "a limited amount" of recursion plus actually logging when this is hit should make management more robust against overlapping timing issues aka "race conditions".

Your patch has been applied to the master branch.

Can we also apply this to 2.5? I see this trigerred easily with the new persistent connection / PLAP support. I haven't figured the exact reason but hitting reconnect or disconnect at certain instances triggers this -- like when the connection is almost complete and the daemon is doing slow-ish netsh commands. The same code-path is not traversed when interactive service is in use and it seems hitting the "race condition" is much harder in that case.

Otherwise we have to limit these new GUI features to 2.6 which would require a new branch in the GUI and some changes to the build process.

In some sense this is a "bug fix" though the fix itself is a band-aid as opposed to implementing a command queue to save these write actions instead of dropping them.

Selva

author
#4 lore raw

Re: [Openvpn-devel] [PATCH applied] Re: Allow a few levels of recursion in virtual_output_callback()

In case this request was lost, here goes again. Can we have this cherry-picked into 2.5 before the next release?

Selva

Quoted 36 lines · Selva Nair

Hi,

Quoted 6 lines · Gert Doering

I cannot test this (beyond "compile", but that is trivial) but the description in

Quoted 8 lines

https://www.mail-archive.com/[email protected]/msg24738.html

makes sense, so allowing "a limited amount" of recursion plus actually logging when this is hit should make management more robust against overlapping timing issues aka "race conditions".

Your patch has been applied to the master branch.

Can we also apply this to 2.5? I see this trigerred easily with the new persistent connection / PLAP support. I haven't figured the exact reason but hitting reconnect or disconnect at certain instances triggers this -- like when the connection is almost complete and the daemon is doing slow-ish netsh commands. The same code-path is not traversed when interactive service is in use and it seems hitting the "race condition" is much harder in that case.

Otherwise we have to limit these new GUI features to 2.6 which would require a new branch in the GUI and some changes to the build process.

In some sense this is a "bug fix" though the fix itself is a band-aid as opposed to implementing a command queue to save these write actions instead of dropping them.

Selva

#5 lore raw

Re: [Openvpn-devel] [PATCH applied] Re: Allow a few levels of recursion in virtual_output_callback()

Hi,

Quoted 2 lines · Selva Nair

In case this request was lost, here goes again. Can we have this cherry-picked into 2.5 before the next release?

Oops. It got lost, was rediscovered last week, and got lost again.

Sorry, and thanks for the reminder.

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]...
#6 lore raw

Re: [Openvpn-devel] [PATCH applied] Re: Allow a few levels of recursion in virtual_output_callback()

In reply to Gert Doering

Hi,

Quoted 3 lines · Gert Doering

Your patch has been applied to the master branch.

commit 4dfd592ff1ee18aa4859264c8a341dfa1a291988

... and after some reminding, to release/2.5 as well.

commit 468f53ae3bfcfca6563acbf648e7a0bc6f94b038 (HEAD -> release/2.5)

Author: Selva Nair <[email protected]...>
Date:   Wed Jul 27 23:45:08 2022 -0400

Allow a few levels of recursion in virtual_output_callback()
...

    (cherry picked from commit 4dfd592ff1ee18aa4859264c8a341dfa1a291988)

Since this code is virtually unchanged "since ever", it cherrypicked smoothly, diff looks good, and a small client-side test run worked just fine (same caveat as for the "master" patch, I have nothing which triggers this problem today).

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]...