|
|
14f8ab |
From 56c8ef4a64506c64aeb95d5a2c38d7107f90ac3a Mon Sep 17 00:00:00 2001
|
|
|
14f8ab |
From: Xavi Hernandez <xhernandez@redhat.com>
|
|
|
14f8ab |
Date: Tue, 5 Feb 2019 16:57:52 +0100
|
|
|
14f8ab |
Subject: [PATCH 442/449] fuse: correctly handle setxattr values
|
|
|
14f8ab |
|
|
|
14f8ab |
The setxattr function receives a pointer to raw data, which may not be
|
|
|
14f8ab |
null-terminated. When this data needs to be interpreted as a string, an
|
|
|
14f8ab |
explicit null termination needs to be added before using the value.
|
|
|
14f8ab |
|
|
|
14f8ab |
Upstream patch https://review.gluster.org/#/c/glusterfs/+/22157
|
|
|
14f8ab |
> Change-Id: Id110f9b215b22786da5782adec9449ce38d0d563
|
|
|
14f8ab |
> updates: bz#1193929
|
|
|
14f8ab |
> Signed-off-by: Xavi Hernandez <xhernandez@redhat.com>
|
|
|
14f8ab |
|
|
|
14f8ab |
Note: this change is not addressing the issue of bz 1787310,
|
|
|
14f8ab |
indeed it is prerequisite for other changes that do.
|
|
|
14f8ab |
|
|
|
14f8ab |
BUG: 1787310
|
|
|
14f8ab |
Change-Id: I56417b130eb2a1f388108456c905a577eb658793
|
|
|
14f8ab |
Signed-off-by: Csaba Henk <csaba@redhat.com>
|
|
|
14f8ab |
Reviewed-on: https://code.engineering.redhat.com/gerrit/202758
|
|
|
14f8ab |
Tested-by: RHGS Build Bot <nigelb@redhat.com>
|
|
|
14f8ab |
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
|
|
|
14f8ab |
---
|
|
|
14f8ab |
libglusterfs/src/glusterfs/xlator.h | 2 +-
|
|
|
14f8ab |
libglusterfs/src/xlator.c | 28 +++++++++++++++++++++++++---
|
|
|
14f8ab |
xlators/mount/fuse/src/fuse-bridge.c | 20 ++++++++++++++++----
|
|
|
14f8ab |
3 files changed, 42 insertions(+), 8 deletions(-)
|
|
|
14f8ab |
|
|
|
14f8ab |
diff --git a/libglusterfs/src/glusterfs/xlator.h b/libglusterfs/src/glusterfs/xlator.h
|
|
|
14f8ab |
index db04c4d..8650ccc 100644
|
|
|
14f8ab |
--- a/libglusterfs/src/glusterfs/xlator.h
|
|
|
14f8ab |
+++ b/libglusterfs/src/glusterfs/xlator.h
|
|
|
14f8ab |
@@ -1043,7 +1043,7 @@ xlator_mem_acct_init(xlator_t *xl, int num_types);
|
|
|
14f8ab |
void
|
|
|
14f8ab |
xlator_mem_acct_unref(struct mem_acct *mem_acct);
|
|
|
14f8ab |
int
|
|
|
14f8ab |
-is_gf_log_command(xlator_t *trans, const char *name, char *value);
|
|
|
14f8ab |
+is_gf_log_command(xlator_t *trans, const char *name, char *value, size_t size);
|
|
|
14f8ab |
int
|
|
|
14f8ab |
glusterd_check_log_level(const char *value);
|
|
|
14f8ab |
int
|
|
|
14f8ab |
diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c
|
|
|
14f8ab |
index 6bd4f09..108b96a 100644
|
|
|
14f8ab |
--- a/libglusterfs/src/xlator.c
|
|
|
14f8ab |
+++ b/libglusterfs/src/xlator.c
|
|
|
14f8ab |
@@ -1278,8 +1278,21 @@ xlator_destroy(xlator_t *xl)
|
|
|
14f8ab |
return 0;
|
|
|
14f8ab |
}
|
|
|
14f8ab |
|
|
|
14f8ab |
+static int32_t
|
|
|
14f8ab |
+gf_bin_to_string(char *dst, size_t size, void *src, size_t len)
|
|
|
14f8ab |
+{
|
|
|
14f8ab |
+ if (len >= size) {
|
|
|
14f8ab |
+ return EINVAL;
|
|
|
14f8ab |
+ }
|
|
|
14f8ab |
+
|
|
|
14f8ab |
+ memcpy(dst, src, len);
|
|
|
14f8ab |
+ dst[len] = 0;
|
|
|
14f8ab |
+
|
|
|
14f8ab |
+ return 0;
|
|
|
14f8ab |
+}
|
|
|
14f8ab |
+
|
|
|
14f8ab |
int
|
|
|
14f8ab |
-is_gf_log_command(xlator_t *this, const char *name, char *value)
|
|
|
14f8ab |
+is_gf_log_command(xlator_t *this, const char *name, char *value, size_t size)
|
|
|
14f8ab |
{
|
|
|
14f8ab |
xlator_t *trav = NULL;
|
|
|
14f8ab |
char key[1024] = {
|
|
|
14f8ab |
@@ -1291,7 +1304,11 @@ is_gf_log_command(xlator_t *this, const char *name, char *value)
|
|
|
14f8ab |
glusterfs_ctx_t *ctx = NULL;
|
|
|
14f8ab |
|
|
|
14f8ab |
if (!strcmp("trusted.glusterfs.syslog", name)) {
|
|
|
14f8ab |
- ret = gf_string2boolean(value, &syslog_flag);
|
|
|
14f8ab |
+ ret = gf_bin_to_string(key, sizeof(key), value, size);
|
|
|
14f8ab |
+ if (ret != 0) {
|
|
|
14f8ab |
+ goto out;
|
|
|
14f8ab |
+ }
|
|
|
14f8ab |
+ ret = gf_string2boolean(key, &syslog_flag);
|
|
|
14f8ab |
if (ret) {
|
|
|
14f8ab |
ret = EOPNOTSUPP;
|
|
|
14f8ab |
goto out;
|
|
|
14f8ab |
@@ -1307,7 +1324,12 @@ is_gf_log_command(xlator_t *this, const char *name, char *value)
|
|
|
14f8ab |
if (fnmatch("trusted.glusterfs*set-log-level", name, FNM_NOESCAPE))
|
|
|
14f8ab |
goto out;
|
|
|
14f8ab |
|
|
|
14f8ab |
- log_level = glusterd_check_log_level(value);
|
|
|
14f8ab |
+ ret = gf_bin_to_string(key, sizeof(key), value, size);
|
|
|
14f8ab |
+ if (ret != 0) {
|
|
|
14f8ab |
+ goto out;
|
|
|
14f8ab |
+ }
|
|
|
14f8ab |
+
|
|
|
14f8ab |
+ log_level = glusterd_check_log_level(key);
|
|
|
14f8ab |
if (log_level == -1) {
|
|
|
14f8ab |
ret = EOPNOTSUPP;
|
|
|
14f8ab |
goto out;
|
|
|
14f8ab |
diff --git a/xlators/mount/fuse/src/fuse-bridge.c b/xlators/mount/fuse/src/fuse-bridge.c
|
|
|
14f8ab |
index 2e7584c..cfad2b4 100644
|
|
|
14f8ab |
--- a/xlators/mount/fuse/src/fuse-bridge.c
|
|
|
14f8ab |
+++ b/xlators/mount/fuse/src/fuse-bridge.c
|
|
|
14f8ab |
@@ -4112,7 +4112,7 @@ fuse_setxattr(xlator_t *this, fuse_in_header_t *finh, void *msg,
|
|
|
14f8ab |
|
|
|
14f8ab |
/* Check if the command is for changing the log
|
|
|
14f8ab |
level of process or specific xlator */
|
|
|
14f8ab |
- ret = is_gf_log_command(this, name, value);
|
|
|
14f8ab |
+ ret = is_gf_log_command(this, name, value, fsi->size);
|
|
|
14f8ab |
if (ret >= 0) {
|
|
|
14f8ab |
op_errno = ret;
|
|
|
14f8ab |
goto done;
|
|
|
14f8ab |
@@ -4159,11 +4159,23 @@ fuse_setxattr(xlator_t *this, fuse_in_header_t *finh, void *msg,
|
|
|
14f8ab |
* fixups to make sure that's the case. To avoid nasty
|
|
|
14f8ab |
* surprises, allocate an extra byte and add a NUL here.
|
|
|
14f8ab |
*/
|
|
|
14f8ab |
- dict_value = memdup(value, fsi->size + 1);
|
|
|
14f8ab |
+ dict_value = GF_MALLOC(fsi->size + 1, gf_common_mt_char);
|
|
|
14f8ab |
+ if (dict_value == NULL) {
|
|
|
14f8ab |
+ gf_log("glusterfs-fuse", GF_LOG_ERROR,
|
|
|
14f8ab |
+ "%" PRIu64 ": SETXATTR value allocation failed",
|
|
|
14f8ab |
+ finh->unique);
|
|
|
14f8ab |
+ op_errno = ENOMEM;
|
|
|
14f8ab |
+ goto done;
|
|
|
14f8ab |
+ }
|
|
|
14f8ab |
+ memcpy(dict_value, value, fsi->size);
|
|
|
14f8ab |
dict_value[fsi->size] = '\0';
|
|
|
14f8ab |
}
|
|
|
14f8ab |
- dict_set(state->xattr, newkey,
|
|
|
14f8ab |
- data_from_dynptr((void *)dict_value, fsi->size));
|
|
|
14f8ab |
+ ret = dict_set_dynptr(state->xattr, newkey, dict_value, fsi->size);
|
|
|
14f8ab |
+ if (ret < 0) {
|
|
|
14f8ab |
+ op_errno = -ret;
|
|
|
14f8ab |
+ GF_FREE(dict_value);
|
|
|
14f8ab |
+ goto done;
|
|
|
14f8ab |
+ }
|
|
|
14f8ab |
|
|
|
14f8ab |
state->flags = fsi->flags;
|
|
|
14f8ab |
state->name = newkey;
|
|
|
14f8ab |
--
|
|
|
14f8ab |
1.8.3.1
|
|
|
14f8ab |
|