Blob Blame History Raw
From 2481925ea7fcbac7cc60f511379157afdcbca9c7 Mon Sep 17 00:00:00 2001
From: Pranith Kumar K <pkarampu@redhat.com>
Date: Fri, 23 Sep 2016 21:06:37 +0530
Subject: [PATCH 109/141] storage/posix: Fix race in posix_pstat

Problem:
When one thread is in the process of creating a file/directory
and the other thread is doing readdirp, there is a chance that
posix_pstat, creation fops race in the following manner which
will lead to wrong stat values to be read by parent xlators
like posix-acl.

Creation fops                           posix_pstat() as part of readdirp
1) file is created with uid/gid 0/0     1) does stat of the path that
                                           is created just now.
2) Does chown to set the correct
   uid/gid
3) Sets the acl/user/internal xattrs
4) Sets the gfid on the entry and
   completes the creation of the file/dir
                                        2) fills the gfid in the iatt

If unwind of readdirp hits server xlator before creation fop, then
posix-acl remembers uid/gid of the file to be root/root and fails
fops like open etc on it.

Fix:
Reverse the order of filling gfid and filling lstat() values in
posix_pstat() so that if there is gfid in iatt buffer uid/gid
are valid.

 >Change-Id: I46caa7f6da7abfa40a0b1d70e35b88de9c64959c
 >Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
 >Reviewed-on: http://review.gluster.org/15564
 >NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
 >CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
 >Smoke: Gluster Build System <jenkins@build.gluster.org>
 >Reviewed-by: Shyamsundar Ranganathan <srangana@redhat.com>

BUG: 1339765
Change-Id: Id14a37eb5b71d9d8eb28ae83079047c23ab6f51f
Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/87555
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
Tested-by: Atin Mukherjee <amukherj@redhat.com>
---
 xlators/storage/posix/src/posix-helpers.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c
index 86c3339..2912896 100644
--- a/xlators/storage/posix/src/posix-helpers.c
+++ b/xlators/storage/posix/src/posix-helpers.c
@@ -640,6 +640,11 @@ posix_pstat (xlator_t *this, uuid_t gfid, const char *path,
 
         priv = this->private;
 
+        if (gfid && !gf_uuid_is_null (gfid))
+                gf_uuid_copy (stbuf.ia_gfid, gfid);
+        else
+                posix_fill_gfid_path (this, path, &stbuf);
+
         ret = sys_lstat (path, &lstatbuf);
 
         if (ret != 0) {
@@ -672,11 +677,6 @@ posix_pstat (xlator_t *this, uuid_t gfid, const char *path,
 
         iatt_from_stat (&stbuf, &lstatbuf);
 
-        if (gfid && !gf_uuid_is_null (gfid))
-                gf_uuid_copy (stbuf.ia_gfid, gfid);
-        else
-                posix_fill_gfid_path (this, path, &stbuf);
-
         posix_fill_ino_from_gfid (this, &stbuf);
 
         if (buf_p)
-- 
1.7.1