a3470f
From 11ae607a1c958f166e689bacf00acbae989c4d8e Mon Sep 17 00:00:00 2001
a3470f
From: Amar Tumballi <amarts@redhat.com>
a3470f
Date: Thu, 9 Aug 2018 13:00:01 +0530
a3470f
Subject: [PATCH 349/351] posix: don't allow '../' path in 'name'
a3470f
a3470f
This will prevent any arbitrary file creation through glusterfs
a3470f
by modifying the client bits.
a3470f
a3470f
BUG: 1613686
a3470f
BUG: 1613685
a3470f
BUG: 1613684
a3470f
a3470f
Change-Id: I6def64956d9e5541e7f70a8910a4d6ce4bde61e9
a3470f
Signed-off-by: Amar Tumballi <amarts@redhat.com>
a3470f
Reviewed-on: https://code.engineering.redhat.com/gerrit/146548
a3470f
Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
a3470f
Reviewed-by: Nithya Balachandran <nbalacha@redhat.com>
a3470f
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
a3470f
---
a3470f
 xlators/protocol/server/src/server-resolve.c | 12 ++++++++++++
a3470f
 xlators/storage/posix/src/posix-handle.h     |  5 +++++
a3470f
 2 files changed, 17 insertions(+)
a3470f
a3470f
diff --git a/xlators/protocol/server/src/server-resolve.c b/xlators/protocol/server/src/server-resolve.c
a3470f
index 6ffb909..b3eda0e 100644
a3470f
--- a/xlators/protocol/server/src/server-resolve.c
a3470f
+++ b/xlators/protocol/server/src/server-resolve.c
a3470f
@@ -311,6 +311,18 @@ resolve_entry_simple (call_frame_t *frame)
a3470f
         /* expected @parent was found from the inode cache */
a3470f
         gf_uuid_copy (state->loc_now->pargfid, resolve->pargfid);
a3470f
         state->loc_now->parent = inode_ref (parent);
a3470f
+
a3470f
+        if (strstr (resolve->bname, "../")) {
a3470f
+                /* Resolving outside the parent's tree is not allowed */
a3470f
+                gf_msg (this->name, GF_LOG_ERROR, EPERM,
a3470f
+                        PS_MSG_GFID_RESOLVE_FAILED,
a3470f
+                        "%s: path sent by client not allowed",
a3470f
+                        resolve->bname);
a3470f
+                resolve->op_ret   = -1;
a3470f
+                resolve->op_errno = EPERM;
a3470f
+                ret = 1;
a3470f
+                goto out;
a3470f
+        }
a3470f
         state->loc_now->name = resolve->bname;
a3470f
 
a3470f
         inode = inode_grep (state->itable, parent, resolve->bname);
a3470f
diff --git a/xlators/storage/posix/src/posix-handle.h b/xlators/storage/posix/src/posix-handle.h
a3470f
index cb1f84e..a0f82ec 100644
a3470f
--- a/xlators/storage/posix/src/posix-handle.h
a3470f
+++ b/xlators/storage/posix/src/posix-handle.h
a3470f
@@ -223,6 +223,11 @@
a3470f
                 break;                                                  \
a3470f
         }                                                               \
a3470f
                                                                         \
a3470f
+        if (strstr (loc->name, "../")) {                                \
a3470f
+                gf_msg (this->name, GF_LOG_ERROR, 0, P_MSG_ENTRY_HANDLE_CREATE, \
a3470f
+                        "'../' in name not allowed: (%s)", loc->name); \
a3470f
+                break;                                                  \
a3470f
+        }                                                               \
a3470f
         if (LOC_HAS_ABSPATH (loc)) {                                    \
a3470f
                 MAKE_REAL_PATH (entp, this, loc->path);                 \
a3470f
                 __parp = strdupa (entp);                                \
a3470f
-- 
a3470f
1.8.3.1
a3470f