|
|
786c6d |
From 1fa1b51356c0ea6e1d30f2d370b3b766d4230537 Mon Sep 17 00:00:00 2001
|
|
|
786c6d |
From: Mike Christie <michaelc@cs.wisc.edu>
|
|
|
786c6d |
Date: Thu, 5 Dec 2013 18:12:32 -0600
|
|
|
786c6d |
Subject: [PATCH] iscsi tools: Bug fix on IPC address copy (version 2)
|
|
|
786c6d |
|
|
|
786c6d |
This patch merges Yufei Ren <yufei.ren@stonybrook.edu> patch
|
|
|
786c6d |
with comments from the list plus what I think is a bug in the
|
|
|
786c6d |
addr_len usage.
|
|
|
786c6d |
|
|
|
786c6d |
For the addr_len use, it looks like we were using that as the
|
|
|
786c6d |
arg to memcpy, but that value included the length of the pathname
|
|
|
786c6d |
string and also the offset of sun_path in the sockaddr_un and so
|
|
|
786c6d |
that is too long.
|
|
|
786c6d |
---
|
|
|
786c6d |
usr/iscsi_util.c | 12 ++++++++++++
|
|
|
786c6d |
usr/iscsi_util.h | 3 +++
|
|
|
786c6d |
usr/iscsid_req.c | 7 +------
|
|
|
786c6d |
usr/mgmt_ipc.c | 6 +-----
|
|
|
786c6d |
4 files changed, 17 insertions(+), 11 deletions(-)
|
|
|
786c6d |
|
|
|
786c6d |
diff --git a/usr/iscsi_util.c b/usr/iscsi_util.c
|
|
|
786c6d |
index ac86847..9dbfbfd 100644
|
|
|
786c6d |
--- a/usr/iscsi_util.c
|
|
|
786c6d |
+++ b/usr/iscsi_util.c
|
|
|
786c6d |
@@ -25,16 +25,28 @@
|
|
|
786c6d |
#include <string.h>
|
|
|
786c6d |
#include <errno.h>
|
|
|
786c6d |
#include <ctype.h>
|
|
|
786c6d |
+#include <sys/socket.h>
|
|
|
786c6d |
+#include <sys/un.h>
|
|
|
786c6d |
#include <sys/types.h>
|
|
|
786c6d |
#include <sys/stat.h>
|
|
|
786c6d |
#include <sys/resource.h>
|
|
|
786c6d |
|
|
|
786c6d |
+#include "sysdeps.h"
|
|
|
786c6d |
#include "log.h"
|
|
|
786c6d |
#include "iscsi_settings.h"
|
|
|
786c6d |
#include "iface.h"
|
|
|
786c6d |
#include "session_info.h"
|
|
|
786c6d |
#include "iscsi_util.h"
|
|
|
786c6d |
|
|
|
786c6d |
+int setup_abstract_addr(struct sockaddr_un *addr, char *unix_sock_name)
|
|
|
786c6d |
+{
|
|
|
786c6d |
+ memset(addr, 0, sizeof(*addr));
|
|
|
786c6d |
+ addr->sun_family = AF_LOCAL;
|
|
|
786c6d |
+ strlcpy(addr->sun_path + 1, unix_sock_name, sizeof(addr->sun_path) - 1);
|
|
|
786c6d |
+ return offsetof(struct sockaddr_un, sun_path) +
|
|
|
786c6d |
+ strlen(addr->sun_path + 1) + 1;
|
|
|
786c6d |
+}
|
|
|
786c6d |
+
|
|
|
786c6d |
void daemon_init(void)
|
|
|
786c6d |
{
|
|
|
786c6d |
int fd;
|
|
|
786c6d |
diff --git a/usr/iscsi_util.h b/usr/iscsi_util.h
|
|
|
786c6d |
index 110dfa8..ff725eb 100644
|
|
|
786c6d |
--- a/usr/iscsi_util.h
|
|
|
786c6d |
+++ b/usr/iscsi_util.h
|
|
|
786c6d |
@@ -26,4 +26,7 @@ extern int __iscsi_match_session(struct node_rec *rec, char *targetname,
|
|
|
786c6d |
extern char *strstrip(char *s);
|
|
|
786c6d |
extern char *cfg_get_string_param(char *pathname, const char *key);
|
|
|
786c6d |
|
|
|
786c6d |
+struct sockaddr_un;
|
|
|
786c6d |
+extern int setup_abstract_addr(struct sockaddr_un *addr, char *unix_sock_name);
|
|
|
786c6d |
+
|
|
|
786c6d |
#endif
|
|
|
786c6d |
diff --git a/usr/iscsid_req.c b/usr/iscsid_req.c
|
|
|
786c6d |
index 715c0aa..0e91dee 100644
|
|
|
786c6d |
--- a/usr/iscsid_req.c
|
|
|
786c6d |
+++ b/usr/iscsid_req.c
|
|
|
786c6d |
@@ -67,12 +67,7 @@ static int ipc_connect(int *fd, char *unix_sock_name, int start_iscsid)
|
|
|
786c6d |
return ISCSI_ERR_ISCSID_NOTCONN;
|
|
|
786c6d |
}
|
|
|
786c6d |
|
|
|
786c6d |
- addr_len = offsetof(struct sockaddr_un, sun_path) + strlen(unix_sock_name) + 1;
|
|
|
786c6d |
-
|
|
|
786c6d |
- memset(&addr, 0, sizeof(addr));
|
|
|
786c6d |
- addr.sun_family = AF_LOCAL;
|
|
|
786c6d |
- memcpy((char *) &addr.sun_path + 1, unix_sock_name,
|
|
|
786c6d |
- strlen(unix_sock_name));
|
|
|
786c6d |
+ addr_len = setup_abstract_addr(&addr, unix_sock_name);
|
|
|
786c6d |
|
|
|
786c6d |
/*
|
|
|
786c6d |
* Trying to connect with exponential backoff
|
|
|
786c6d |
diff --git a/usr/mgmt_ipc.c b/usr/mgmt_ipc.c
|
|
|
786c6d |
index 87bd346..a82c063 100644
|
|
|
786c6d |
--- a/usr/mgmt_ipc.c
|
|
|
786c6d |
+++ b/usr/mgmt_ipc.c
|
|
|
786c6d |
@@ -59,11 +59,7 @@ mgmt_ipc_listen(void)
|
|
|
786c6d |
return fd;
|
|
|
786c6d |
}
|
|
|
786c6d |
|
|
|
786c6d |
- addr_len = offsetof(struct sockaddr_un, sun_path) + strlen(ISCSIADM_NAMESPACE) + 1;
|
|
|
786c6d |
-
|
|
|
786c6d |
- memset(&addr, 0, sizeof(addr));
|
|
|
786c6d |
- addr.sun_family = AF_LOCAL;
|
|
|
786c6d |
- memcpy((char *) &addr.sun_path + 1, ISCSIADM_NAMESPACE, addr_len);
|
|
|
786c6d |
+ addr_len = setup_abstract_addr(&addr, ISCSIADM_NAMESPACE);
|
|
|
786c6d |
|
|
|
786c6d |
if ((err = bind(fd, (struct sockaddr *) &addr, addr_len)) < 0 ) {
|
|
|
786c6d |
log_error("Can not bind IPC socket");
|
|
|
786c6d |
--
|
|
|
786c6d |
1.8.3.1
|
|
|
786c6d |
|