Updated to upstream version 1.2 plus latest fixes
resolves: RHEL-148557 Made sure that all removed patches are now part of the upstream version. Signed-off-by: Nils Koenig <nkoenig@redhat.com>
This commit is contained in:
parent
0dea5db92c
commit
963e9b440e
137
0001-Add-channel_path-setting-to-daemon-config-file.patch
Normal file
137
0001-Add-channel_path-setting-to-daemon-config-file.patch
Normal file
@ -0,0 +1,137 @@
|
||||
commit 5a04b59495490bf921c661ff95754ea9955e7cd4
|
||||
Author: Jim Fehlig <jfehlig@suse.com>
|
||||
Date: Fri Sep 27 09:20:52 2024 -0600
|
||||
|
||||
Add channel_path setting to daemon config file
|
||||
|
||||
libvirt commit 8abc979b moved the target path for channel devices.
|
||||
To accommodate libvirt deployments with and without that commit,
|
||||
allow specifying the path in the daemon configuration file.
|
||||
|
||||
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
|
||||
diff --git a/README b/README
|
||||
index 579acd5..2ff7e8b 100644
|
||||
--- a/README
|
||||
+++ b/README
|
||||
@@ -51,6 +51,7 @@ includes a few examples of user-defined metrics, which provide a
|
||||
<size unit="k">256</size>
|
||||
</disk>
|
||||
<virtio>
|
||||
+ <channel_path>/var/run/libvirt/qemu/channel</channel_path>
|
||||
<max_channels>1024</max_channels>
|
||||
<expiration_time>15</expiration_time>
|
||||
</virtio>
|
||||
@@ -300,6 +301,8 @@ between the host and VMs. Basically for a virtio serial device, QEMU creates
|
||||
- 'connects' both to a 'communication channel'
|
||||
|
||||
It can be configured in the virtio section of the vhostmd configuration file.
|
||||
+<channel_path> defines a path on the host where QEMU creates the unix domain
|
||||
+sockets.
|
||||
<max_channels> defines the maximum number of virtio channels/VMs supported
|
||||
by the vhostmd instance with a default value of 1024.
|
||||
<expiration_time> is the time after which the virtio serial channel of a VM
|
||||
diff --git a/include/virtio.h b/include/virtio.h
|
||||
index 1ff31a2..962adea 100644
|
||||
--- a/include/virtio.h
|
||||
+++ b/include/virtio.h
|
||||
@@ -24,7 +24,7 @@
|
||||
/*
|
||||
* Initialize virtio layer
|
||||
*/
|
||||
-int virtio_init(int max_channel, int expiration_period);
|
||||
+int virtio_init(char *channel_path, int max_channel, int expiration_period);
|
||||
|
||||
/*
|
||||
* Main virtio function
|
||||
diff --git a/vhostmd.dtd b/vhostmd.dtd
|
||||
index 6c159dd..045860d 100644
|
||||
--- a/vhostmd.dtd
|
||||
+++ b/vhostmd.dtd
|
||||
@@ -20,7 +20,8 @@ Virtual Host Metrics Daemon (vhostmd). Configuration file DTD
|
||||
<!ELEMENT update_period (#PCDATA)>
|
||||
<!ELEMENT transport (#PCDATA)>
|
||||
|
||||
-<!ELEMENT virtio (max_channels,expiration_time)>
|
||||
+<!ELEMENT virtio (channel_path,max_channels,expiration_time)>
|
||||
+<!ELEMENT channel_path (#PCDATA)>
|
||||
<!ELEMENT max_channels (#PCDATA)>
|
||||
<!ELEMENT expiration_time (#PCDATA)>
|
||||
|
||||
diff --git a/vhostmd.xml b/vhostmd.xml
|
||||
index 5c88d8c..0dff85d 100644
|
||||
--- a/vhostmd.xml
|
||||
+++ b/vhostmd.xml
|
||||
@@ -34,6 +34,7 @@ the logical && operator must be replaced with "&&".
|
||||
<size unit="k">256</size>
|
||||
</disk>
|
||||
<virtio>
|
||||
+ <channel_path>/var/run/libvirt/qemu/channel</channel_path>
|
||||
<max_channels>1024</max_channels>
|
||||
<expiration_time>15</expiration_time>
|
||||
</virtio>
|
||||
diff --git a/vhostmd/vhostmd.c b/vhostmd/vhostmd.c
|
||||
index 4426faf..88e89ac 100644
|
||||
--- a/vhostmd/vhostmd.c
|
||||
+++ b/vhostmd/vhostmd.c
|
||||
@@ -105,6 +105,7 @@ static mdisk_header md_header =
|
||||
};
|
||||
static char *search_path = NULL;
|
||||
static int transports = 0;
|
||||
+static char *virtio_channel_path = NULL;
|
||||
static int virtio_max_channels = 1024;
|
||||
static int virtio_expiration_time = 15;
|
||||
|
||||
@@ -623,7 +624,14 @@ static int parse_config_file(const char *filename)
|
||||
}
|
||||
|
||||
if (transports & VIRTIO) {
|
||||
- if (vu_xpath_long("string(./globals/virtio/max_channels[1])", ctxt, &l) == 0)
|
||||
+ virtio_channel_path = vu_xpath_string("string(./globals/virtio/channel_path[1])", ctxt);
|
||||
+ if (virtio_channel_path == NULL) {
|
||||
+ virtio_channel_path = strdup("/var/lib/libvirt/qemu/channel/target");
|
||||
+ if (virtio_channel_path == NULL)
|
||||
+ goto out;
|
||||
+ }
|
||||
+
|
||||
+ if (vu_xpath_long("string(./globals/virtio/max_channels[1])", ctxt, &l) == 0)
|
||||
virtio_max_channels = (int)l;
|
||||
|
||||
if (vu_xpath_long("string(./globals/virtio/expiration_time[1])", ctxt, &l) == 0)
|
||||
@@ -980,7 +988,7 @@ static int vhostmd_run(int diskfd)
|
||||
if (virtio_expiration_time < (update_period * 3))
|
||||
virtio_expiration_time = update_period * 3;
|
||||
|
||||
- if (virtio_init(virtio_max_channels, virtio_expiration_time)) {
|
||||
+ if (virtio_init(virtio_channel_path, virtio_max_channels, virtio_expiration_time)) {
|
||||
vu_buffer_delete(buf);
|
||||
return -1;
|
||||
}
|
||||
diff --git a/vhostmd/virtio.c b/vhostmd/virtio.c
|
||||
index 98340ce..d2d07bf 100644
|
||||
--- a/vhostmd/virtio.c
|
||||
+++ b/vhostmd/virtio.c
|
||||
@@ -68,7 +68,7 @@ static channel_t *channel = NULL;
|
||||
static id_map_t *id_map = NULL;
|
||||
static time_t exp_period = 0;
|
||||
|
||||
-static const char *channel_path = "/var/lib/libvirt/qemu/channel/target";
|
||||
+static const char *channel_path = NULL;
|
||||
static const char *channel_name = "org.github.vhostmd.1";
|
||||
static int channel_max = 0;
|
||||
static volatile int channel_count = 0;
|
||||
@@ -572,13 +572,14 @@ static void vio_handle_io(unsigned epoll_wait_ms)
|
||||
* Once the channel is added to epoll the vu_buffer can be accessed
|
||||
* by the epoll_event.data.ptr.
|
||||
*/
|
||||
-int virtio_init(int _max_channel, int _expiration_period)
|
||||
+int virtio_init(char *_channel_path, int _max_channel, int _expiration_period)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (virtio_status == VIRTIO_INIT) {
|
||||
pthread_mutex_init(&channel_mtx, NULL);
|
||||
|
||||
+ channel_path = _channel_path;
|
||||
channel_max = _max_channel;
|
||||
exp_period = _expiration_period;
|
||||
channel_count = 0;
|
||||
@ -1,42 +0,0 @@
|
||||
From 83cc269f6892852be94467cea771b3ad1da8a369 Mon Sep 17 00:00:00 2001
|
||||
From: Jim Fehlig <jfehlig@suse.com>
|
||||
Date: Tue, 8 Oct 2019 20:56:18 -0600
|
||||
Subject: [PATCH 01/19] Relax virtio requirement in config file
|
||||
|
||||
When the virtio transport was introduced the schema was changed to
|
||||
require a <virtio> transport in vhostmd.conf. When updating existing
|
||||
deployments without a virtio transport specified in vhostmd.conf,
|
||||
vhostmd fails to start
|
||||
|
||||
/usr/sbin/vhostmd -d
|
||||
/etc/vhostmd/vhostmd.conf:41: element globals: validity error : Element
|
||||
globals content does not follow the DTD, expecting (disk , virtio ,
|
||||
update_period , path , transport+), got (disk update_period path transport )
|
||||
validate_config_file(): Failed to validate :/etc/vhostmd/vhostmd.conf
|
||||
Config file: /etc/vhostmd/vhostmd.conf, fails DTD validation
|
||||
|
||||
Relax the requirement for virtio transport in the schema. With the
|
||||
introduction of multiple transports perhaps the others shoud be optional
|
||||
as well, but requiring virtio is clearly a regression.
|
||||
|
||||
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
|
||||
---
|
||||
vhostmd.dtd | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/vhostmd.dtd b/vhostmd.dtd
|
||||
index db417fd..888270e 100644
|
||||
--- a/vhostmd.dtd
|
||||
+++ b/vhostmd.dtd
|
||||
@@ -9,7 +9,7 @@ Virtual Host Metrics Daemon (vhostmd). Configuration file DTD
|
||||
-->
|
||||
|
||||
<!ELEMENT vhostmd (globals,metrics)>
|
||||
-<!ELEMENT globals (disk,virtio,update_period,path,transport+)>
|
||||
+<!ELEMENT globals (disk,virtio*,update_period,path,transport+)>
|
||||
|
||||
<!ELEMENT disk (name,path,size)>
|
||||
<!ELEMENT name (#PCDATA)>
|
||||
--
|
||||
2.32.0
|
||||
|
||||
77
0002-Support-libvirts-new-channel-path-naming-scheme.patch
Normal file
77
0002-Support-libvirts-new-channel-path-naming-scheme.patch
Normal file
@ -0,0 +1,77 @@
|
||||
commit 176fcda44caca807b4bec9fd613991afd9d5a70b
|
||||
Author: Jim Fehlig <jfehlig@suse.com>
|
||||
Date: Fri Sep 27 10:48:41 2024 -0600
|
||||
|
||||
Support libvirt's new channel path naming scheme
|
||||
|
||||
libvirt commit 8abc979bb0 changed the channel path naming scheme from
|
||||
domain-<id>-<name> to <id>-<name>. Change the logic searching for channels
|
||||
to work with either scheme.
|
||||
|
||||
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
|
||||
diff --git a/vhostmd/virtio.c b/vhostmd/virtio.c
|
||||
index d2d07bf..4516b1f 100644
|
||||
--- a/vhostmd/virtio.c
|
||||
+++ b/vhostmd/virtio.c
|
||||
@@ -277,34 +277,37 @@ static int vio_readdir(const char * path)
|
||||
}
|
||||
|
||||
while ((ent = readdir(dir)) != NULL) {
|
||||
- int rc, id;
|
||||
-
|
||||
- if (sscanf(ent->d_name, "domain-%d-", &id) == 1) {
|
||||
-
|
||||
- char tmp[SUN_PATH_LEN + 8];
|
||||
- struct stat st;
|
||||
-
|
||||
- rc = snprintf(tmp, sizeof(tmp), "%s/%s/%s", path, ent->d_name, channel_name);
|
||||
+ char tmp[SUN_PATH_LEN + 8];
|
||||
+ struct stat st;
|
||||
+ char *name = NULL;
|
||||
+ int id = -1;
|
||||
+ int rc;
|
||||
+ channel_t *c = NULL;
|
||||
+
|
||||
+ if (sscanf(ent->d_name, "domain-%d-", &id) == 1)
|
||||
+ name = strchr(&(ent->d_name[strlen("domain-")]), '-');
|
||||
+ else if (sscanf(ent->d_name, "%d-", &id) == 1)
|
||||
+ name = strchr(ent->d_name, '-');
|
||||
+ else
|
||||
+ continue;
|
||||
|
||||
- if (rc > 0 && rc < (int) sizeof(tmp) &&
|
||||
- strlen(tmp) < SUN_PATH_LEN &&
|
||||
- stat(tmp, &st) == 0 &&
|
||||
- S_ISSOCK(st.st_mode)) {
|
||||
+ rc = snprintf(tmp, sizeof(tmp), "%s/%s/%s", path, ent->d_name, channel_name);
|
||||
|
||||
- channel_t *c = NULL;
|
||||
- const char *name = strchr(&(ent->d_name[strlen("domain-")]), '-');
|
||||
+ if (rc > 0 && rc < (int) sizeof(tmp) &&
|
||||
+ strlen(tmp) < SUN_PATH_LEN &&
|
||||
+ stat(tmp, &st) == 0 &&
|
||||
+ S_ISSOCK(st.st_mode)) {
|
||||
|
||||
- pthread_mutex_lock(&channel_mtx);
|
||||
- c = vio_channel_find(id, name, 0);
|
||||
- pthread_mutex_unlock(&channel_mtx);
|
||||
+ pthread_mutex_lock(&channel_mtx);
|
||||
+ c = vio_channel_find(id, name, 0);
|
||||
+ pthread_mutex_unlock(&channel_mtx);
|
||||
|
||||
- if (c && c->fd == FREE) {
|
||||
- c->uds_name = strdup(tmp);
|
||||
- if (c->uds_name == NULL)
|
||||
- goto error;
|
||||
- if (vio_channel_open(c))
|
||||
- goto error;
|
||||
- }
|
||||
+ if (c && c->fd == FREE) {
|
||||
+ c->uds_name = strdup(tmp);
|
||||
+ if (c->uds_name == NULL)
|
||||
+ goto error;
|
||||
+ if (vio_channel_open(c))
|
||||
+ goto error;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,58 +0,0 @@
|
||||
From 06e73264b2338d20aa6e3f17b9820be3768439bf Mon Sep 17 00:00:00 2001
|
||||
From: Jim Fehlig <jfehlig@suse.com>
|
||||
Date: Mon, 6 Jan 2020 16:14:18 -0700
|
||||
Subject: [PATCH 02/19] libmetrics: Set pointer NULL after free
|
||||
|
||||
From a coverity scan
|
||||
|
||||
vhostmd-1.1/libmetrics/libmetrics.c:185:10: warning: Attempt to free released memory
|
||||
free(mdisk->buffer);
|
||||
|
||||
Some error conditions will call mdisk_content_free(), which could result
|
||||
in a double-free when the entire mdisk is freed and mdisk_content_free()
|
||||
is called again. Protect agains these potential double-frees by setting
|
||||
the mdisk contents NULL after freeing them.
|
||||
|
||||
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
|
||||
---
|
||||
libmetrics/libmetrics.c | 24 ++++++++++++++++--------
|
||||
1 file changed, 16 insertions(+), 8 deletions(-)
|
||||
|
||||
diff --git a/libmetrics/libmetrics.c b/libmetrics/libmetrics.c
|
||||
index 6c80681..a5582e7 100644
|
||||
--- a/libmetrics/libmetrics.c
|
||||
+++ b/libmetrics/libmetrics.c
|
||||
@@ -177,14 +177,22 @@ static metric_disk * mdisk_alloc()
|
||||
static void mdisk_content_free()
|
||||
{
|
||||
if (mdisk) {
|
||||
- if (mdisk->doc)
|
||||
- xmlFreeDoc(mdisk->doc);
|
||||
- if (mdisk->pctxt)
|
||||
- xmlFreeParserCtxt(mdisk->pctxt);
|
||||
- if (mdisk->buffer)
|
||||
- free(mdisk->buffer);
|
||||
- if (mdisk->disk_name)
|
||||
- free(mdisk->disk_name);
|
||||
+ if (mdisk->doc) {
|
||||
+ xmlFreeDoc(mdisk->doc);
|
||||
+ mdisk->doc = NULL;
|
||||
+ }
|
||||
+ if (mdisk->pctxt) {
|
||||
+ xmlFreeParserCtxt(mdisk->pctxt);
|
||||
+ mdisk->pctxt = NULL;
|
||||
+ }
|
||||
+ if (mdisk->buffer) {
|
||||
+ free(mdisk->buffer);
|
||||
+ mdisk->buffer = NULL;
|
||||
+ }
|
||||
+ if (mdisk->disk_name) {
|
||||
+ free(mdisk->disk_name);
|
||||
+ mdisk->disk_name = NULL;
|
||||
+ }
|
||||
}
|
||||
}
|
||||
|
||||
--
|
||||
2.32.0
|
||||
|
||||
31
0003-Fix-parsing-of-vmstat-output.patch
Normal file
31
0003-Fix-parsing-of-vmstat-output.patch
Normal file
@ -0,0 +1,31 @@
|
||||
commit 9d282891eaaeebf1b94c67314d97e55a0b58d9c2 (HEAD -> master, origin/master, origin/HEAD)
|
||||
Author: Jim Fehlig <jfehlig@suse.com>
|
||||
Date: Fri Sep 27 13:25:58 2024 -0600
|
||||
|
||||
Fix parsing of vmstat output
|
||||
|
||||
The output of `vmstat -s`, which is used to calculate the Paged{In,Out}Memory
|
||||
metrics, changed from "pages paged {in,out}" to "K paged {in,out}" in procps4.
|
||||
Change the associated actions to match against the new output.
|
||||
|
||||
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
|
||||
diff --git a/vhostmd.xml b/vhostmd.xml
|
||||
index 0dff85d..c957d1d 100644
|
||||
--- a/vhostmd.xml
|
||||
+++ b/vhostmd.xml
|
||||
@@ -98,13 +98,13 @@ the logical && operator must be replaced with "&&".
|
||||
<metric type="uint64" context="host">
|
||||
<name>PagedInMemory</name>
|
||||
<action>
|
||||
- vmstat -s | awk '/pages paged in/ {printf "%d\n", $1 / 1024 * $(getconf PAGESIZE) / 1024;}'
|
||||
+ vmstat -s | awk '/K paged in/ {printf "%d\n", $1;}'
|
||||
</action>
|
||||
</metric>
|
||||
<metric type="uint64" context="host">
|
||||
<name>PagedOutMemory</name>
|
||||
<action>
|
||||
- vmstat -s | awk '/pages paged out/ {printf "%d\n", $1 / 1024 * $(getconf PAGESIZE) / 1024;}'
|
||||
+ vmstat -s | awk '/K paged out/ {printf "%d\n", $1;}'
|
||||
</action>
|
||||
</metric>
|
||||
<metric type="group" context="host">
|
||||
@ -1,125 +0,0 @@
|
||||
From 9db959c9e3f83cb2a4fc07534462e769990d9631 Mon Sep 17 00:00:00 2001
|
||||
From: Jim Fehlig <jfehlig@suse.com>
|
||||
Date: Mon, 6 Jan 2020 16:33:24 -0700
|
||||
Subject: [PATCH 03/19] libmetrics: Initialize local variable 'ret' to failure
|
||||
|
||||
The get_mdef() and dump_xenstore_metrics() functions have local variables
|
||||
named 'ret' that are initialized to zero, meaning success. In failure paths
|
||||
'ret' is set to -1 before jumping to the 'out' label. Invert this logic by
|
||||
initializing 'ret' to -1 and only setting it to success after the function
|
||||
bodies have successfully executed.
|
||||
|
||||
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
|
||||
---
|
||||
libmetrics/libmetrics.c | 16 ++++------------
|
||||
1 file changed, 4 insertions(+), 12 deletions(-)
|
||||
|
||||
diff --git a/libmetrics/libmetrics.c b/libmetrics/libmetrics.c
|
||||
index a5582e7..49b38ea 100644
|
||||
--- a/libmetrics/libmetrics.c
|
||||
+++ b/libmetrics/libmetrics.c
|
||||
@@ -228,7 +228,7 @@ static int get_mdef(metric_disk *mdisk, private_metric *pmdef)
|
||||
xmlNodePtr node;
|
||||
char *str;
|
||||
char *xpath;
|
||||
- int ret = 0;
|
||||
+ int ret = -1;
|
||||
|
||||
ctxt = xmlXPathNewContext(mdisk->doc);
|
||||
if (!ctxt) {
|
||||
@@ -242,19 +242,16 @@ static int get_mdef(metric_disk *mdisk, private_metric *pmdef)
|
||||
if ((obj == NULL) || (obj->type != XPATH_NODESET)) {
|
||||
libmsg("%s(): No metrics found that matches %s in context:%s or malformed definition\n",
|
||||
__func__, pmdef->name, pmdef->context);
|
||||
- ret = -1;
|
||||
goto out;
|
||||
}
|
||||
if (xmlXPathNodeSetGetLength(obj->nodesetval) != 1) {
|
||||
libmsg("%s(): No metrics found that matches %s in context:%s or malformed definition\n",
|
||||
__func__, pmdef->name, pmdef->context);
|
||||
- ret = -1;
|
||||
goto out;
|
||||
}
|
||||
node = obj->nodesetval->nodeTab[0];
|
||||
if ((str = (char *)xmlGetProp(node, BAD_CAST "type")) == NULL) {
|
||||
libmsg("%s(): Metric type not specified\n", __func__);
|
||||
- ret = -1;
|
||||
goto out;
|
||||
}
|
||||
metric_type_from_str((char *)str, &(pmdef->type));
|
||||
@@ -267,7 +264,6 @@ static int get_mdef(metric_disk *mdisk, private_metric *pmdef)
|
||||
free(xpath);
|
||||
if ((obj == NULL) || (obj->type != XPATH_NODESET)) {
|
||||
libmsg("%s(): No metrics value found!\n", __func__);
|
||||
- ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -276,6 +272,7 @@ static int get_mdef(metric_disk *mdisk, private_metric *pmdef)
|
||||
str = (char *)xmlNodeListGetString(mdisk->doc, node, 1);
|
||||
pmdef->value = strdup(str);
|
||||
free(str);
|
||||
+ ret = 0;
|
||||
|
||||
out:
|
||||
if (obj)
|
||||
@@ -707,7 +704,7 @@ int dump_xenstore_metrics(const char *dest_file)
|
||||
char *buf = NULL, *path = NULL, *metrics = NULL;
|
||||
struct xs_handle *xsh = NULL;
|
||||
unsigned int len;
|
||||
- int ret = 0;
|
||||
+ int ret = -1;
|
||||
xmlParserCtxtPtr pctxt = NULL;
|
||||
xmlDocPtr doc = NULL;
|
||||
int domid;
|
||||
@@ -726,35 +723,30 @@ int dump_xenstore_metrics(const char *dest_file)
|
||||
|
||||
if ((domid = get_dom_id()) == -1) {
|
||||
libmsg("Unable to derive domID.\n" );
|
||||
- ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
xsh = xs_domain_open();
|
||||
if (xsh == NULL) {
|
||||
libmsg("xs_domain_open() error. errno: %d.\n", errno);
|
||||
- ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
path = xs_get_domain_path(xsh, domid);
|
||||
if (path == NULL) {
|
||||
libmsg("xs_get_domain_path() error. domid %d.\n", 0);
|
||||
- ret = -1;
|
||||
goto out;
|
||||
}
|
||||
asprintf(&buf, "%s/metrics", path);
|
||||
metrics = xs_read(xsh, XBT_NULL, buf, &len);
|
||||
if (metrics == NULL) {
|
||||
libmsg("xs_read(): uuid get error. %s.\n", buf);
|
||||
- ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
pctxt = xmlNewParserCtxt();
|
||||
if (!pctxt || !pctxt->sax) {
|
||||
libmsg("%s(): failed to create parser \n", __func__);
|
||||
- ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -764,10 +756,10 @@ int dump_xenstore_metrics(const char *dest_file)
|
||||
XML_PARSE_NOWARNING);
|
||||
if (!doc) {
|
||||
libmsg("%s(): libxml failed to xenstore metrics attribute\n", __func__);
|
||||
- ret = -1;
|
||||
goto out;
|
||||
}
|
||||
xmlDocFormatDump(fp, doc, 1);
|
||||
+ ret = 0;
|
||||
|
||||
out:
|
||||
if (fp && fp != stdout)
|
||||
--
|
||||
2.32.0
|
||||
|
||||
@ -1,67 +0,0 @@
|
||||
From f659ec774221532cc5452a07418e2ab1385f162c Mon Sep 17 00:00:00 2001
|
||||
From: Jim Fehlig <jfehlig@suse.com>
|
||||
Date: Mon, 6 Jan 2020 16:43:21 -0700
|
||||
Subject: [PATCH 04/19] libmetrics: Check return value of asprintf
|
||||
|
||||
Exmaple from coverity scan
|
||||
|
||||
vhostmd-1.1/libmetrics/libmetrics.c: scope_hint: In function 'get_mdef'
|
||||
vhostmd-1.1/libmetrics/libmetrics.c:231:4: warning: ignoring return value of 'asprintf', declared with attribute warn_unused_result [-Wunused-result]
|
||||
asprintf(&xpath, "//metrics/metric[name='%s'][@context='%s']", pmdef->name, pmdef->context);
|
||||
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
|
||||
---
|
||||
libmetrics/libmetrics.c | 15 +++++++++++----
|
||||
1 file changed, 11 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/libmetrics/libmetrics.c b/libmetrics/libmetrics.c
|
||||
index 49b38ea..4b2369a 100644
|
||||
--- a/libmetrics/libmetrics.c
|
||||
+++ b/libmetrics/libmetrics.c
|
||||
@@ -236,7 +236,9 @@ static int get_mdef(metric_disk *mdisk, private_metric *pmdef)
|
||||
}
|
||||
|
||||
/* Get the matching metric node type */
|
||||
- asprintf(&xpath, "//metrics/metric[name='%s'][@context='%s']", pmdef->name, pmdef->context);
|
||||
+ if (asprintf(&xpath, "//metrics/metric[name='%s'][@context='%s']", pmdef->name, pmdef->context) < 0)
|
||||
+ goto out;
|
||||
+
|
||||
obj = xmlXPathEval(BAD_CAST xpath, ctxt);
|
||||
free(xpath);
|
||||
if ((obj == NULL) || (obj->type != XPATH_NODESET)) {
|
||||
@@ -259,7 +261,9 @@ static int get_mdef(metric_disk *mdisk, private_metric *pmdef)
|
||||
xmlXPathFreeObject(obj);
|
||||
|
||||
/* Get the matching metric node value */
|
||||
- asprintf(&xpath, "//metrics/metric[name='%s'][@context='%s']/value/text()", pmdef->name, pmdef->context);
|
||||
+ if (asprintf(&xpath, "//metrics/metric[name='%s'][@context='%s']/value/text()", pmdef->name, pmdef->context) < 0)
|
||||
+ goto out;
|
||||
+
|
||||
obj = xmlXPathEval( BAD_CAST xpath, ctxt); /* worked but no nodes */
|
||||
free(xpath);
|
||||
if ((obj == NULL) || (obj->type != XPATH_NODESET)) {
|
||||
@@ -349,7 +353,8 @@ retry:
|
||||
strcmp(entry->d_name, "..") == 0)
|
||||
continue;
|
||||
|
||||
- asprintf(&path, "/dev/%s", entry->d_name);
|
||||
+ if (asprintf(&path, "/dev/%s", entry->d_name) < 0)
|
||||
+ goto error;
|
||||
#else
|
||||
path = strdup("/dev/shm/vhostmd0");
|
||||
#endif
|
||||
@@ -737,7 +742,9 @@ int dump_xenstore_metrics(const char *dest_file)
|
||||
libmsg("xs_get_domain_path() error. domid %d.\n", 0);
|
||||
goto out;
|
||||
}
|
||||
- asprintf(&buf, "%s/metrics", path);
|
||||
+ if (asprintf(&buf, "%s/metrics", path) , 0)
|
||||
+ goto out;
|
||||
+
|
||||
metrics = xs_read(xsh, XBT_NULL, buf, &len);
|
||||
if (metrics == NULL) {
|
||||
libmsg("xs_read(): uuid get error. %s.\n", buf);
|
||||
--
|
||||
2.32.0
|
||||
|
||||
@ -1,41 +0,0 @@
|
||||
From 3d4f3acdfc9f937bea946bb1c7dfad1f3516a6ce Mon Sep 17 00:00:00 2001
|
||||
From: Jim Fehlig <jfehlig@suse.com>
|
||||
Date: Mon, 6 Jan 2020 17:42:39 -0700
|
||||
Subject: [PATCH 05/19] libmetrics: Remove unsafe XML_PARSE_NOENT option
|
||||
|
||||
From coverity scan
|
||||
|
||||
Error: UNSAFE_XML_PARSE_CONFIG:
|
||||
vhostmd-1.1/libmetrics/libmetrics.c:412: unsafe_xml_parse_config: XML parse option should not have flag "XML_PARSE_NOENT" set, which is vulnerable to XML external entity attack.
|
||||
410| mdisk->doc = xmlCtxtReadMemory(mdisk->pctxt, mdisk->buffer,
|
||||
411| mdisk->length, "mdisk.xml", NULL,
|
||||
412|-> XML_PARSE_NOENT | XML_PARSE_NONET |
|
||||
413| XML_PARSE_NOWARNING);
|
||||
414| if (!mdisk->doc) {
|
||||
|
||||
It should be safe to remove the option.
|
||||
|
||||
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
|
||||
---
|
||||
libmetrics/libmetrics.c | 5 ++---
|
||||
1 file changed, 2 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/libmetrics/libmetrics.c b/libmetrics/libmetrics.c
|
||||
index 4b2369a..2819f80 100644
|
||||
--- a/libmetrics/libmetrics.c
|
||||
+++ b/libmetrics/libmetrics.c
|
||||
@@ -418,9 +418,8 @@ retry:
|
||||
}
|
||||
|
||||
mdisk->doc = xmlCtxtReadMemory(mdisk->pctxt, mdisk->buffer,
|
||||
- mdisk->length, "mdisk.xml", NULL,
|
||||
- XML_PARSE_NOENT | XML_PARSE_NONET |
|
||||
- XML_PARSE_NOWARNING);
|
||||
+ mdisk->length, "mdisk.xml", NULL,
|
||||
+ XML_PARSE_NONET | XML_PARSE_NOWARNING);
|
||||
if (!mdisk->doc) {
|
||||
libmsg("%s(): libxml failed to parse mdisk.xml buffer\n", __func__);
|
||||
goto error;
|
||||
--
|
||||
2.32.0
|
||||
|
||||
@ -1,53 +0,0 @@
|
||||
From 855326a8c9ec1a599354f743fb5391a2766a2a9c Mon Sep 17 00:00:00 2001
|
||||
From: Jim Fehlig <jfehlig@suse.com>
|
||||
Date: Mon, 6 Jan 2020 17:47:10 -0700
|
||||
Subject: [PATCH 06/19] libmetrics: Ensure libmetrics mutex is unlocked in
|
||||
error paths
|
||||
|
||||
From coverity scan
|
||||
|
||||
vhostmd-1.1/libmetrics/libmetrics.c:595: missing_unlock: Returning without unlocking "libmetrics_mutex".
|
||||
593| if (mdisk_alloc() == NULL) {
|
||||
594| errno = ENOMEM;
|
||||
595|-> return -1;
|
||||
596| }
|
||||
597| read_mdisk(mdisk);
|
||||
|
||||
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
|
||||
---
|
||||
libmetrics/libmetrics.c | 5 +++--
|
||||
1 file changed, 3 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/libmetrics/libmetrics.c b/libmetrics/libmetrics.c
|
||||
index 2819f80..756645c 100644
|
||||
--- a/libmetrics/libmetrics.c
|
||||
+++ b/libmetrics/libmetrics.c
|
||||
@@ -601,7 +601,7 @@ int get_metric(const char *metric_name, metric **mdef, metric_context context)
|
||||
mdisk_free();
|
||||
if (mdisk_alloc() == NULL) {
|
||||
errno = ENOMEM;
|
||||
- return -1;
|
||||
+ goto out;
|
||||
}
|
||||
read_mdisk(mdisk);
|
||||
}
|
||||
@@ -620,7 +620,7 @@ int get_metric(const char *metric_name, metric **mdef, metric_context context)
|
||||
|
||||
if ((lmdef = metric_alloc_padded(extra_len)) == NULL) {
|
||||
errno = ENOMEM;
|
||||
- return -1;
|
||||
+ goto out;
|
||||
}
|
||||
|
||||
lmdef->type = pmdef.type;
|
||||
@@ -635,6 +635,7 @@ int get_metric(const char *metric_name, metric **mdef, metric_context context)
|
||||
if (pmdef.context)
|
||||
free(pmdef.context);
|
||||
|
||||
+out:
|
||||
/* unlock library data */
|
||||
pthread_mutex_unlock(&libmetrics_mutex);
|
||||
return ret;
|
||||
--
|
||||
2.32.0
|
||||
|
||||
@ -1,49 +0,0 @@
|
||||
From 2cbce5fcb652226bf159f9cd9649f5869d76f6b7 Mon Sep 17 00:00:00 2001
|
||||
From: Jim Fehlig <jfehlig@suse.com>
|
||||
Date: Mon, 6 Jan 2020 18:40:33 -0700
|
||||
Subject: [PATCH 07/19] libmetrics: Fix potential memory leak
|
||||
|
||||
From coverity scan
|
||||
|
||||
vhostmd-1.1/libmetrics/libmetrics.c:613:18: warning: Potential leak of memory pointed to by 'pmdef.context'
|
||||
errno = ENOMEM;
|
||||
|
||||
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
|
||||
---
|
||||
libmetrics/libmetrics.c | 6 ++++--
|
||||
1 file changed, 4 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/libmetrics/libmetrics.c b/libmetrics/libmetrics.c
|
||||
index 756645c..6817df9 100644
|
||||
--- a/libmetrics/libmetrics.c
|
||||
+++ b/libmetrics/libmetrics.c
|
||||
@@ -586,7 +586,8 @@ int get_metric(const char *metric_name, metric **mdef, metric_context context)
|
||||
int ret = -1;
|
||||
|
||||
*mdef = NULL;
|
||||
-
|
||||
+ memset(&pmdef, 0, sizeof(private_metric));
|
||||
+
|
||||
if (mdisk == NULL) {
|
||||
errno = ENODEV;
|
||||
return -1;
|
||||
@@ -628,6 +629,8 @@ int get_metric(const char *metric_name, metric **mdef, metric_context context)
|
||||
*mdef = lmdef;
|
||||
ret = 0;
|
||||
}
|
||||
+
|
||||
+out:
|
||||
if (pmdef.name)
|
||||
free(pmdef.name);
|
||||
if (pmdef.value)
|
||||
@@ -635,7 +638,6 @@ int get_metric(const char *metric_name, metric **mdef, metric_context context)
|
||||
if (pmdef.context)
|
||||
free(pmdef.context);
|
||||
|
||||
-out:
|
||||
/* unlock library data */
|
||||
pthread_mutex_unlock(&libmetrics_mutex);
|
||||
return ret;
|
||||
--
|
||||
2.32.0
|
||||
|
||||
@ -1,40 +0,0 @@
|
||||
From bc5da0b99699bbeb653b86398a7112bc0885c31e Mon Sep 17 00:00:00 2001
|
||||
From: Jim Fehlig <jfehlig@suse.com>
|
||||
Date: Mon, 6 Jan 2020 18:51:40 -0700
|
||||
Subject: [PATCH 08/19] libmetrics: Use proper conversion specifier when
|
||||
calling log function
|
||||
|
||||
From coverity scan
|
||||
|
||||
vhostmd-1.1/libmetrics/libmetrics.c:817: invalid_type: Argument "5L" to format specifier "%u" was expected to have type "unsigned int" but has type "long".
|
||||
|
||||
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
|
||||
---
|
||||
libmetrics/libmetrics.c | 4 ++--
|
||||
1 file changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/libmetrics/libmetrics.c b/libmetrics/libmetrics.c
|
||||
index 6817df9..0f4cf70 100644
|
||||
--- a/libmetrics/libmetrics.c
|
||||
+++ b/libmetrics/libmetrics.c
|
||||
@@ -823,7 +823,7 @@ static char *get_virtio_metrics(void)
|
||||
usleep(10000);
|
||||
if (time(NULL) > end_time) {
|
||||
libmsg("%s(): Unable to send metrics request"
|
||||
- " - timeout after %us\n", __func__, timeout);
|
||||
+ " - timeout after %lis\n", __func__, timeout);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
@@ -856,7 +856,7 @@ static char *get_virtio_metrics(void)
|
||||
usleep(10000);
|
||||
if (time(NULL) > end_time) {
|
||||
libmsg("%s(): Unable to read metrics"
|
||||
- " - timeout after %us\n", __func__, timeout);
|
||||
+ " - timeout after %lis\n", __func__, timeout);
|
||||
goto error;
|
||||
}
|
||||
} else
|
||||
--
|
||||
2.32.0
|
||||
|
||||
@ -1,75 +0,0 @@
|
||||
From cba4dddebc56886034038f907085da3c6b50baab Mon Sep 17 00:00:00 2001
|
||||
From: Jim Fehlig <jfehlig@suse.com>
|
||||
Date: Mon, 6 Jan 2020 18:59:18 -0700
|
||||
Subject: [PATCH 09/19] libmetrics: Fix potential leak of FILE pointer
|
||||
|
||||
From coverity scan
|
||||
|
||||
vhostmd-1.1/libmetrics/libmetrics.c:892: alloc_fn: Storage is returned from allocation function "fopen".
|
||||
vhostmd-1.1/libmetrics/libmetrics.c:892: var_assign: Assigning: "fp" = storage returned from "fopen(dest_file, "w")".
|
||||
vhostmd-1.1/libmetrics/libmetrics.c:900: noescape: Resource "fp" is not freed or pointed-to in "fwrite".
|
||||
vhostmd-1.1/libmetrics/libmetrics.c:909: leaked_storage: Variable "fp" going out of scope leaks the storage it points to.
|
||||
907| free(response);
|
||||
908|
|
||||
909|-> return 0;
|
||||
910|
|
||||
911| error:
|
||||
|
||||
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
|
||||
---
|
||||
libmetrics/libmetrics.c | 16 +++++++---------
|
||||
1 file changed, 7 insertions(+), 9 deletions(-)
|
||||
|
||||
diff --git a/libmetrics/libmetrics.c b/libmetrics/libmetrics.c
|
||||
index 0f4cf70..8819074 100644
|
||||
--- a/libmetrics/libmetrics.c
|
||||
+++ b/libmetrics/libmetrics.c
|
||||
@@ -890,10 +890,11 @@ int dump_virtio_metrics(const char *dest_file)
|
||||
FILE *fp = stdout;
|
||||
char *response = NULL;
|
||||
size_t len;
|
||||
+ int ret = -1;
|
||||
|
||||
response = get_virtio_metrics();
|
||||
if (response == NULL)
|
||||
- goto error;
|
||||
+ return -1;
|
||||
|
||||
len = strlen(response);
|
||||
|
||||
@@ -902,27 +903,24 @@ int dump_virtio_metrics(const char *dest_file)
|
||||
if (fp == NULL) {
|
||||
libmsg("%s(), unable to dump metrics: fopen(%s) %s\n",
|
||||
__func__, dest_file, strerror(errno));
|
||||
- goto error;
|
||||
+ goto out;
|
||||
}
|
||||
}
|
||||
|
||||
if (fwrite(response, 1UL, len, fp) != len) {
|
||||
libmsg("%s(), unable to export metrics to file:%s %s\n",
|
||||
__func__, dest_file ? dest_file : "stdout", strerror(errno));
|
||||
- goto error;
|
||||
+ goto out;
|
||||
}
|
||||
|
||||
- if (response)
|
||||
- free(response);
|
||||
+ ret = 0;
|
||||
|
||||
- return 0;
|
||||
-
|
||||
- error:
|
||||
+out:
|
||||
if (dest_file && fp)
|
||||
fclose(fp);
|
||||
|
||||
if (response)
|
||||
free(response);
|
||||
|
||||
- return -1;
|
||||
+ return ret;
|
||||
}
|
||||
--
|
||||
2.32.0
|
||||
|
||||
@ -1,55 +0,0 @@
|
||||
From 69fcc2075d7cb1f16eb7d27ae3559fa3c77f5514 Mon Sep 17 00:00:00 2001
|
||||
From: Jim Fehlig <jfehlig@suse.com>
|
||||
Date: Tue, 7 Jan 2020 11:36:56 -0700
|
||||
Subject: [PATCH 10/19] util: Add missing call to va_end
|
||||
|
||||
From coverity scan
|
||||
|
||||
Error: VARARGS (CWE-237):
|
||||
vhostmd-1.1/vhostmd/util.c:209: va_init: Initializing va_list "argptr".
|
||||
vhostmd-1.1/vhostmd/util.c:218: missing_va_end: va_end was not called for "argptr".
|
||||
216| grow_size = (count > 1000) ? count : 1000;
|
||||
217| if (buffer_grow(buf, grow_size) < 0)
|
||||
218|-> return;
|
||||
219|
|
||||
220| size = buf->size - buf->use - 1;
|
||||
|
||||
Error: VARARGS (CWE-237):
|
||||
vhostmd-1.1/vhostmd/util.c:209: va_init: Initializing va_list "argptr".
|
||||
vhostmd-1.1/vhostmd/util.c:226: missing_va_end: va_end was not called for "argptr".
|
||||
224| buf->use += count;
|
||||
225| buf->content[buf->use] = '\0';
|
||||
226|-> }
|
||||
227|
|
||||
228| /*
|
||||
|
||||
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
|
||||
---
|
||||
vhostmd/util.c | 5 ++++-
|
||||
1 file changed, 4 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/vhostmd/util.c b/vhostmd/util.c
|
||||
index 5747f16..1f9545b 100644
|
||||
--- a/vhostmd/util.c
|
||||
+++ b/vhostmd/util.c
|
||||
@@ -214,13 +214,16 @@ void vu_buffer_vsprintf(vu_buffer *buf, const char *format, ...)
|
||||
va_end(locarg);
|
||||
|
||||
grow_size = (count > 1000) ? count : 1000;
|
||||
- if (buffer_grow(buf, grow_size) < 0)
|
||||
+ if (buffer_grow(buf, grow_size) < 0) {
|
||||
+ va_end(argptr);
|
||||
return;
|
||||
+ }
|
||||
|
||||
size = buf->size - buf->use - 1;
|
||||
va_copy(locarg, argptr);
|
||||
}
|
||||
va_end(locarg);
|
||||
+ va_end(argptr);
|
||||
buf->use += count;
|
||||
buf->content[buf->use] = '\0';
|
||||
}
|
||||
--
|
||||
2.32.0
|
||||
|
||||
@ -1,40 +0,0 @@
|
||||
From b39f7cc778903e9cda8aa46d170b9efe80efda89 Mon Sep 17 00:00:00 2001
|
||||
From: Jim Fehlig <jfehlig@suse.com>
|
||||
Date: Tue, 7 Jan 2020 11:41:11 -0700
|
||||
Subject: [PATCH 11/19] util: Fix potential memory leak
|
||||
|
||||
From coverity scan
|
||||
|
||||
vhostmd-1.1/vhostmd/util.c:415:14: warning: Potential leak of memory pointed to by 'cp'
|
||||
return(NULL);
|
||||
|
||||
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
|
||||
---
|
||||
vhostmd/util.c | 4 +++-
|
||||
1 file changed, 3 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/vhostmd/util.c b/vhostmd/util.c
|
||||
index 1f9545b..599c5c7 100644
|
||||
--- a/vhostmd/util.c
|
||||
+++ b/vhostmd/util.c
|
||||
@@ -415,7 +415,7 @@ char *vu_str_replace(const char *haystack, const char *origstr, const char *news
|
||||
|
||||
dest = malloc(strlen(haystack) - (origlen * cnt) + (newlen * cnt) + 1);
|
||||
if (dest == NULL) {
|
||||
- return(NULL);
|
||||
+ goto out;
|
||||
}
|
||||
*dest = '\0';
|
||||
|
||||
@@ -428,6 +428,8 @@ char *vu_str_replace(const char *haystack, const char *origstr, const char *news
|
||||
cp = p + origlen;
|
||||
}
|
||||
strcat(dest, cp);
|
||||
+
|
||||
+out:
|
||||
free(tempstr);
|
||||
|
||||
return dest;
|
||||
--
|
||||
2.32.0
|
||||
|
||||
@ -1,38 +0,0 @@
|
||||
From 4350fcf7a5c4cb7d803db1a0df2b757230b90e25 Mon Sep 17 00:00:00 2001
|
||||
From: Jim Fehlig <jfehlig@suse.com>
|
||||
Date: Tue, 7 Jan 2020 11:47:33 -0700
|
||||
Subject: [PATCH 12/19] util: Check return value of strstr
|
||||
|
||||
From coverity scan
|
||||
|
||||
vhostmd-1.1/vhostmd/util.c:421: returned_null: "strstr" returns "NULL" (checked 6 out of 7 times).
|
||||
|
||||
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
|
||||
---
|
||||
vhostmd/util.c | 10 ++++++----
|
||||
1 file changed, 6 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/vhostmd/util.c b/vhostmd/util.c
|
||||
index 599c5c7..317dbc6 100644
|
||||
--- a/vhostmd/util.c
|
||||
+++ b/vhostmd/util.c
|
||||
@@ -422,10 +422,12 @@ char *vu_str_replace(const char *haystack, const char *origstr, const char *news
|
||||
cp = tempstr;
|
||||
for (i=0; i <cnt; i++) {
|
||||
p = strstr(cp, origstr);
|
||||
- *p = '\0';
|
||||
- strcat(dest, cp);
|
||||
- strcat(dest, newstr);
|
||||
- cp = p + origlen;
|
||||
+ if (p) {
|
||||
+ *p = '\0';
|
||||
+ strcat(dest, cp);
|
||||
+ strcat(dest, newstr);
|
||||
+ cp = p + origlen;
|
||||
+ }
|
||||
}
|
||||
strcat(dest, cp);
|
||||
|
||||
--
|
||||
2.32.0
|
||||
|
||||
@ -1,48 +0,0 @@
|
||||
From 1771ddb83fe8a8cb38e7bee212bdfa3d1927cfc5 Mon Sep 17 00:00:00 2001
|
||||
From: Jim Fehlig <jfehlig@suse.com>
|
||||
Date: Tue, 7 Jan 2020 11:52:23 -0700
|
||||
Subject: [PATCH 13/19] Check return value of asprintf
|
||||
|
||||
Example from coverity scan
|
||||
|
||||
vhostmd-1.1/vhostmd/util.c: scope_hint: In function 'vu_append_string'
|
||||
vhostmd-1.1/vhostmd/util.c:484:7: warning: ignoring return value of 'asprintf', declared with attribute warn_unused_result [-Wunused-result]
|
||||
asprintf(&cp, "%s,%s", *dest, str);
|
||||
|
||||
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
|
||||
---
|
||||
vhostmd/util.c | 3 ++-
|
||||
vhostmd/vhostmd.c | 3 ++-
|
||||
2 files changed, 4 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/vhostmd/util.c b/vhostmd/util.c
|
||||
index 317dbc6..d7ce3fc 100644
|
||||
--- a/vhostmd/util.c
|
||||
+++ b/vhostmd/util.c
|
||||
@@ -488,7 +488,8 @@ int vu_append_string(char **dest, xmlChar * str)
|
||||
char *cp;
|
||||
|
||||
if (*dest) {
|
||||
- asprintf(&cp, "%s,%s", *dest, str);
|
||||
+ if (asprintf(&cp, "%s,%s", *dest, str) < 0)
|
||||
+ return -1;
|
||||
free(*dest);
|
||||
*dest = cp;
|
||||
}
|
||||
diff --git a/vhostmd/vhostmd.c b/vhostmd/vhostmd.c
|
||||
index 7e29e6f..7374ec9 100644
|
||||
--- a/vhostmd/vhostmd.c
|
||||
+++ b/vhostmd/vhostmd.c
|
||||
@@ -259,7 +259,8 @@ static int parse_group_metric(xmlDocPtr xml ATTRIBUTE_UNUSED,
|
||||
vu_log(VHOSTMD_WARN, "parse_group_metric: node path not found");
|
||||
return -1;
|
||||
}
|
||||
- asprintf(&cp, "%s/variable", path);
|
||||
+ if (asprintf(&cp, "%s/variable", path) < 0)
|
||||
+ goto error;
|
||||
|
||||
obj = xmlXPathEval( BAD_CAST cp, ctxt);
|
||||
if ((obj == NULL) || (obj->type != XPATH_NODESET)) {
|
||||
--
|
||||
2.32.0
|
||||
|
||||
@ -1,36 +0,0 @@
|
||||
From 71a94a18c470ebbd870253b8aedbb7b3b24a274b Mon Sep 17 00:00:00 2001
|
||||
From: Jim Fehlig <jfehlig@suse.com>
|
||||
Date: Tue, 14 Jan 2020 15:08:54 -0700
|
||||
Subject: [PATCH 14/19] vhostmd: Fix memory leak in parse_transports
|
||||
|
||||
From coverity scan
|
||||
|
||||
vhostmd-1.1/vhostmd/vhostmd.c:455: alloc_fn: Storage is returned from allocation function "xmlXPathEval".
|
||||
vhostmd-1.1/vhostmd/vhostmd.c:455: var_assign: Assigning: "obj" = storage returned from "xmlXPathEval((xmlChar *)"//vhostmd/globals/transport", ctxt)".
|
||||
vhostmd-1.1/vhostmd/vhostmd.c:474: leaked_storage: Variable "obj" going out of scope leaks the storage it points to.
|
||||
472| #else
|
||||
473| vu_log (VHOSTMD_ERR, "No support for xenstore transport in this vhostmd");
|
||||
474|-> return -1;
|
||||
475| #endif
|
||||
476| }
|
||||
|
||||
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
|
||||
---
|
||||
vhostmd/vhostmd.c | 1 +
|
||||
1 file changed, 1 insertion(+)
|
||||
|
||||
diff --git a/vhostmd/vhostmd.c b/vhostmd/vhostmd.c
|
||||
index 7374ec9..3d1d53e 100644
|
||||
--- a/vhostmd/vhostmd.c
|
||||
+++ b/vhostmd/vhostmd.c
|
||||
@@ -472,6 +472,7 @@ static int parse_transports(xmlDocPtr xml,
|
||||
transports |= XENSTORE;
|
||||
#else
|
||||
vu_log (VHOSTMD_ERR, "No support for xenstore transport in this vhostmd");
|
||||
+ xmlXPathFreeObject(obj);
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
--
|
||||
2.32.0
|
||||
|
||||
@ -1,36 +0,0 @@
|
||||
From d9eeede678521776d327784d0307de6c98920bb8 Mon Sep 17 00:00:00 2001
|
||||
From: Jim Fehlig <jfehlig@suse.com>
|
||||
Date: Tue, 14 Jan 2020 15:12:28 -0700
|
||||
Subject: [PATCH 15/19] vhostmd: Remove unsafe XML_PARSE_NOENT option
|
||||
|
||||
From coverity scan
|
||||
|
||||
vhostmd-1.1/vhostmd/vhostmd.c:553: unsafe_xml_parse_config: XML parse option should not have flag "XML_PARSE_NOENT" set, which is vulnerable to XML external entty attack.
|
||||
551|
|
||||
552| xml = xmlCtxtReadFile(pctxt, filename, NULL,
|
||||
553|-> XML_PARSE_NOENT | XML_PARSE_NONET |
|
||||
554| XML_PARSE_NOWARNING);
|
||||
555| if (!xml) {
|
||||
|
||||
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
|
||||
---
|
||||
vhostmd/vhostmd.c | 3 +--
|
||||
1 file changed, 1 insertion(+), 2 deletions(-)
|
||||
|
||||
diff --git a/vhostmd/vhostmd.c b/vhostmd/vhostmd.c
|
||||
index 3d1d53e..4d04989 100644
|
||||
--- a/vhostmd/vhostmd.c
|
||||
+++ b/vhostmd/vhostmd.c
|
||||
@@ -552,8 +552,7 @@ static int parse_config_file(const char *filename)
|
||||
goto out;
|
||||
|
||||
xml = xmlCtxtReadFile(pctxt, filename, NULL,
|
||||
- XML_PARSE_NOENT | XML_PARSE_NONET |
|
||||
- XML_PARSE_NOWARNING);
|
||||
+ XML_PARSE_NONET | XML_PARSE_NOWARNING);
|
||||
if (!xml) {
|
||||
vu_log(VHOSTMD_ERR, "libxml failed to parse config file %s",
|
||||
filename);
|
||||
--
|
||||
2.32.0
|
||||
|
||||
@ -1,94 +0,0 @@
|
||||
From 4f7b23e19c88c92d834d5f975c846b47eaa03c79 Mon Sep 17 00:00:00 2001
|
||||
From: Jim Fehlig <jfehlig@suse.com>
|
||||
Date: Tue, 14 Jan 2020 15:33:39 -0700
|
||||
Subject: [PATCH 16/19] vhostmd: Check return value of file functions
|
||||
|
||||
Check return value of ftruncate, lseek, and write functions as
|
||||
reported by coverity. Example from coverity scan
|
||||
|
||||
vhostmd-1.1/vhostmd/vhostmd.c: scope_hint: In function 'metrics_disk_create'
|
||||
vhostmd-1.1/vhostmd/vhostmd.c:821:4: warning: ignoring return value of 'ftruncate', declared with attribute warn_unused_result [-Wunused-result]
|
||||
ftruncate(fd, mdisk_size);
|
||||
^~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
819|
|
||||
820| /* truncate to a possible new size */
|
||||
821|-> ftruncate(fd, mdisk_size);
|
||||
822|
|
||||
823| /* zero fill metrics data */
|
||||
|
||||
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
|
||||
---
|
||||
vhostmd/vhostmd.c | 33 +++++++++++++++++++++++++--------
|
||||
1 file changed, 25 insertions(+), 8 deletions(-)
|
||||
|
||||
diff --git a/vhostmd/vhostmd.c b/vhostmd/vhostmd.c
|
||||
index 4d04989..1600a87 100644
|
||||
--- a/vhostmd/vhostmd.c
|
||||
+++ b/vhostmd/vhostmd.c
|
||||
@@ -675,8 +675,12 @@ static int metrics_disk_busy(int fd, int busy)
|
||||
{
|
||||
md_header.busy = (uint32_t)(htonl(busy));
|
||||
|
||||
- lseek(fd, offsetof(mdisk_header, busy), SEEK_SET);
|
||||
- write(fd, &(md_header.busy), sizeof(uint32_t));
|
||||
+ if (lseek(fd, offsetof(mdisk_header, busy), SEEK_SET) == -1)
|
||||
+ return -1;
|
||||
+
|
||||
+ if (write(fd, &(md_header.busy), sizeof(uint32_t)) == -1)
|
||||
+ return -1;
|
||||
+
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -724,6 +728,8 @@ error:
|
||||
|
||||
static int metrics_disk_update(int fd, vu_buffer *buf)
|
||||
{
|
||||
+ int ret = -1;
|
||||
+
|
||||
if (buf->use > MDISK_SIZE) {
|
||||
vu_log(VHOSTMD_ERR, "Metrics data is larger than metrics disk");
|
||||
return -1;
|
||||
@@ -731,11 +737,17 @@ static int metrics_disk_update(int fd, vu_buffer *buf)
|
||||
|
||||
metrics_disk_busy(fd, 1);
|
||||
metrics_disk_header_update(fd, buf);
|
||||
- lseek(fd, MDISK_HEADER_SIZE, SEEK_SET);
|
||||
- write(fd, buf->content, buf->use);
|
||||
+ if (lseek(fd, MDISK_HEADER_SIZE, SEEK_SET) == -1)
|
||||
+ goto out;
|
||||
+
|
||||
+ if (write(fd, buf->content, buf->use) == -1)
|
||||
+ goto out;
|
||||
+
|
||||
+ ret = 0;
|
||||
+
|
||||
+out:
|
||||
metrics_disk_busy(fd, 0);
|
||||
-
|
||||
- return 0;
|
||||
+ return ret;
|
||||
}
|
||||
|
||||
static int metrics_free()
|
||||
@@ -819,10 +831,15 @@ static int metrics_disk_create(void)
|
||||
}
|
||||
|
||||
/* truncate to a possible new size */
|
||||
- ftruncate(fd, mdisk_size);
|
||||
+ if (ftruncate(fd, mdisk_size) == -1){
|
||||
+ vu_log(VHOSTMD_ERR, "Failed to truncate metrics disk: %s",
|
||||
+ strerror(errno));
|
||||
+ goto error;
|
||||
+ }
|
||||
|
||||
/* zero fill metrics data */
|
||||
- lseek(fd, MDISK_HEADER_SIZE, SEEK_SET);
|
||||
+ if (lseek(fd, MDISK_HEADER_SIZE, SEEK_SET) == -1)
|
||||
+ goto error;
|
||||
for (i = 0; i < size / MDISK_SIZE_MIN; i++)
|
||||
if (write(fd, buf, MDISK_SIZE_MIN) != MDISK_SIZE_MIN) {
|
||||
vu_log(VHOSTMD_ERR, "Error creating disk of requested "
|
||||
--
|
||||
2.32.0
|
||||
|
||||
@ -1,38 +0,0 @@
|
||||
From d86c51d98ce8b891f3948f8aa54fc9634e6a8c67 Mon Sep 17 00:00:00 2001
|
||||
From: Jim Fehlig <jfehlig@suse.com>
|
||||
Date: Tue, 14 Jan 2020 16:04:09 -0700
|
||||
Subject: [PATCH 17/19] vhostmd: Check for valide file handle before calling
|
||||
close
|
||||
|
||||
From coverity scan
|
||||
|
||||
vhostmd-1.1/vhostmd/vhostmd.c:778: var_tested_neg: Assigning: "fd" = a negative value.
|
||||
vhostmd-1.1/vhostmd/vhostmd.c:845: negative_returns: "fd" is passed to a parameter that cannot be negative.
|
||||
843| free(dir);
|
||||
844| free(buf);
|
||||
845|-> close(fd);
|
||||
846| return -1;
|
||||
847| }
|
||||
|
||||
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
|
||||
---
|
||||
vhostmd/vhostmd.c | 3 ++-
|
||||
1 file changed, 2 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/vhostmd/vhostmd.c b/vhostmd/vhostmd.c
|
||||
index 1600a87..1395bc5 100644
|
||||
--- a/vhostmd/vhostmd.c
|
||||
+++ b/vhostmd/vhostmd.c
|
||||
@@ -860,7 +860,8 @@ static int metrics_disk_create(void)
|
||||
error:
|
||||
free(dir);
|
||||
free(buf);
|
||||
- close(fd);
|
||||
+ if (fd != -1)
|
||||
+ close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
--
|
||||
2.32.0
|
||||
|
||||
@ -1,46 +0,0 @@
|
||||
From ff6959fd9203c667f6b4c95fa812621cc91dc42e Mon Sep 17 00:00:00 2001
|
||||
From: Jim Fehlig <jfehlig@suse.com>
|
||||
Date: Tue, 14 Jan 2020 16:08:42 -0700
|
||||
Subject: [PATCH 18/19] vhostmd: Fix memory leak in vhostmd_run
|
||||
|
||||
Example from coverity scan
|
||||
|
||||
vhostmd-1.1/vhostmd/vhostmd.c:940: alloc_arg: "vu_buffer_create" allocates memory that is stored into "buf".
|
||||
vhostmd-1.1/vhostmd/vhostmd.c:959: leaked_storage: Variable "buf" going out of scope leaks the storage it points to.
|
||||
957| vu_log(VHOSTMD_ERR, "Failed to start virtio thread '%s'\n",
|
||||
958| strerror(rc));
|
||||
959|-> return -1;
|
||||
960| }
|
||||
961| }
|
||||
|
||||
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
|
||||
---
|
||||
vhostmd/vhostmd.c | 5 ++++-
|
||||
1 file changed, 4 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/vhostmd/vhostmd.c b/vhostmd/vhostmd.c
|
||||
index 1395bc5..6f3709b 100644
|
||||
--- a/vhostmd/vhostmd.c
|
||||
+++ b/vhostmd/vhostmd.c
|
||||
@@ -967,14 +967,17 @@ static int vhostmd_run(int diskfd)
|
||||
if (virtio_expiration_time < (update_period * 3))
|
||||
virtio_expiration_time = update_period * 3;
|
||||
|
||||
- if (virtio_init(virtio_max_channels, virtio_expiration_time))
|
||||
+ if (virtio_init(virtio_max_channels, virtio_expiration_time)) {
|
||||
+ vu_buffer_delete(buf);
|
||||
return -1;
|
||||
+ }
|
||||
|
||||
rc = pthread_create(&virtio_tid, NULL, virtio_run, NULL);
|
||||
|
||||
if (rc != 0) {
|
||||
vu_log(VHOSTMD_ERR, "Failed to start virtio thread '%s'\n",
|
||||
strerror(rc));
|
||||
+ vu_buffer_delete(buf);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
--
|
||||
2.32.0
|
||||
|
||||
@ -1,36 +0,0 @@
|
||||
From 99995e4ba138f43b277620bd43a096c72f354548 Mon Sep 17 00:00:00 2001
|
||||
From: Jim Fehlig <jfehlig@suse.com>
|
||||
Date: Tue, 14 Jan 2020 16:22:48 -0700
|
||||
Subject: [PATCH 19/19] virtio: Fix strncpy length parameter
|
||||
|
||||
Leave an extra byte for null-terminator in call to strncpy. From
|
||||
coverity scan
|
||||
|
||||
vhostmd-1.1/vhostmd/virtio.c:194: buffer_size_warning: Calling "strncpy" with a maximum size argument of 108 bytes on destination array "address.sun_path" of size 108 bytes might leave the destination string unterminated.
|
||||
192| address.sun_family = AF_LOCAL;
|
||||
193|
|
||||
194|-> strncpy(address.sun_path, c->uds_name, SUN_PATH_LEN);
|
||||
195|
|
||||
196| if ((c->fd = socket(AF_LOCAL, SOCK_STREAM, 0)) == -1)
|
||||
|
||||
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
|
||||
---
|
||||
vhostmd/virtio.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/vhostmd/virtio.c b/vhostmd/virtio.c
|
||||
index f227b45..a6c2515 100644
|
||||
--- a/vhostmd/virtio.c
|
||||
+++ b/vhostmd/virtio.c
|
||||
@@ -191,7 +191,7 @@ static int vio_channel_open(channel_t * c)
|
||||
bzero(&address, sizeof(address));
|
||||
address.sun_family = AF_LOCAL;
|
||||
|
||||
- strncpy(address.sun_path, c->uds_name, SUN_PATH_LEN);
|
||||
+ strncpy(address.sun_path, c->uds_name, SUN_PATH_LEN - 1);
|
||||
|
||||
if ((c->fd = socket(AF_LOCAL, SOCK_STREAM, 0)) == -1)
|
||||
goto error;
|
||||
--
|
||||
2.32.0
|
||||
|
||||
5
rpminspect.yaml
Normal file
5
rpminspect.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
xml:
|
||||
# Regular expression (man 7 regex) matching directories to ignore
|
||||
# during the xml inspection. Skip DTD files, which
|
||||
# contain a mix of XML and code.
|
||||
exclude_path: .*(\.dtd)$
|
||||
2
sources
2
sources
@ -1 +1 @@
|
||||
SHA512 (vhostmd-1.1.tar.gz) = 9fad55c96c504b59345fb670d9ae9b83c892d82f05784253c8826436a1a75419bb73d6be48a8f8d956f89c77ab4f54a85200e92078c22c8f156954ca8f434d49
|
||||
SHA512 (vhostmd-1.2.tar.gz) = 13f797ca29ad9038bae966625d2dd764e030369b885ac520aa49d102d3bb9ea2356d0cf381ee3ce2ac3c1da0fc19ba2613241c736644c099bb3697180b852aed
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
|
||||
Configuration file for virtual host metrics daemon (vhostmd).
|
||||
|
||||
A metrics disk between 1024 bytes and 256Mbytes is supported.
|
||||
A better, less noisy, more minimal configuration file
|
||||
which doesn't depend on Xen.
|
||||
|
||||
@ -17,6 +18,12 @@ A metric's value is set to the output produced by executing its action.
|
||||
the vm currently under inspection is substituted for NAME. Only useful
|
||||
within the vm element.
|
||||
|
||||
NOTE - 'action' must be a valid shell builtin, script or external
|
||||
command found in the path specified by the global <path> element.
|
||||
When chaining commands, '&', '<' and '>' are reserved characters,
|
||||
therefore '&', '<' and '>' must be used instead. For example,
|
||||
the logical && operator must be replaced with "&&".
|
||||
|
||||
-->
|
||||
|
||||
|
||||
@ -81,6 +88,7 @@ way.
|
||||
<size unit="k">256</size>
|
||||
</disk>
|
||||
<virtio>
|
||||
<channel_path>/run/libvirt/qemu/channel</channel_path>
|
||||
<max_channels>1024</max_channels>
|
||||
<expiration_time>15</expiration_time>
|
||||
</virtio>
|
||||
|
||||
41
vhostmd.spec
41
vhostmd.spec
@ -2,37 +2,18 @@
|
||||
|
||||
Summary: Virtualization host metrics daemon
|
||||
Name: vhostmd
|
||||
Version: 1.1
|
||||
Release: 11%{?dist}
|
||||
License: GPLv2+
|
||||
Version: 1.2
|
||||
Release: 1%{?dist}
|
||||
License: LGPL-2.1-or-later
|
||||
|
||||
URL: https://github.com/vhostmd/vhostmd
|
||||
|
||||
Source0: https://github.com/vhostmd/vhostmd/archive/v%{version}/%{name}-%{version}.tar.gz
|
||||
Source1: vhostmd.conf
|
||||
|
||||
# Prevents updates from previous versions with the old config file
|
||||
# from breaking (RHBZ#1782897).
|
||||
# https://github.com/vhostmd/vhostmd/commit/83cc269f6892852be94467cea771b3ad1da8a369
|
||||
Patch0001: 0001-Relax-virtio-requirement-in-config-file.patch
|
||||
Patch0002: 0002-libmetrics-Set-pointer-NULL-after-free.patch
|
||||
Patch0003: 0003-libmetrics-Initialize-local-variable-ret-to-failure.patch
|
||||
Patch0004: 0004-libmetrics-Check-return-value-of-asprintf.patch
|
||||
Patch0005: 0005-libmetrics-Remove-unsafe-XML_PARSE_NOENT-option.patch
|
||||
Patch0006: 0006-libmetrics-Ensure-libmetrics-mutex-is-unlocked-in-er.patch
|
||||
Patch0007: 0007-libmetrics-Fix-potential-memory-leak.patch
|
||||
Patch0008: 0008-libmetrics-Use-proper-conversion-specifier-when-call.patch
|
||||
Patch0009: 0009-libmetrics-Fix-potential-leak-of-FILE-pointer.patch
|
||||
Patch0010: 0010-util-Add-missing-call-to-va_end.patch
|
||||
Patch0011: 0011-util-Fix-potential-memory-leak.patch
|
||||
Patch0012: 0012-util-Check-return-value-of-strstr.patch
|
||||
Patch0013: 0013-Check-return-value-of-asprintf.patch
|
||||
Patch0014: 0014-vhostmd-Fix-memory-leak-in-parse_transports.patch
|
||||
Patch0015: 0015-vhostmd-Remove-unsafe-XML_PARSE_NOENT-option.patch
|
||||
Patch0016: 0016-vhostmd-Check-return-value-of-file-functions.patch
|
||||
Patch0017: 0017-vhostmd-Check-for-valide-file-handle-before-calling-.patch
|
||||
Patch0018: 0018-vhostmd-Fix-memory-leak-in-vhostmd_run.patch
|
||||
Patch0019: 0019-virtio-Fix-strncpy-length-parameter.patch
|
||||
Patch0001: 0001-Add-channel_path-setting-to-daemon-config-file.patch
|
||||
Patch0002: 0002-Support-libvirts-new-channel-path-naming-scheme.patch
|
||||
Patch0003: 0003-Fix-parsing-of-vmstat-output.patch
|
||||
|
||||
BuildRequires: make
|
||||
BuildRequires: gcc
|
||||
@ -125,11 +106,7 @@ rm $RPM_BUILD_ROOT%{_datadir}/vhostmd/scripts/pagerate.pl
|
||||
|
||||
%pre
|
||||
# UID:GID 112:112 reserved, see RHBZ#534109.
|
||||
getent group vhostmd >/dev/null || groupadd -g 112 -r vhostmd
|
||||
getent passwd vhostmd >/dev/null || \
|
||||
useradd -u 112 -r -g vhostmd -d %{_datadir}/vhostmd -s /sbin/nologin \
|
||||
-c "Virtual Host Metrics Daemon" vhostmd
|
||||
exit 0
|
||||
%sysusers_create_inline u vhostmd 112 "Virtual Host Metrics Daemon" %{_datadir}/vhostmd /sbin/nologin
|
||||
|
||||
|
||||
%post
|
||||
@ -181,6 +158,10 @@ exit 0
|
||||
|
||||
|
||||
%changelog
|
||||
* Wed Feb 11 2026 Nils Koenig <nkoenig@redhat.com> - 1.2-1
|
||||
- Updated to upstream version 1.2 plus latest fixes
|
||||
resolves: RHEL-148557
|
||||
|
||||
* Tue Aug 10 2021 Mohan Boddu <mboddu@redhat.com> - 1.1-11
|
||||
- Rebuilt for IMA sigs, glibc 2.34, aarch64 flags
|
||||
Related: rhbz#1991688
|
||||
|
||||
Loading…
Reference in New Issue
Block a user