190130
From cddd253c5e3f0a7c3b91c35cea8ad1921cb43b98 Mon Sep 17 00:00:00 2001
190130
From: Kinglong Mee <kinglongmee@gmail.com>
190130
Date: Thu, 18 Jul 2019 11:43:01 +0800
190130
Subject: [PATCH 454/456] features/locks: avoid use after freed of frame for
190130
 blocked lock
190130
190130
The fop contains blocked lock may use freed frame info when other
190130
unlock fop has unwind the blocked lock.
190130
190130
Because the blocked lock is added to block list in inode lock(or
190130
other lock), after that, when out of the inode lock, the fop
190130
contains the blocked lock should not use it.
190130
190130
Upstream Patch - https://review.gluster.org/#/c/glusterfs/+/23155/
190130
190130
>Change-Id: Icb309a1cc78380dc982b26d50c18d67e4f2c8915
190130
>fixes: bz#1737291
190130
>Signed-off-by: Kinglong Mee <mijinlong@horiscale.com>
190130
190130
Change-Id: Icb309a1cc78380dc982b26d50c18d67e4f2c8915
190130
BUG: 1812789
190130
Reviewed-on: https://code.engineering.redhat.com/gerrit/206465
190130
Tested-by: RHGS Build Bot <nigelb@redhat.com>
190130
Reviewed-by: Xavi Hernandez Juan <xhernandez@redhat.com>
190130
---
190130
 xlators/features/locks/src/common.c    | 4 ++++
190130
 xlators/features/locks/src/entrylk.c   | 4 ++--
190130
 xlators/features/locks/src/inodelk.c   | 7 +++++--
190130
 xlators/features/locks/src/posix.c     | 5 +++--
190130
 xlators/features/locks/src/reservelk.c | 2 --
190130
 5 files changed, 14 insertions(+), 8 deletions(-)
190130
190130
diff --git a/xlators/features/locks/src/common.c b/xlators/features/locks/src/common.c
190130
index 6e7fb4b..1406e70 100644
190130
--- a/xlators/features/locks/src/common.c
190130
+++ b/xlators/features/locks/src/common.c
190130
@@ -1080,6 +1080,10 @@ pl_setlk(xlator_t *this, pl_inode_t *pl_inode, posix_lock_t *lock,
190130
                    lock->fl_type == F_UNLCK ? "Unlock" : "Lock",
190130
                    lock->client_pid, lkowner_utoa(&lock->owner),
190130
                    lock->user_flock.l_start, lock->user_flock.l_len);
190130
+
190130
+            pl_trace_block(this, lock->frame, NULL, NULL, F_SETLKW,
190130
+                           &lock->user_flock, NULL);
190130
+
190130
             lock->blocked = 1;
190130
             __insert_lock(pl_inode, lock);
190130
             ret = -1;
190130
diff --git a/xlators/features/locks/src/entrylk.c b/xlators/features/locks/src/entrylk.c
190130
index ced5eca..93c649c 100644
190130
--- a/xlators/features/locks/src/entrylk.c
190130
+++ b/xlators/features/locks/src/entrylk.c
190130
@@ -552,6 +552,8 @@ __lock_blocked_add(xlator_t *this, pl_inode_t *pinode, pl_dom_list_t *dom,
190130
     gf_msg_trace(this->name, 0, "Blocking lock: {pinode=%p, basename=%s}",
190130
                  pinode, lock->basename);
190130
 
190130
+    entrylk_trace_block(this, lock->frame, NULL, NULL, NULL, lock->basename,
190130
+                        ENTRYLK_LOCK, lock->type);
190130
 out:
190130
     return -EAGAIN;
190130
 }
190130
@@ -932,8 +934,6 @@ out:
190130
                           op_ret, op_errno);
190130
     unwind:
190130
         STACK_UNWIND_STRICT(entrylk, frame, op_ret, op_errno, NULL);
190130
-    } else {
190130
-        entrylk_trace_block(this, frame, volume, fd, loc, basename, cmd, type);
190130
     }
190130
 
190130
     if (pcontend != NULL) {
190130
diff --git a/xlators/features/locks/src/inodelk.c b/xlators/features/locks/src/inodelk.c
190130
index a9c42f1..24dee49 100644
190130
--- a/xlators/features/locks/src/inodelk.c
190130
+++ b/xlators/features/locks/src/inodelk.c
190130
@@ -420,6 +420,8 @@ __lock_blocked_add(xlator_t *this, pl_dom_list_t *dom, pl_inode_lock_t *lock,
190130
                  lkowner_utoa(&lock->owner), lock->user_flock.l_start,
190130
                  lock->user_flock.l_len);
190130
 
190130
+    pl_trace_block(this, lock->frame, NULL, NULL, F_SETLKW, &lock->user_flock,
190130
+                   lock->volume);
190130
 out:
190130
     return -EAGAIN;
190130
 }
190130
@@ -959,6 +961,7 @@ pl_common_inodelk(call_frame_t *frame, xlator_t *this, const char *volume,
190130
     int ret = -1;
190130
     GF_UNUSED int dict_ret = -1;
190130
     int can_block = 0;
190130
+    short lock_type = 0;
190130
     pl_inode_t *pinode = NULL;
190130
     pl_inode_lock_t *reqlock = NULL;
190130
     pl_dom_list_t *dom = NULL;
190130
@@ -1024,13 +1027,13 @@ pl_common_inodelk(call_frame_t *frame, xlator_t *this, const char *volume,
190130
             /* fall through */
190130
 
190130
         case F_SETLK:
190130
+            lock_type = flock->l_type;
190130
             memcpy(&reqlock->user_flock, flock, sizeof(struct gf_flock));
190130
             ret = pl_inode_setlk(this, ctx, pinode, reqlock, can_block, dom,
190130
                                  inode);
190130
 
190130
             if (ret < 0) {
190130
-                if ((can_block) && (F_UNLCK != flock->l_type)) {
190130
-                    pl_trace_block(this, frame, fd, loc, cmd, flock, volume);
190130
+                if ((can_block) && (F_UNLCK != lock_type)) {
190130
                     goto out;
190130
                 }
190130
                 gf_log(this->name, GF_LOG_TRACE, "returning EAGAIN");
190130
diff --git a/xlators/features/locks/src/posix.c b/xlators/features/locks/src/posix.c
190130
index 50f1265..7887b82 100644
190130
--- a/xlators/features/locks/src/posix.c
190130
+++ b/xlators/features/locks/src/posix.c
190130
@@ -2557,6 +2557,7 @@ pl_lk(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t cmd,
190130
     uint32_t lk_flags = 0;
190130
     posix_locks_private_t *priv = this->private;
190130
     pl_local_t *local = NULL;
190130
+    short lock_type = 0;
190130
 
190130
     int ret = dict_get_uint32(xdata, GF_LOCK_MODE, &lk_flags);
190130
     if (ret == 0) {
190130
@@ -2701,6 +2702,7 @@ pl_lk(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t cmd,
190130
         case F_SETLK:
190130
             reqlock->frame = frame;
190130
             reqlock->this = this;
190130
+            lock_type = flock->l_type;
190130
 
190130
             pthread_mutex_lock(&pl_inode->mutex);
190130
             {
190130
@@ -2738,8 +2740,7 @@ pl_lk(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t cmd,
190130
 
190130
             ret = pl_setlk(this, pl_inode, reqlock, can_block);
190130
             if (ret == -1) {
190130
-                if ((can_block) && (F_UNLCK != flock->l_type)) {
190130
-                    pl_trace_block(this, frame, fd, NULL, cmd, flock, NULL);
190130
+                if ((can_block) && (F_UNLCK != lock_type)) {
190130
                     goto out;
190130
                 }
190130
                 gf_log(this->name, GF_LOG_DEBUG, "returning EAGAIN");
190130
diff --git a/xlators/features/locks/src/reservelk.c b/xlators/features/locks/src/reservelk.c
190130
index 51076d7..604691f 100644
190130
--- a/xlators/features/locks/src/reservelk.c
190130
+++ b/xlators/features/locks/src/reservelk.c
190130
@@ -312,8 +312,6 @@ grant_blocked_lock_calls(xlator_t *this, pl_inode_t *pl_inode)
190130
         ret = pl_setlk(this, pl_inode, lock, can_block);
190130
         if (ret == -1) {
190130
             if (can_block) {
190130
-                pl_trace_block(this, lock->frame, fd, NULL, cmd,
190130
-                               &lock->user_flock, NULL);
190130
                 continue;
190130
             } else {
190130
                 gf_log(this->name, GF_LOG_DEBUG, "returning EAGAIN");
190130
-- 
190130
1.8.3.1
190130