|
|
9ae3f9 |
From 5e231ceb35bb763d6fafc7c3efe1c3c582929cc2 Mon Sep 17 00:00:00 2001
|
|
|
9ae3f9 |
From: Xavi Hernandez <xhernandez@redhat.com>
|
|
|
9ae3f9 |
Date: Tue, 14 Jan 2020 13:28:47 +0100
|
|
|
9ae3f9 |
Subject: [PATCH 417/449] events: fix IPv6 memory corruption
|
|
|
9ae3f9 |
|
|
|
9ae3f9 |
When an event was generated and the target host was resolved to an IPv6
|
|
|
9ae3f9 |
address, there was a memory overflow when that address was copied to a
|
|
|
9ae3f9 |
fixed IPv4 structure (IPv6 addresses are longer than IPv4 ones).
|
|
|
9ae3f9 |
|
|
|
9ae3f9 |
This fix correctly handles IPv4 and IPv6 addresses returned by
|
|
|
9ae3f9 |
getaddrinfo()
|
|
|
9ae3f9 |
|
|
|
9ae3f9 |
Backport of:
|
|
|
9ae3f9 |
> Upstream-patch-link: https://review.gluster.org/24014
|
|
|
9ae3f9 |
> Change-Id: I5864a0c6e6f1b405bd85988529570140cf23b250
|
|
|
9ae3f9 |
> Fixes: bz#1790870
|
|
|
9ae3f9 |
> Signed-off-by: Xavi Hernandez <xhernandez@redhat.com>
|
|
|
9ae3f9 |
|
|
|
9ae3f9 |
BUG: 1792873
|
|
|
9ae3f9 |
Change-Id: I5864a0c6e6f1b405bd85988529570140cf23b250
|
|
|
9ae3f9 |
Signed-off-by: Xavi Hernandez <xhernandez@redhat.com>
|
|
|
9ae3f9 |
Reviewed-on: https://code.engineering.redhat.com/gerrit/202486
|
|
|
9ae3f9 |
Tested-by: RHGS Build Bot <nigelb@redhat.com>
|
|
|
9ae3f9 |
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
|
|
|
9ae3f9 |
---
|
|
|
9ae3f9 |
libglusterfs/src/events.c | 56 +++++++++++++----------------------------------
|
|
|
9ae3f9 |
1 file changed, 15 insertions(+), 41 deletions(-)
|
|
|
9ae3f9 |
|
|
|
9ae3f9 |
diff --git a/libglusterfs/src/events.c b/libglusterfs/src/events.c
|
|
|
9ae3f9 |
index 4e2f8f9..6d1e383 100644
|
|
|
9ae3f9 |
--- a/libglusterfs/src/events.c
|
|
|
9ae3f9 |
+++ b/libglusterfs/src/events.c
|
|
|
9ae3f9 |
@@ -34,7 +34,6 @@ _gf_event(eventtypes_t event, const char *fmt, ...)
|
|
|
9ae3f9 |
int ret = 0;
|
|
|
9ae3f9 |
int sock = -1;
|
|
|
9ae3f9 |
char *eventstr = NULL;
|
|
|
9ae3f9 |
- struct sockaddr_in server;
|
|
|
9ae3f9 |
va_list arguments;
|
|
|
9ae3f9 |
char *msg = NULL;
|
|
|
9ae3f9 |
glusterfs_ctx_t *ctx = NULL;
|
|
|
9ae3f9 |
@@ -42,11 +41,10 @@ _gf_event(eventtypes_t event, const char *fmt, ...)
|
|
|
9ae3f9 |
struct addrinfo hints;
|
|
|
9ae3f9 |
struct addrinfo *result = NULL;
|
|
|
9ae3f9 |
xlator_t *this = THIS;
|
|
|
9ae3f9 |
- int sin_family = AF_INET;
|
|
|
9ae3f9 |
char *volfile_server_transport = NULL;
|
|
|
9ae3f9 |
|
|
|
9ae3f9 |
/* Global context */
|
|
|
9ae3f9 |
- ctx = THIS->ctx;
|
|
|
9ae3f9 |
+ ctx = this->ctx;
|
|
|
9ae3f9 |
|
|
|
9ae3f9 |
if (event < 0 || event >= EVENT_LAST) {
|
|
|
9ae3f9 |
ret = EVENT_ERROR_INVALID_INPUTS;
|
|
|
9ae3f9 |
@@ -60,48 +58,31 @@ _gf_event(eventtypes_t event, const char *fmt, ...)
|
|
|
9ae3f9 |
goto out;
|
|
|
9ae3f9 |
}
|
|
|
9ae3f9 |
|
|
|
9ae3f9 |
- memset(&hints, 0, sizeof(hints));
|
|
|
9ae3f9 |
- hints.ai_family = AF_UNSPEC;
|
|
|
9ae3f9 |
-
|
|
|
9ae3f9 |
if (ctx) {
|
|
|
9ae3f9 |
volfile_server_transport = ctx->cmd_args.volfile_server_transport;
|
|
|
9ae3f9 |
}
|
|
|
9ae3f9 |
-
|
|
|
9ae3f9 |
if (!volfile_server_transport) {
|
|
|
9ae3f9 |
volfile_server_transport = "tcp";
|
|
|
9ae3f9 |
}
|
|
|
9ae3f9 |
- /* Get Host name to send message */
|
|
|
9ae3f9 |
+
|
|
|
9ae3f9 |
+ /* host = NULL returns localhost */
|
|
|
9ae3f9 |
+ host = NULL;
|
|
|
9ae3f9 |
if (ctx && ctx->cmd_args.volfile_server &&
|
|
|
9ae3f9 |
(strcmp(volfile_server_transport, "unix"))) {
|
|
|
9ae3f9 |
/* If it is client code then volfile_server is set
|
|
|
9ae3f9 |
use that information to push the events. */
|
|
|
9ae3f9 |
- if ((getaddrinfo(ctx->cmd_args.volfile_server, NULL, &hints,
|
|
|
9ae3f9 |
- &result)) != 0) {
|
|
|
9ae3f9 |
- ret = EVENT_ERROR_RESOLVE;
|
|
|
9ae3f9 |
- goto out;
|
|
|
9ae3f9 |
- }
|
|
|
9ae3f9 |
-
|
|
|
9ae3f9 |
- if (get_ip_from_addrinfo(result, &host) == NULL) {
|
|
|
9ae3f9 |
- ret = EVENT_ERROR_RESOLVE;
|
|
|
9ae3f9 |
- goto out;
|
|
|
9ae3f9 |
- }
|
|
|
9ae3f9 |
-
|
|
|
9ae3f9 |
- sin_family = result->ai_family;
|
|
|
9ae3f9 |
- } else {
|
|
|
9ae3f9 |
- /* Localhost, Use the defined IP for localhost */
|
|
|
9ae3f9 |
- host = gf_strdup(EVENT_HOST);
|
|
|
9ae3f9 |
+ host = ctx->cmd_args.volfile_server;
|
|
|
9ae3f9 |
}
|
|
|
9ae3f9 |
|
|
|
9ae3f9 |
- /* Socket Configurations */
|
|
|
9ae3f9 |
- server.sin_family = sin_family;
|
|
|
9ae3f9 |
- server.sin_port = htons(EVENT_PORT);
|
|
|
9ae3f9 |
- ret = inet_pton(server.sin_family, host, &server.sin_addr);
|
|
|
9ae3f9 |
- if (ret <= 0) {
|
|
|
9ae3f9 |
- gf_msg(this->name, GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG,
|
|
|
9ae3f9 |
- "inet_pton failed with return code %d", ret);
|
|
|
9ae3f9 |
+ memset(&hints, 0, sizeof(hints));
|
|
|
9ae3f9 |
+ hints.ai_family = AF_UNSPEC;
|
|
|
9ae3f9 |
+ hints.ai_socktype = SOCK_DGRAM;
|
|
|
9ae3f9 |
+ hints.ai_flags = AI_ADDRCONFIG;
|
|
|
9ae3f9 |
+
|
|
|
9ae3f9 |
+ if ((getaddrinfo(host, TOSTRING(EVENT_PORT), &hints, &result)) != 0) {
|
|
|
9ae3f9 |
+ ret = EVENT_ERROR_RESOLVE;
|
|
|
9ae3f9 |
goto out;
|
|
|
9ae3f9 |
}
|
|
|
9ae3f9 |
- memset(&server.sin_zero, '\0', sizeof(server.sin_zero));
|
|
|
9ae3f9 |
|
|
|
9ae3f9 |
va_start(arguments, fmt);
|
|
|
9ae3f9 |
ret = gf_vasprintf(&msg, fmt, arguments);
|
|
|
9ae3f9 |
@@ -113,15 +94,15 @@ _gf_event(eventtypes_t event, const char *fmt, ...)
|
|
|
9ae3f9 |
}
|
|
|
9ae3f9 |
|
|
|
9ae3f9 |
ret = gf_asprintf(&eventstr, "%u %d %s", (unsigned)time(NULL), event, msg);
|
|
|
9ae3f9 |
-
|
|
|
9ae3f9 |
+ GF_FREE(msg);
|
|
|
9ae3f9 |
if (ret <= 0) {
|
|
|
9ae3f9 |
ret = EVENT_ERROR_MSG_FORMAT;
|
|
|
9ae3f9 |
goto out;
|
|
|
9ae3f9 |
}
|
|
|
9ae3f9 |
|
|
|
9ae3f9 |
/* Send Message */
|
|
|
9ae3f9 |
- if (sendto(sock, eventstr, strlen(eventstr), 0, (struct sockaddr *)&server,
|
|
|
9ae3f9 |
- sizeof(server)) <= 0) {
|
|
|
9ae3f9 |
+ if (sendto(sock, eventstr, strlen(eventstr), 0, result->ai_addr,
|
|
|
9ae3f9 |
+ result->ai_addrlen) <= 0) {
|
|
|
9ae3f9 |
ret = EVENT_ERROR_SEND;
|
|
|
9ae3f9 |
goto out;
|
|
|
9ae3f9 |
}
|
|
|
9ae3f9 |
@@ -133,17 +114,10 @@ out:
|
|
|
9ae3f9 |
sys_close(sock);
|
|
|
9ae3f9 |
}
|
|
|
9ae3f9 |
|
|
|
9ae3f9 |
- /* Allocated by gf_vasprintf */
|
|
|
9ae3f9 |
- if (msg)
|
|
|
9ae3f9 |
- GF_FREE(msg);
|
|
|
9ae3f9 |
-
|
|
|
9ae3f9 |
/* Allocated by gf_asprintf */
|
|
|
9ae3f9 |
if (eventstr)
|
|
|
9ae3f9 |
GF_FREE(eventstr);
|
|
|
9ae3f9 |
|
|
|
9ae3f9 |
- if (host)
|
|
|
9ae3f9 |
- GF_FREE(host);
|
|
|
9ae3f9 |
-
|
|
|
9ae3f9 |
if (result)
|
|
|
9ae3f9 |
freeaddrinfo(result);
|
|
|
9ae3f9 |
|
|
|
9ae3f9 |
--
|
|
|
9ae3f9 |
1.8.3.1
|
|
|
9ae3f9 |
|