Attention is currently required from: Arne Schwabe.
Hello Arne Schwabe,
I'd like you to do a code review.
Please visit
https://gerrit.openvpn.net/c/openvpn/+/2375?usp=email
to review the following change.
Change subject: auth-pam: don't truncate long usernames and passwords
......................................................................
auth-pam: don't truncate long usernames and passwords
The background process read username, password and the static
challenge response into 128 byte buffers and silently cut longer
values. Long passwords failed, and for passwords of 127 characters or
more, any password with the same first 127 characters was accepted.
Size the buffers like USER_PASS_LEN in openvpn, and reject the
authentication if a received string still does not fit.
Change-Id: I8d2e7c12de329acc940facdcc95efe4682249f9c
Signed-off-by: Razvan Cojocaru <[email protected]>
---
M src/plugins/auth-pam/auth-pam.c
1 file changed, 34 insertions(+), 12 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/75/2375/1
diff --git a/src/plugins/auth-pam/auth-pam.c b/src/plugins/auth-pam/auth-pam.c
index 16fd2a1..821dae1 100644
--- a/src/plugins/auth-pam/auth-pam.c
+++ b/src/plugins/auth-pam/auth-pam.c
@@ -48,6 +48,7 @@
#include <signal.h>
#include <syslog.h>
#include <limits.h>
+#include <stdbool.h>
#include "utils.h"
#include <arpa/inet.h>
#include <openvpn-plugin.h>
@@ -100,6 +101,9 @@
#define N_NAME_VALUE 16
+/* max. length of username/password in openvpn, including the NUL */
+#define USER_PASS_LEN 4096
+
struct name_value
{
const char *name;
@@ -120,10 +124,10 @@
{
int verb;
- char username[128];
- char password[128];
+ char username[USER_PASS_LEN];
+ char password[USER_PASS_LEN];
char common_name[128];
- char response[128];
+ char response[USER_PASS_LEN];
char remote[INET6_ADDRSTRLEN];
const struct name_value_list *name_value_list;
@@ -169,16 +173,24 @@
}
}
+/*
+ * Receive a string sent by send_string(). *truncated is set if it did not
+ * fit into buffer. It is cut off and terminated in that case.
+ */
static ssize_t
-recv_string(int fd, char *buffer, size_t len)
+recv_string(int fd, char *buffer, size_t len, bool *truncated)
{
if (len > 0)
{
memset(buffer, 0, len);
ssize_t size = read(fd, buffer, len);
- buffer[len - 1] = 0;
if (size >= 1)
{
+ if (buffer[size - 1] != '\0')
+ {
+ buffer[len - 1] = '\0';
+ *truncated = true;
+ }
return size;
}
}
@@ -993,11 +1005,13 @@
switch (command)
{
case COMMAND_VERIFY:
- if (recv_string(fd, up.username, sizeof(up.username)) == -1
- || recv_string(fd, up.password, sizeof(up.password)) == -1
- || recv_string(fd, up.common_name, sizeof(up.common_name))
== -1
- || recv_string(fd, ac_file_name, sizeof(ac_file_name)) ==
-1
- || recv_string(fd, up.remote, sizeof(up.remote)) == -1)
+ {
+ bool truncated = false;
+ if (recv_string(fd, up.username, sizeof(up.username),
&truncated) == -1
+ || recv_string(fd, up.password, sizeof(up.password),
&truncated) == -1
+ || recv_string(fd, up.common_name, sizeof(up.common_name),
&truncated) == -1
+ || recv_string(fd, ac_file_name, sizeof(ac_file_name),
&truncated) == -1
+ || recv_string(fd, up.remote, sizeof(up.remote),
&truncated) == -1)
{
plugin_log(PLOG_ERR | PLOG_ERRNO, MODULE,
"BACKGROUND: read error on command channel:
code=%d, exiting",
@@ -1016,12 +1030,19 @@
#endif
}
+ if (truncated)
+ {
+ plugin_log(PLOG_ERR, MODULE,
+ "BACKGROUND: user '%s': auth data too long,
rejecting",
+ up.username);
+ }
+
/* If password is of the form SCRV1:base64:base64 split it up
*/
split_scrv1_password(&up);
/* client wants deferred auth
*/
- if (strlen(ac_file_name) > 0)
+ if (!truncated && strlen(ac_file_name) > 0)
{
do_deferred_pam_auth(fd, ac_file_name, service, &up);
break;
@@ -1031,7 +1052,7 @@
/* non-deferred auth: wait for pam result and send
* result back via control socketpair
*/
- if (pam_auth(service, &up)) /* Succeeded */
+ if (!truncated && pam_auth(service, &up)) /* Succeeded */
{
if (send_control(fd, RESPONSE_VERIFY_SUCCEEDED) == -1)
{
@@ -1051,6 +1072,7 @@
}
plugin_secure_memzero(up.password, sizeof(up.password));
break;
+ }
case COMMAND_EXIT:
goto done;
--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2375?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8d2e7c12de329acc940facdcc95efe4682249f9c
Gerrit-Change-Number: 2375
Gerrit-PatchSet: 1
Gerrit-Owner: Răzvan Cojocaru <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: Arne Schwabe <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel