Skip to contentSkip to conversation

Disable multiple deferred authentication plug-ins

PATCH Superseded David Sommerseth 3 participants 9 messages Mar 13, 2022 – Mar 15, 2022

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover Disable multiple deferred authentication plug-ins

From: David Sommerseth <[email protected]...>

This is an adopted version of [0] for the OpenVPN 2.4 release branch.

It was discovered an issue with OpenVPN 2.x when multiple --plugin modules were loaded and more than one of them used deferred authentication. To fix this properly will require a larger refactoring of the plug-in code, so it was decided in the mean time to disable the possibility to run an OpenVPN server with such a setup. This issue affects the OpenVPN server mode only.

This patch set adds a new test plug-in and adds some test documentation on how to test various combinations of authentication plug-ins. Since this new plug-in (multi-auth.c) is fairly close to the simple.c plug-in, just more flexible for test setups, we remove the old one. The fix itself is isolated in a separate patch in this set.

The order of patches are insignificant; there are no inter-dependencies between them.

[0] <https://www.mail-archive.com/[email protected]/msg23934.html>

    Message-ID: <[email protected]...>

--
kind regards,

David Sommerseth
OpenVPN Inc

David Sommerseth (3):
sample-plugin: New plugin for testing multiple auth plugins
plug-ins: Disallow multiple deferred authentication plug-ins
plug-ins: Remove defer/simple.c sample plugin

 doc/openvpn.8                            |  13 +
 doc/tests/authentication-plugins.md      | 153 +++++++
 sample/sample-plugins/defer/README       |   9 +-
 sample/sample-plugins/defer/multi-auth.c | 413 +++++++++++++++++
 sample/sample-plugins/defer/simple.c     | 541 -----------------------
 sample/sample-plugins/defer/simple.def   |   6 -
 src/openvpn/plugin.c                     |  33 +-
 7 files changed, 616 insertions(+), 552 deletions(-)
 create mode 100644 doc/tests/authentication-plugins.md
 create mode 100644 sample/sample-plugins/defer/multi-auth.c
 delete mode 100644 sample/sample-plugins/defer/simple.c
 delete mode 100755 sample/sample-plugins/defer/simple.def
Signature · 1 line
2.27.0
#1 lore raw

PATCH v4 1/3 sample-plugin: New plugin for testing multiple auth plugins

From: David Sommerseth <[email protected]...>

This plugin allows setting username/passwords as well as configure deferred authentication behaviour as part of the runtime initialization.

With this plug-in it is easier to test various scenarios where multiple authentication plug-ins are active on the server side.

A test documentation was also added to describe various test cases and the expected results.

---
v3 - Flipped NULL==var/NULL!=var to (var)/(!var) in if() block

---
 doc/tests/authentication-plugins.md      | 153 +++++++++
 sample/sample-plugins/defer/README       |   8 +
 sample/sample-plugins/defer/multi-auth.c | 413 +++++++++++++++++++++++
 3 files changed, 574 insertions(+)
 create mode 100644 doc/tests/authentication-plugins.md
 create mode 100644 sample/sample-plugins/defer/multi-auth.c
doc/tests/authentication-plugins.md new file +153 -0
new file mode 100644
index 00000000..1f5fb851
@@ -0,0 +1,153 @@
+# TESTING OF MULTIPLE AUTHENTICATION PLUG-INS
+
+
+OpenVPN 2.x can support loading and authenticating users through multiple
+plug-ins at the same time.  But it can only support a single plug-in doing
+deferred authentication.  However, a plug-in supporting deferred
+authentication may be accompanied by other authentication plug-ins **not**
+doing deferred authentication.
+
+This is a test script useful to test the various combinations and order of
+plug-in execution.
+
+The configuration files are expected to be used from the root of the build
+directory.
+
+To build the needed authentication plug-in, run:
+
+     make -C sample/sample-plugins
+
+
+## Test configs
+
+* Client config
+
+      verb 4
+      dev tun
+      client
+      remote x.x.x.x
+      ca sample/sample-keys/ca.crt
+      cert sample/sample-keys/client.crt
+      key sample/sample-keys/client.key
+      auth-user-pass
+
+* Base server config (`base-server.conf`)
+
+      verb 4
+      dev tun
+      server 10.8.0.0 255.255.255.0
+      dh sample/sample-keys/dh2048.pem
+      ca sample/sample-keys/ca.crt
+      cert sample/sample-keys/server.crt
+      key sample/sample-keys/server.key
+
+
+## Test cases
+
+### Test: *sanity-1*
+
+This tests the basic authentication with an instant answer.
+
+     config base-server.conf
+     plugin multi-auth.so S1.1 0 foo bar
+
+#### Expected results
+ - Username/password `foo`/`bar`: **PASS**
+ - Anything else: **FAIL**
+
+
+### Test: *sanity-2*
+
+This is similar to `sanity-1`, but does the authentication
+through two plug-ins providing an instant reply.
+
+     config base-server.conf
+     plugin multi-auth.so S2.1 0 foo bar
+     plugin multi-auth.so S2.2 0 foo bar
+
+#### Expected results
+ - Username/password `foo`/`bar`: **PASS**
+ - Anything else: **FAIL**
+
+
+### Test: *sanity-3*
+
+This is also similar to `sanity-1`, but uses deferred authentication
+with a 1 second delay on the response.
+
+     plugin multi-auth.so S3.1 1000 foo bar
+
+#### Expected results
+ - Username/password `foo`/`bar`: **PASS**
+ - Anything else: **FAIL**
+
+
+### Test: *case-a*
+
+Runs two authentications, the first one deferred by 1 second and the
+second one providing an instant response.
+
+     plugin multi-auth.so A.1 1000 foo bar
+     plugin multi-auth.so A.2 0 foo bar
+
+#### Expected results
+ - Username/password `foo`/`bar`: **PASS**
+ - Anything else: **FAIL**
+
+
+### Test: *case-b*
+
+This is similar to `case-a`, but the instant authentication response
+is provided first before the deferred authentication.
+
+     plugin multi-auth.so B.1 0 foo bar
+     plugin multi-auth.so B.2 1000 test pass
+
+#### Expected results
+ - **Always FAIL**
+ - This test should never pass, as each plug-in expects different
+   usernames and passwords.
+
+
+### Test: *case-c*
+
+This is similar to the two prior tests, but the authentication result
+is returned instantly in both steps.
+
+     plugin multi-auth.so C.1 0 foo bar
+     plugin multi-auth.so C.2 0 foo2 bar2
+
+#### Expected results
+ - **Always FAIL**
+ - This test should never pass, as each plug-in expects different
+   usernames and passwords.
+
+
+### Test: *case-d*
+
+This is similar to the `case-b` test, but the order of deferred
+and instant response is reversed.
+
+    plugin ./multi-auth.so D.1 2000 test pass
+    plugin ./multi-auth.so D.2 0 foo bar
+
+#### Expected results
+ - **Always FAIL**
+ - This test should never pass, as each plug-in expects different
+   usernames and passwords.
+
+
+### Test: *case-e*
+
+This test case will run two deferred authentication plug-ins.  This is
+**not** supported by OpenVPN, and should therefore fail instantly.
+
+    plugin ./multi-auth.so E1 1000 test1 pass1
+    plugin ./multi-auth.so E2 2000 test2 pass2
+
+#### Expected results
+ - The OpenVPN server process should stop running
+ - An error about multiple deferred plug-ins being configured
+   should be seen in the server log.
+
+
sample/sample-plugins/defer/README +8 -0
index d8990f8b..4c032993 100644
@@ -5,12 +5,20 @@ Examples provided:
 simple.c -- using the --auth-user-pass-verify callback,
             test deferred authentication.
 
+multi-auth.c -- Test plug-in for testing multiple authentication
+                plug-ins in the same OpenVPN server configuration.
+                Only tested on Linux.
+
 To build:
 
   ./build simple (Linux/BSD/etc.)
+  ./build multi-auth (Linux/BSD/etc.)
   ./winbuild simple (MinGW on Windows)
 
 To use in OpenVPN, add to config file:
 
   plugin simple.so (Linux/BSD/etc.)
   plugin simple.dll (MinGW on Windows)
+
+For the multi-auth.so, see the documentation in
+doc/tests/authentication-plugins.md
sample/sample-plugins/defer/multi-auth.c new file +413 -0

413 lines not on this page · raw message

Signature · 1 line
2.27.0
Acked-by on v4 1/3
#2 lore raw

Re: [Openvpn-devel] [PATCH v2.4 v4 1/3] sample-plugin: New plugin for testing multiple auth plugins

Hi,

Quoted 5 lines · David Sommerseth

From: David Sommerseth <[email protected]...>

This plugin allows setting username/passwords as well as configure deferred authentication behaviour as part of the runtime initialization.

Quoted 7 lines

With this plug-in it is easier to test various scenarios where multiple authentication plug-ins are active on the server side.

A test documentation was also added to describe various test cases and the expected results.

Tested and it greatly helps understanding various auth plugin combinations behaviours.

Signature · 1 line
Antonio Quartulli
#3 lore raw

Re: [Openvpn-devel] [PATCH v2.4 v4 1/3] sample-plugin: New plugin for testing multiple auth plugins

In reply to David Sommerseth

Hi,

Quoted 5 lines · David Sommerseth

From: David Sommerseth <[email protected]...>

This plugin allows setting username/passwords as well as configure deferred authentication behaviour as part of the runtime initialization.

Quoted 7 lines

With this plug-in it is easier to test various scenarios where multiple authentication plug-ins are active on the server side.

A test documentation was also added to describe various test cases and the expected results.

Well, not sure if we really want this new plugin in 2.4, but if we want this, we need a v5 of this patch with correct build instructions for 2.4 - as it is, it does not build (there is no Makefile in "sample/sample-plugins", and "build" does not set proper -I, so "config.h" cannot be found).

Thus, NAK.

Focusing on "only the CVE patch" for now.

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

PATCH v4 2/3 plug-ins: Disallow multiple deferred authentication plug-ins

In reply to David Sommerseth

From: David Sommerseth <[email protected]...>

The plug-in API in OpenVPN 2.x is not designed for running multiple deferred authentication processes in parallel. The authentication results of such configurations are not to be trusted. For now we bail out when this discovered with an error in the log.

CVE: 2022-0547

---
Note: The man page snippet is copied from the generated nroff formatting from the git master generated man page.

v3 - flip CONSTANT==var to var==CONSTANT in if() clause v4 - Use M_FATAL instead of M_ERR

---
 doc/openvpn.8        | 13 +++++++++++++
 src/openvpn/plugin.c | 33 ++++++++++++++++++++++++++++++---
 2 files changed, 43 insertions(+), 3 deletions(-)
doc/openvpn.8 +13 -0
index 598d5fce..a6a5feb6 100644
@@ -2805,6 +2805,19 @@ function (such as tls\-verify, auth\-user\-pass\-verify, or
 client\-connect), then
 every module and script must return success (0) in order for
 the connection to be authenticated.
+
+.INDENT 7.0
+.TP
+.B \fBWARNING\fP:
+Plug\-ins may do deferred execution, meaning the plug\-in will
+return the control back to the main OpenVPN process and provide
+the plug\-in result later on via a different thread or process.
+OpenVPN does \fBNOT\fP support multiple authentication plug\-ins
+\fBwhere more than one of them\fP do deferred authentication.
+If this behaviour is detected, OpenVPN will shut down upon first
+authentication.
+.UNINDENT
+.UNINDENT
 .\"*********************************************************
 .TP
 .B \-\-keying\-material\-exporter label len
src/openvpn/plugin.c +30 -3
index 0ab99ab5..76d1b2e5 100644
@@ -809,7 +809,7 @@ plugin_call_ssl(const struct plugin_list *pl,
         const int n = plugin_n(pl);
         bool success = false;
         bool error = false;
-        bool deferred = false;
+        bool deferred_auth_done = false;
 
         setenv_del(es, "script_type");
         envp = make_env_array(es, false, &gc);
@@ -834,7 +834,34 @@ plugin_call_ssl(const struct plugin_list *pl,
                     break;
 
                 case OPENVPN_PLUGIN_FUNC_DEFERRED:
-                    deferred = true;
+                    if ((type == OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY
+                        && deferred_auth_done)
+                    {
+                        /*
+                         * Do not allow deferred auth if a deferred auth has
+                         * already been started.  This should allow a single
+                         * deferred auth call to happen, with one or more
+                         * auth calls with an instant authentication result.
+                         *
+                         * The plug-in API is not designed for multiple
+                         * deferred authentications to happen, as the
+                         * auth_control_file file will be shared across all
+                         * the plug-ins.
+                         *
+                         * Since this is considered a critical configuration
+                         * error, we bail out and exit the OpenVPN process.
+                         */
+                        error = true;
+                        msg(M_FATAL,
+                            "Exiting due to multiple authentication plug-ins "
+                            "performing deferred authentication. Only one "
+                            "authentication plug-in doing deferred auth is "
+                            "allowed.  Ignoring the result and stopping now, "
+                            "the current authentication result is not to be "
+                            "trusted.");
+                        break;
+                    }
+                    deferred_auth_done = true;
                     break;
 
                 default:
@@ -858,7 +885,7 @@ plugin_call_ssl(const struct plugin_list *pl,
         {
             return OPENVPN_PLUGIN_FUNC_ERROR;
         }
-        else if (deferred)
+        else if (deferred_auth_done)
         {
             return OPENVPN_PLUGIN_FUNC_DEFERRED;
         }
Signature · 1 line
2.27.0
Acked-by on v4 2/3
#5 lore raw

Re: [Openvpn-devel] [PATCH v2.4 v4 2/3] plug-ins: Disallow multiple deferred authentication plug-ins

Hi,

Quoted 9 lines · David Sommerseth

From: David Sommerseth <[email protected]...>

The plug-in API in OpenVPN 2.x is not designed for running multiple deferred authentication processes in parallel. The authentication results of such configurations are not to be trusted. For now we bail out when this discovered with an error in the log.

CVE: 2022-0547

Tested and it does what it says on the lid.
The whole approach requires larger refactoring, but for now this is enough to close the hole.

Signature · 1 line
Antonio Quartulli
#6 lore raw

Re: [Openvpn-devel] [PATCH v2.4 v4 2/3] plug-ins: Disallow multiple deferred authentication plug-ins

In reply to David Sommerseth

Hi,

src/openvpn/plugin.c plugin_call_ssl(const struct plugin_list *pl, · line 839

Quoted 5 lines · David Sommerseth

case OPENVPN_PLUGIN_FUNC_DEFERRED:

src/openvpn/plugin.c +3 -1
-                    deferred = true;
+                    if ((type == OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY
+                        && deferred_auth_done)
+                    {

As discussed on IRC, a fat finger sneaked into this and stole a bracket.

So, formally, NAK, as I won't change code, except in emergencies (which this isn't)

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

PATCH v4 3/3 plug-ins: Remove defer/simple.c sample plugin

In reply to David Sommerseth

From: David Sommerseth <[email protected]...>

The use case for this plug-in is dubious now with the new multi-auth.c plugin available. This new plugin is based on simple.c, but allows far more flexibility for testing.

---
 sample/sample-plugins/defer/README     |   3 -
 sample/sample-plugins/defer/simple.c   | 541 -------------------------
 sample/sample-plugins/defer/simple.def |   6 -
 3 files changed, 550 deletions(-)
 delete mode 100644 sample/sample-plugins/defer/simple.c
 delete mode 100755 sample/sample-plugins/defer/simple.def
sample/sample-plugins/defer/README +0 -3
index 4c032993..b20f4eea 100644
@@ -2,9 +2,6 @@ OpenVPN plugin examples.
 
 Examples provided:
 
-simple.c -- using the --auth-user-pass-verify callback,
-            test deferred authentication.
-
 multi-auth.c -- Test plug-in for testing multiple authentication
                 plug-ins in the same OpenVPN server configuration.
                 Only tested on Linux.
sample/sample-plugins/defer/simple.c deleted +0 -541

541 lines not on this page · raw message

sample/sample-plugins/defer/simple.def deleted +0 -6
deleted file mode 100755
index a87507d1..00000000
@@ -1,6 +0,0 @@
-LIBRARY   OpenVPN_PLUGIN_SAMPLE
-DESCRIPTION "Sample OpenVPN plug-in module."
-EXPORTS
-   openvpn_plugin_open_v1   @1
-   openvpn_plugin_func_v1   @2
-   openvpn_plugin_close_v1  @3
Signature · 1 line
2.27.0
Acked-by on v4 3/3
#8 lore raw

Re: [Openvpn-devel] [PATCH v2.4 v4 3/3] plug-ins: Remove defer/simple.c sample plugin

Hi,

Quoted 7 lines · David Sommerseth

From: David Sommerseth <[email protected]...>

The use case for this plug-in is dubious now with the new multi-auth.c plugin available. This new plugin is based on simple.c, but allows far more flexibility for testing.

Does nothing more than removing the simple auth plugin (superseded by the plugin in 1/2)

Signature · 1 line
Antonio Quartulli