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