]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: mech - Add MECH_SEC_ALLOW_NULS flag
authorAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 6 May 2020 10:07:01 +0000 (13:07 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Mon, 11 May 2020 08:44:04 +0000 (11:44 +0300)
Prevent embedded NULs for any mechs that do not have this flag

12 files changed:
src/auth/auth-request.c
src/auth/mech-anonymous.c
src/auth/mech-apop.c
src/auth/mech-dovecot-token.c
src/auth/mech-gssapi.c
src/auth/mech-ntlm.c
src/auth/mech-otp.c
src/auth/mech-plain.c
src/auth/mech-rpa.c
src/auth/mech-winbind.c
src/auth/mech.c
src/lib-auth/auth-client-interface.h

index 8420c84329fdf7917fd6cdc2be6c31208a4928f2..a1fa51d412f267f082a212925e34f0b5151bc91d 100644 (file)
@@ -635,6 +635,11 @@ void auth_request_initial(struct auth_request *request)
        i_assert(request->state == AUTH_REQUEST_STATE_NEW);
 
        auth_request_set_state(request, AUTH_REQUEST_STATE_MECH_CONTINUE);
+
+       if (auth_request_fail_on_nuls(request, request->initial_response,
+                                     request->initial_response_len))
+               return;
+
        request->mech->auth_initial(request, request->initial_response,
                                    request->initial_response_len);
 }
@@ -649,6 +654,9 @@ void auth_request_continue(struct auth_request *request,
                return;
        }
 
+       if (auth_request_fail_on_nuls(request, data, data_size))
+               return;
+
        auth_request_refresh_last_access(request);
        request->mech->auth_continue(request, data, data_size);
 }
index 05b89236a6cb443233618af30ccbe58adfe143bf..8c1ca21d2fcca9b3fd659486e5819e684fff1dbd 100644 (file)
@@ -38,7 +38,7 @@ static struct auth_request *mech_anonymous_auth_new(void)
 const struct mech_module mech_anonymous = {
        "ANONYMOUS",
 
-       .flags = MECH_SEC_ANONYMOUS,
+       .flags = MECH_SEC_ANONYMOUS | MECH_SEC_ALLOW_NULS,
        .passdb_need = MECH_PASSDB_NEED_NOTHING,
 
        mech_anonymous_auth_new,
index 86533db083420d53bdd1adbfd59fafeb8f803f3c..f28171fba80b6b807470cd8aab747a697c9b92f3 100644 (file)
@@ -162,7 +162,8 @@ static struct auth_request *mech_apop_auth_new(void)
 const struct mech_module mech_apop = {
        "APOP",
 
-       .flags = MECH_SEC_PRIVATE | MECH_SEC_DICTIONARY | MECH_SEC_ACTIVE,
+       .flags = MECH_SEC_PRIVATE | MECH_SEC_DICTIONARY | MECH_SEC_ACTIVE |
+                MECH_SEC_ALLOW_NULS,
        .passdb_need = MECH_PASSDB_NEED_VERIFY_RESPONSE,
 
        mech_apop_auth_new,
index 9b70a4e9186acd8da0ffda84e5ae0451064f62b8..9813a967240de3659641b6225c73111a410ff335 100644 (file)
@@ -81,7 +81,7 @@ static struct auth_request *mech_dovecot_token_auth_new(void)
 const struct mech_module mech_dovecot_token = {
        "DOVECOT-TOKEN",
 
-       .flags = MECH_SEC_PRIVATE,
+       .flags = MECH_SEC_PRIVATE | MECH_SEC_ALLOW_NULS,
        .passdb_need = MECH_PASSDB_NEED_NOTHING,
 
        mech_dovecot_token_auth_new,
index d6b199cb3bbc31d6116a8a0636ec1011a0a4858d..f29e48da8810bd1be84da9aeb05cb7d4c113bf93 100644 (file)
@@ -750,7 +750,7 @@ const struct mech_module mech_gssapi = {
 const struct mech_module mech_gssapi_spnego = {
        "GSS-SPNEGO",
 
-       .flags = 0,
+       .flags = MECH_SEC_ALLOW_NULS,
        .passdb_need = MECH_PASSDB_NEED_NOTHING,
 
        mech_gssapi_auth_new,
index 43afd896f975a73d1d6eb1f2a217f43f2c60c53b..f782999c6b5b28130d6ca1382d7a7b752d88d7d6 100644 (file)
@@ -249,7 +249,8 @@ static struct auth_request *mech_ntlm_auth_new(void)
 const struct mech_module mech_ntlm = {
        "NTLM",
 
-       .flags = MECH_SEC_DICTIONARY | MECH_SEC_ACTIVE,
+       .flags = MECH_SEC_DICTIONARY | MECH_SEC_ACTIVE |
+                MECH_SEC_ALLOW_NULS,
        .passdb_need = MECH_PASSDB_NEED_LOOKUP_CREDENTIALS,
 
        mech_ntlm_auth_new,
index 0d4a51bdef61e87c71b6a4a3671f0cd020f03044..16aec961eb7671e415ea4321daed1f59441b2ff1 100644 (file)
@@ -256,7 +256,7 @@ static struct auth_request *mech_otp_auth_new(void)
 const struct mech_module mech_otp = {
        "OTP",
 
-       .flags = MECH_SEC_DICTIONARY | MECH_SEC_ACTIVE,
+       .flags = MECH_SEC_DICTIONARY | MECH_SEC_ACTIVE | MECH_SEC_ALLOW_NULS,
        .passdb_need = MECH_PASSDB_NEED_SET_CREDENTIALS,
 
        mech_otp_auth_new,
index 1e21e7e3267af425bf2f483f9be169edad9e4377..444b0ff4b897b2926209a417c2920cc3ad3e209c 100644 (file)
@@ -78,7 +78,7 @@ static struct auth_request *mech_plain_auth_new(void)
 const struct mech_module mech_plain = {
        "PLAIN",
 
-       .flags = MECH_SEC_PLAINTEXT,
+       .flags = MECH_SEC_PLAINTEXT | MECH_SEC_ALLOW_NULS,
        .passdb_need = MECH_PASSDB_NEED_VERIFY_PLAIN,
 
        mech_plain_auth_new,
index 94fca52ec0e1ff53aef311352fa6bd46679fbb6f..08298ebdd68b6cdc3b1806910315d7bcb03feded 100644 (file)
@@ -580,7 +580,7 @@ const struct mech_module mech_rpa = {
        "RPA",
 
        .flags = MECH_SEC_DICTIONARY | MECH_SEC_ACTIVE |
-               MECH_SEC_MUTUAL_AUTH,
+               MECH_SEC_MUTUAL_AUTH | MECH_SEC_ALLOW_NULS,
        .passdb_need = MECH_PASSDB_NEED_LOOKUP_CREDENTIALS,
 
        mech_rpa_auth_new,
index 6be16e79c35ddb1fa4f004c3311f4db61ffb382f..1710116d7dfada2b06f89f91deee264fce091e34 100644 (file)
@@ -339,7 +339,8 @@ static struct auth_request *mech_winbind_spnego_auth_new(void)
 const struct mech_module mech_winbind_ntlm = {
        "NTLM",
 
-       .flags = MECH_SEC_DICTIONARY | MECH_SEC_ACTIVE,
+       .flags = MECH_SEC_DICTIONARY | MECH_SEC_ACTIVE |
+                MECH_SEC_ALLOW_NULS,
        .passdb_need = MECH_PASSDB_NEED_NOTHING,
 
        mech_winbind_ntlm_auth_new,
index 77c9f437c244165af45b595995bef413d6b44b43..8f4d8a64642ea244923c50be72f1169bfc0921d1 100644 (file)
@@ -68,6 +68,8 @@ void mech_generic_auth_free(struct auth_request *request)
 bool auth_request_fail_on_nuls(struct auth_request *request,
                               const unsigned char *data, size_t data_size)
 {
+       if ((request->mech->flags & MECH_SEC_ALLOW_NULS) != 0)
+               return FALSE;
        if (memchr(data, '\0', data_size) != NULL) {
                e_debug(request->mech_event, "Unexpected NUL in auth data");
                auth_request_fail(request);
index cdccbee38bcb0487bd6a679f6388de3348e5367e..2367a00a203f0caada80b4ecec416ec48f8b2a75 100644 (file)
@@ -23,7 +23,9 @@ enum mech_security_flags {
        /* Provides forward secrecy between sessions */
        MECH_SEC_FORWARD_SECRECY        = 0x0020,
        /* Provides mutual authentication */
-       MECH_SEC_MUTUAL_AUTH            = 0x0040
+       MECH_SEC_MUTUAL_AUTH            = 0x0040,
+       /* Allow NULs in input data */
+       MECH_SEC_ALLOW_NULS             = 0x0080,
 };
 
 /* auth failure codes */