|
|
4ae388 |
[PATCH] Multipath: Remove duplicated memset() for multipathd show command.
|
|
|
4ae388 |
[PATCH] multipath-tools: New way to limit the IPC command length.
|
|
|
4ae388 |
[PATCH] multipath-tools: Perform socket client uid check on IPC commands.
|
|
|
4ae388 |
|
|
|
4ae388 |
Signed-off-by: Gris Ge <fge@redhat.com>
|
|
|
4ae388 |
---
|
|
|
4ae388 |
libmultipath/print.c | 10 ----------
|
|
|
4ae388 |
libmultipath/uxsock.c | 38 +++++++++++++++++++++++++++++---------
|
|
|
4ae388 |
libmultipath/uxsock.h | 9 +++++++++
|
|
|
4ae388 |
multipathd/main.c | 15 +++++++++++++--
|
|
|
4ae388 |
multipathd/uxlsnr.c | 31 ++++++++++++++++++++++++++-----
|
|
|
4ae388 |
multipathd/uxlsnr.h | 8 +++++---
|
|
|
4ae388 |
6 files changed, 82 insertions(+), 29 deletions(-)
|
|
|
4ae388 |
|
|
|
4ae388 |
Index: multipath-tools-130222/libmultipath/print.c
|
|
|
4ae388 |
===================================================================
|
|
|
4ae388 |
--- multipath-tools-130222.orig/libmultipath/print.c
|
|
|
4ae388 |
+++ multipath-tools-130222/libmultipath/print.c
|
|
|
4ae388 |
@@ -771,8 +771,6 @@ snprint_multipath_header (char * line, i
|
|
|
4ae388 |
int fwd;
|
|
|
4ae388 |
struct multipath_data * data;
|
|
|
4ae388 |
|
|
|
4ae388 |
- memset(line, 0, len);
|
|
|
4ae388 |
-
|
|
|
4ae388 |
do {
|
|
|
4ae388 |
if (!TAIL)
|
|
|
4ae388 |
break;
|
|
|
4ae388 |
@@ -806,8 +804,6 @@ snprint_multipath (char * line, int len,
|
|
|
4ae388 |
struct multipath_data * data;
|
|
|
4ae388 |
char buff[MAX_FIELD_LEN] = {};
|
|
|
4ae388 |
|
|
|
4ae388 |
- memset(line, 0, len);
|
|
|
4ae388 |
-
|
|
|
4ae388 |
do {
|
|
|
4ae388 |
if (!TAIL)
|
|
|
4ae388 |
break;
|
|
|
4ae388 |
@@ -842,8 +838,6 @@ snprint_path_header (char * line, int le
|
|
|
4ae388 |
int fwd;
|
|
|
4ae388 |
struct path_data * data;
|
|
|
4ae388 |
|
|
|
4ae388 |
- memset(line, 0, len);
|
|
|
4ae388 |
-
|
|
|
4ae388 |
do {
|
|
|
4ae388 |
if (!TAIL)
|
|
|
4ae388 |
break;
|
|
|
4ae388 |
@@ -877,8 +871,6 @@ snprint_path (char * line, int len, char
|
|
|
4ae388 |
struct path_data * data;
|
|
|
4ae388 |
char buff[MAX_FIELD_LEN];
|
|
|
4ae388 |
|
|
|
4ae388 |
- memset(line, 0, len);
|
|
|
4ae388 |
-
|
|
|
4ae388 |
do {
|
|
|
4ae388 |
if (!TAIL)
|
|
|
4ae388 |
break;
|
|
|
4ae388 |
@@ -914,8 +906,6 @@ snprint_pathgroup (char * line, int len,
|
|
|
4ae388 |
struct pathgroup_data * data;
|
|
|
4ae388 |
char buff[MAX_FIELD_LEN];
|
|
|
4ae388 |
|
|
|
4ae388 |
- memset(line, 0, len);
|
|
|
4ae388 |
-
|
|
|
4ae388 |
do {
|
|
|
4ae388 |
if (!TAIL)
|
|
|
4ae388 |
break;
|
|
|
4ae388 |
Index: multipath-tools-130222/libmultipath/uxsock.c
|
|
|
4ae388 |
===================================================================
|
|
|
4ae388 |
--- multipath-tools-130222.orig/libmultipath/uxsock.c
|
|
|
4ae388 |
+++ multipath-tools-130222/libmultipath/uxsock.c
|
|
|
4ae388 |
@@ -20,6 +20,15 @@
|
|
|
4ae388 |
|
|
|
4ae388 |
#include "memory.h"
|
|
|
4ae388 |
#include "uxsock.h"
|
|
|
4ae388 |
+
|
|
|
4ae388 |
+/*
|
|
|
4ae388 |
+ * Code is similar with mpath_recv_reply() with data size limitation
|
|
|
4ae388 |
+ * and debug-able malloc.
|
|
|
4ae388 |
+ * When limit == 0, it means no limit on data size, used for socket client
|
|
|
4ae388 |
+ * to receiving data from multipathd.
|
|
|
4ae388 |
+ */
|
|
|
4ae388 |
+static int _recv_packet(int fd, char **buf, ssize_t limit);
|
|
|
4ae388 |
+
|
|
|
4ae388 |
/*
|
|
|
4ae388 |
* create a unix domain socket and start listening on it
|
|
|
4ae388 |
* return a file descriptor open on the socket
|
|
|
4ae388 |
@@ -95,27 +104,38 @@ int send_packet(int fd, const char *buf)
|
|
|
4ae388 |
return ret;
|
|
|
4ae388 |
}
|
|
|
4ae388 |
|
|
|
4ae388 |
-/*
|
|
|
4ae388 |
- * receive a packet in length prefix format
|
|
|
4ae388 |
- */
|
|
|
4ae388 |
-int recv_packet(int fd, char **buf)
|
|
|
4ae388 |
+static int _recv_packet(int fd, char **buf, ssize_t limit)
|
|
|
4ae388 |
{
|
|
|
4ae388 |
- int err;
|
|
|
4ae388 |
- ssize_t len;
|
|
|
4ae388 |
+ int err = 0;
|
|
|
4ae388 |
+ ssize_t len = 0;
|
|
|
4ae388 |
unsigned int timeout = DEFAULT_REPLY_TIMEOUT;
|
|
|
4ae388 |
|
|
|
4ae388 |
*buf = NULL;
|
|
|
4ae388 |
len = mpath_recv_reply_len(fd, timeout);
|
|
|
4ae388 |
if (len <= 0)
|
|
|
4ae388 |
return len;
|
|
|
4ae388 |
+ if ((limit > 0) && (len > limit))
|
|
|
4ae388 |
+ return -EINVAL;
|
|
|
4ae388 |
(*buf) = MALLOC(len);
|
|
|
4ae388 |
if (!*buf)
|
|
|
4ae388 |
return -ENOMEM;
|
|
|
4ae388 |
err = mpath_recv_reply_data(fd, *buf, len, timeout);
|
|
|
4ae388 |
- if (err) {
|
|
|
4ae388 |
+ if (err != 0) {
|
|
|
4ae388 |
FREE(*buf);
|
|
|
4ae388 |
(*buf) = NULL;
|
|
|
4ae388 |
- return err;
|
|
|
4ae388 |
}
|
|
|
4ae388 |
- return 0;
|
|
|
4ae388 |
+ return err;
|
|
|
4ae388 |
+}
|
|
|
4ae388 |
+
|
|
|
4ae388 |
+/*
|
|
|
4ae388 |
+ * receive a packet in length prefix format
|
|
|
4ae388 |
+ */
|
|
|
4ae388 |
+int recv_packet(int fd, char **buf)
|
|
|
4ae388 |
+{
|
|
|
4ae388 |
+ return _recv_packet(fd, buf, 0 /* no limit */);
|
|
|
4ae388 |
+}
|
|
|
4ae388 |
+
|
|
|
4ae388 |
+int recv_packet_from_client(int fd, char **buf)
|
|
|
4ae388 |
+{
|
|
|
4ae388 |
+ return _recv_packet(fd, buf, _MAX_CMD_LEN);
|
|
|
4ae388 |
}
|
|
|
4ae388 |
Index: multipath-tools-130222/libmultipath/uxsock.h
|
|
|
4ae388 |
===================================================================
|
|
|
4ae388 |
--- multipath-tools-130222.orig/libmultipath/uxsock.h
|
|
|
4ae388 |
+++ multipath-tools-130222/libmultipath/uxsock.h
|
|
|
4ae388 |
@@ -3,3 +3,12 @@ int ux_socket_listen(const char *name);
|
|
|
4ae388 |
int send_packet(int fd, const char *buf);
|
|
|
4ae388 |
int recv_packet(int fd, char **buf);
|
|
|
4ae388 |
size_t write_all(int fd, const void *buf, size_t len);
|
|
|
4ae388 |
+
|
|
|
4ae388 |
+#define _MAX_CMD_LEN 512
|
|
|
4ae388 |
+
|
|
|
4ae388 |
+/*
|
|
|
4ae388 |
+ * Used for receiving socket command from untrusted socket client where data
|
|
|
4ae388 |
+ * size is restricted to 512(_MAX_CMD_LEN) at most.
|
|
|
4ae388 |
+ * Return -EINVAL if data length requested by client exceeded the _MAX_CMD_LEN.
|
|
|
4ae388 |
+ */
|
|
|
4ae388 |
+int recv_packet_from_client(int fd, char **buf);
|
|
|
4ae388 |
Index: multipath-tools-130222/multipathd/main.c
|
|
|
4ae388 |
===================================================================
|
|
|
4ae388 |
--- multipath-tools-130222.orig/multipathd/main.c
|
|
|
4ae388 |
+++ multipath-tools-130222/multipathd/main.c
|
|
|
4ae388 |
@@ -18,6 +18,7 @@
|
|
|
4ae388 |
#include <linux/oom.h>
|
|
|
4ae388 |
#include <libudev.h>
|
|
|
4ae388 |
#include <semaphore.h>
|
|
|
4ae388 |
+#include <stdbool.h>
|
|
|
4ae388 |
#include <mpath_persist.h>
|
|
|
4ae388 |
#include "prioritizers/alua_rtpg.h"
|
|
|
4ae388 |
|
|
|
4ae388 |
@@ -859,7 +860,8 @@ map_discovery (struct vectors * vecs)
|
|
|
4ae388 |
}
|
|
|
4ae388 |
|
|
|
4ae388 |
int
|
|
|
4ae388 |
-uxsock_trigger (char * str, char ** reply, int * len, void * trigger_data)
|
|
|
4ae388 |
+uxsock_trigger (char * str, char ** reply, int * len, bool is_root,
|
|
|
4ae388 |
+ void * trigger_data)
|
|
|
4ae388 |
{
|
|
|
4ae388 |
struct vectors * vecs;
|
|
|
4ae388 |
int r;
|
|
|
4ae388 |
@@ -872,6 +874,15 @@ uxsock_trigger (char * str, char ** repl
|
|
|
4ae388 |
lock(vecs->lock);
|
|
|
4ae388 |
pthread_testcancel();
|
|
|
4ae388 |
|
|
|
4ae388 |
+ if ((str != NULL) && (is_root == false) &&
|
|
|
4ae388 |
+ (strncmp(str, "list", strlen("list")) != 0) &&
|
|
|
4ae388 |
+ (strncmp(str, "show", strlen("show")) != 0)) {
|
|
|
4ae388 |
+ *reply = STRDUP("permission deny: need to be root");
|
|
|
4ae388 |
+ *len = strlen(*reply) + 1;
|
|
|
4ae388 |
+ r = 1;
|
|
|
4ae388 |
+ goto out;
|
|
|
4ae388 |
+ }
|
|
|
4ae388 |
+
|
|
|
4ae388 |
r = parse_cmd(str, reply, len, vecs);
|
|
|
4ae388 |
|
|
|
4ae388 |
if (r > 0) {
|
|
|
4ae388 |
@@ -885,7 +896,7 @@ uxsock_trigger (char * str, char ** repl
|
|
|
4ae388 |
r = 0;
|
|
|
4ae388 |
}
|
|
|
4ae388 |
/* else if (r < 0) leave *reply alone */
|
|
|
4ae388 |
-
|
|
|
4ae388 |
+out:
|
|
|
4ae388 |
lock_cleanup_pop(vecs->lock);
|
|
|
4ae388 |
return r;
|
|
|
4ae388 |
}
|
|
|
4ae388 |
Index: multipath-tools-130222/multipathd/uxlsnr.c
|
|
|
4ae388 |
===================================================================
|
|
|
4ae388 |
--- multipath-tools-130222.orig/multipathd/uxlsnr.c
|
|
|
4ae388 |
+++ multipath-tools-130222/multipathd/uxlsnr.c
|
|
|
4ae388 |
@@ -21,6 +21,7 @@
|
|
|
4ae388 |
#include <sys/un.h>
|
|
|
4ae388 |
#include <sys/poll.h>
|
|
|
4ae388 |
#include <signal.h>
|
|
|
4ae388 |
+#include <stdbool.h>
|
|
|
4ae388 |
#include <checkers.h>
|
|
|
4ae388 |
#include <memory.h>
|
|
|
4ae388 |
#include <debug.h>
|
|
|
4ae388 |
@@ -48,6 +49,23 @@ struct pollfd *polls;
|
|
|
4ae388 |
volatile sig_atomic_t reconfig_sig = 0;
|
|
|
4ae388 |
volatile sig_atomic_t log_reset_sig = 0;
|
|
|
4ae388 |
|
|
|
4ae388 |
+static bool _socket_client_is_root(int fd);
|
|
|
4ae388 |
+
|
|
|
4ae388 |
+static bool _socket_client_is_root(int fd)
|
|
|
4ae388 |
+{
|
|
|
4ae388 |
+ socklen_t len = 0;
|
|
|
4ae388 |
+ struct ucred uc;
|
|
|
4ae388 |
+
|
|
|
4ae388 |
+ len = sizeof(struct ucred);
|
|
|
4ae388 |
+ if ((fd >= 0) &&
|
|
|
4ae388 |
+ (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &uc, &len) == 0) &&
|
|
|
4ae388 |
+ (uc.uid == 0))
|
|
|
4ae388 |
+ return true;
|
|
|
4ae388 |
+
|
|
|
4ae388 |
+ /* Treat error as not root client */
|
|
|
4ae388 |
+ return false;
|
|
|
4ae388 |
+}
|
|
|
4ae388 |
+
|
|
|
4ae388 |
/*
|
|
|
4ae388 |
* handle a new client joining
|
|
|
4ae388 |
*/
|
|
|
4ae388 |
@@ -105,8 +123,7 @@ void uxsock_cleanup(void *arg)
|
|
|
4ae388 |
/*
|
|
|
4ae388 |
* entry point
|
|
|
4ae388 |
*/
|
|
|
4ae388 |
-void * uxsock_listen(int (*uxsock_trigger)(char *, char **, int *, void *),
|
|
|
4ae388 |
- void * trigger_data)
|
|
|
4ae388 |
+void * uxsock_listen(uxsock_trigger_fn uxsock_trigger, void * trigger_data)
|
|
|
4ae388 |
{
|
|
|
4ae388 |
int ux_sock;
|
|
|
4ae388 |
int rlen;
|
|
|
4ae388 |
@@ -171,12 +188,16 @@ void * uxsock_listen(int (*uxsock_trigge
|
|
|
4ae388 |
struct client *next = c->next;
|
|
|
4ae388 |
|
|
|
4ae388 |
if (polls[i].revents & POLLIN) {
|
|
|
4ae388 |
- if (recv_packet(c->fd, &inbuf) != 0) {
|
|
|
4ae388 |
+ if (recv_packet_from_client(c->fd,
|
|
|
4ae388 |
+ &inbuf) != 0) {
|
|
|
4ae388 |
dead_client(c);
|
|
|
4ae388 |
+ } else if (!inbuf) {
|
|
|
4ae388 |
+ condlog(4, "recv_packet_from_client "
|
|
|
4ae388 |
+ "get null request");
|
|
|
4ae388 |
+ continue;
|
|
|
4ae388 |
} else {
|
|
|
4ae388 |
condlog(4, "Got request [%s]", inbuf);
|
|
|
4ae388 |
- uxsock_trigger(inbuf, &reply, &rlen,
|
|
|
4ae388 |
- trigger_data);
|
|
|
4ae388 |
+ uxsock_trigger(inbuf, &reply, &rlen, _socket_client_is_root(c->fd), trigger_data);
|
|
|
4ae388 |
if (reply) {
|
|
|
4ae388 |
if (send_packet(c->fd,
|
|
|
4ae388 |
reply) != 0) {
|
|
|
4ae388 |
Index: multipath-tools-130222/multipathd/uxlsnr.h
|
|
|
4ae388 |
===================================================================
|
|
|
4ae388 |
--- multipath-tools-130222.orig/multipathd/uxlsnr.h
|
|
|
4ae388 |
+++ multipath-tools-130222/multipathd/uxlsnr.h
|
|
|
4ae388 |
@@ -1,9 +1,11 @@
|
|
|
4ae388 |
#ifndef _UXLSNR_H
|
|
|
4ae388 |
#define _UXLSNR_H
|
|
|
4ae388 |
|
|
|
4ae388 |
-void * uxsock_listen(int (*uxsock_trigger)
|
|
|
4ae388 |
- (char *, char **, int *, void *),
|
|
|
4ae388 |
- void * trigger_data);
|
|
|
4ae388 |
+#include <stdbool.h>
|
|
|
4ae388 |
+
|
|
|
4ae388 |
+typedef int (uxsock_trigger_fn)(char *, char **, int *, bool, void *);
|
|
|
4ae388 |
+
|
|
|
4ae388 |
+void *uxsock_listen(uxsock_trigger_fn uxsock_trigger, void * trigger_data);
|
|
|
4ae388 |
|
|
|
4ae388 |
extern volatile sig_atomic_t reconfig_sig;
|
|
|
4ae388 |
extern volatile sig_atomic_t log_reset_sig;
|