887953
From d5c5cbe82ef0f7bf8686e71cf08b92e7baf62f55 Mon Sep 17 00:00:00 2001
887953
From: Ravishankar N <ravishankar@redhat.com>
887953
Date: Sat, 6 Oct 2018 00:50:53 +0530
887953
Subject: [PATCH 395/399] index: prevent arbitrary file creation outside
887953
 entry-changes folder
887953
887953
Problem:
887953
A compromised client can set arbitrary values for the GF_XATTROP_ENTRY_IN_KEY
887953
and GF_XATTROP_ENTRY_OUT_KEY during xattrop fop. These values are
887953
consumed by index as a filename to be created/deleted according to the key.
887953
Thus it is possible to create/delete random files even outside the gluster
887953
volume boundary.
887953
887953
Fix:
887953
Index expects the filename to be a basename, i.e. it must not contain any
887953
pathname components like "/" or "../". Enforce this.
887953
887953
Fixes: CVE-2018-14654
887953
BUG: 1634671
887953
Change-Id: Ib01c35414c36e3101af9e99a1ea17535ef8bd3b3
887953
Signed-off-by: Ravishankar N <ravishankar@redhat.com>
887953
Reviewed-on: https://code.engineering.redhat.com/gerrit/151985
887953
Reviewed-by: Amar Tumballi <amarts@redhat.com>
887953
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
887953
---
887953
 xlators/features/index/src/index.c | 19 +++++++++++++++++++
887953
 1 file changed, 19 insertions(+)
887953
887953
diff --git a/xlators/features/index/src/index.c b/xlators/features/index/src/index.c
887953
index bf3f4dd..89cdbda 100644
887953
--- a/xlators/features/index/src/index.c
887953
+++ b/xlators/features/index/src/index.c
887953
@@ -852,6 +852,15 @@ index_entry_create (xlator_t *this, inode_t *inode, char *filename)
887953
                 ctx->state[ENTRY_CHANGES] = IN;
887953
         }
887953
 
887953
+        if  (strchr (filename, '/')) {
887953
+                gf_msg (this->name, GF_LOG_ERROR, EINVAL,
887953
+                        INDEX_MSG_INDEX_ADD_FAILED,
887953
+                        "Got invalid entry (%s) for pargfid path (%s)",
887953
+                        filename, pgfid_path);
887953
+                op_errno = EINVAL;
887953
+                goto out;
887953
+        }
887953
+
887953
         op_errno = 0;
887953
 
887953
         snprintf (entry_path, sizeof(entry_path), "%s/%s", pgfid_path,
887953
@@ -886,6 +895,16 @@ index_entry_delete (xlator_t *this, uuid_t pgfid, char *filename)
887953
 
887953
         make_gfid_path (priv->index_basepath, ENTRY_CHANGES_SUBDIR, pgfid,
887953
                         pgfid_path, sizeof (pgfid_path));
887953
+
887953
+        if  (strchr (filename, '/')) {
887953
+                gf_msg (this->name, GF_LOG_ERROR, EINVAL,
887953
+                        INDEX_MSG_INDEX_DEL_FAILED,
887953
+                        "Got invalid entry (%s) for pargfid path (%s)",
887953
+                        filename, pgfid_path);
887953
+                op_errno = EINVAL;
887953
+                goto out;
887953
+        }
887953
+
887953
         snprintf (entry_path, sizeof(entry_path), "%s/%s", pgfid_path,
887953
                   filename);
887953
 
887953
-- 
887953
1.8.3.1
887953