- update hv_kvp_daemon (changes up to 3.11-rc1):

Improve error logging in KVP daemon.
  Fix file descriptor leaks
  Check retrun value of strchr call
  Check return value of poll call
  Check return value of setsockopt call
  daemon should check type of received Netlink msg
  daemon setsockopt should use options macros
  daemon should subscribe only to CN_KVP_IDX group

OBS-URL: https://build.opensuse.org/package/show/Virtualization/hyper-v?expand=0&rev=58
This commit is contained in:
Olaf Hering 2013-07-15 14:11:35 +00:00 committed by Git OBS Bridge
parent 727d8197fc
commit 1051dacf7e
2 changed files with 67 additions and 18 deletions

View File

@ -1,3 +1,16 @@
-------------------------------------------------------------------
Mon Jul 15 15:24:00 CEST 2013 - ohering@suse.de
- update hv_kvp_daemon (changes up to 3.11-rc1):
Improve error logging in KVP daemon.
Fix file descriptor leaks
Check retrun value of strchr call
Check return value of poll call
Check return value of setsockopt call
daemon should check type of received Netlink msg
daemon setsockopt should use options macros
daemon should subscribe only to CN_KVP_IDX group
-------------------------------------------------------------------
Mon Jul 15 12:04:05 CEST 2013 - ohering@suse.de

View File

@ -102,6 +102,10 @@ static struct utsname uts_buf;
#define MAX_FILE_NAME 100
#define ENTRIES_PER_BLOCK 50
#ifndef SOL_NETLINK
#define SOL_NETLINK 270
#endif
struct kvp_record {
char key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
char value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE];
@ -123,7 +127,8 @@ static void kvp_acquire_lock(int pool)
fl.l_pid = getpid();
if (fcntl(kvp_file_info[pool].fd, F_SETLKW, &fl) == -1) {
syslog(LOG_ERR, "Failed to acquire the lock pool: %d", pool);
syslog(LOG_ERR, "Failed to acquire the lock pool: %d; error: %d %s", pool,
errno, strerror(errno));
exit(EXIT_FAILURE);
}
}
@ -134,8 +139,8 @@ static void kvp_release_lock(int pool)
fl.l_pid = getpid();
if (fcntl(kvp_file_info[pool].fd, F_SETLK, &fl) == -1) {
perror("fcntl");
syslog(LOG_ERR, "Failed to release the lock pool: %d", pool);
syslog(LOG_ERR, "Failed to release the lock pool: %d; error: %d %s", pool,
errno, strerror(errno));
exit(EXIT_FAILURE);
}
}
@ -153,8 +158,9 @@ static void kvp_update_file(int pool)
filep = fopen(kvp_file_info[pool].fname, "we");
if (!filep) {
syslog(LOG_ERR, "Failed to open file, pool: %d; error: %d %s", pool,
errno, strerror(errno));
kvp_release_lock(pool);
syslog(LOG_ERR, "Failed to open file, pool: %d", pool);
exit(EXIT_FAILURE);
}
@ -184,8 +190,9 @@ static void kvp_update_mem_state(int pool)
filep = fopen(kvp_file_info[pool].fname, "re");
if (!filep) {
syslog(LOG_ERR, "Failed to open file, pool: %d; error: %d %s", pool,
errno, strerror(errno));
kvp_release_lock(pool);
syslog(LOG_ERR, "Failed to open file, pool: %d", pool);
exit(EXIT_FAILURE);
}
for (;;) {
@ -236,7 +243,8 @@ static int kvp_file_init(void)
if (access(KVP_CONFIG_LOC, F_OK)) {
if (mkdir(KVP_CONFIG_LOC, 0755 /* rwxr-xr-x */)) {
syslog(LOG_ERR, " Failed to create %s", KVP_CONFIG_LOC);
syslog(LOG_ERR, "Failed to create '%s'; error: %d %s", KVP_CONFIG_LOC,
errno, strerror(errno));
exit(EXIT_FAILURE);
}
}
@ -253,12 +261,15 @@ static int kvp_file_init(void)
filep = fopen(fname, "re");
if (!filep)
if (!filep) {
close(fd);
return 1;
}
record = malloc(alloc_unit * num_blocks);
if (record == NULL) {
fclose(filep);
close(fd);
return 1;
}
for (;;) {
@ -282,6 +293,7 @@ static int kvp_file_init(void)
num_blocks);
if (record == NULL) {
fclose(filep);
close(fd);
return 1;
}
continue;
@ -761,7 +773,9 @@ static void kvp_process_ipconfig_file(char *cmd,
break;
x = strchr(p, '\n');
*x = '\0';
if (x)
*x = '\0';
strcat(config_buf, p);
strcat(config_buf, ";");
}
@ -1277,7 +1291,8 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val)
file = fopen(if_file, "w");
if (file == NULL) {
syslog(LOG_ERR, "Failed to open config file");
syslog(LOG_ERR, "Failed to open config file; error: %d %s",
errno, strerror(errno));
return HV_E_FAIL;
}
@ -1409,7 +1424,7 @@ netlink_send(int fd, struct cn_msg *msg)
int main(void)
{
int fd, len, sock_opt;
int fd, len, nl_group;
int error;
struct cn_msg *message;
struct pollfd pfd;
@ -1439,23 +1454,30 @@ int main(void)
fd = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR);
if (fd < 0) {
syslog(LOG_ERR, "netlink socket creation failed; error:%d", fd);
syslog(LOG_ERR, "netlink socket creation failed; error: %d %s", errno,
strerror(errno));
exit(EXIT_FAILURE);
}
addr.nl_family = AF_NETLINK;
addr.nl_pad = 0;
addr.nl_pid = 0;
addr.nl_groups = CN_KVP_IDX;
addr.nl_groups = 0;
error = bind(fd, (struct sockaddr *)&addr, sizeof(addr));
if (error < 0) {
syslog(LOG_ERR, "bind failed; error:%d", error);
syslog(LOG_ERR, "bind failed; error: %d %s", errno, strerror(errno));
close(fd);
exit(EXIT_FAILURE);
}
sock_opt = addr.nl_groups;
setsockopt(fd, 270, 1, &sock_opt, sizeof(sock_opt));
nl_group = CN_KVP_IDX;
if (setsockopt(fd, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP, &nl_group, sizeof(nl_group)) < 0) {
syslog(LOG_ERR, "setsockopt failed; error: %d %s", errno, strerror(errno));
close(fd);
exit(EXIT_FAILURE);
}
/*
* Register ourselves with the kernel.
*/
@ -1470,7 +1492,7 @@ int main(void)
len = netlink_send(fd, message);
if (len < 0) {
syslog(LOG_ERR, "netlink_send failed; error:%d", len);
syslog(LOG_ERR, "netlink_send failed; error: %d %s", errno, strerror(errno));
close(fd);
exit(EXIT_FAILURE);
}
@ -1482,7 +1504,16 @@ int main(void)
socklen_t addr_l = sizeof(addr);
pfd.events = POLLIN;
pfd.revents = 0;
poll(&pfd, 1, -1);
if (poll(&pfd, 1, -1) < 0) {
syslog(LOG_ERR, "poll failed; error: %d %s", errno, strerror(errno));
if (errno == EINVAL) {
close(fd);
exit(EXIT_FAILURE);
}
else
continue;
}
len = recvfrom(fd, kvp_recv_buffer, sizeof(kvp_recv_buffer), 0,
addr_p, &addr_l);
@ -1501,6 +1532,10 @@ int main(void)
}
incoming_msg = (struct nlmsghdr *)kvp_recv_buffer;
if (incoming_msg->nlmsg_type != NLMSG_DONE)
continue;
incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg);
hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data;
@ -1689,7 +1724,8 @@ kvp_done:
len = netlink_send(fd, incoming_cn_msg);
if (len < 0) {
syslog(LOG_ERR, "net_link send failed; error:%d", len);
syslog(LOG_ERR, "net_link send failed; error: %d %s", errno,
strerror(errno));
exit(EXIT_FAILURE);
}
}