14f8ab
From 7d87933f648092ae55d57a96fd06e3df975d764c Mon Sep 17 00:00:00 2001
14f8ab
From: Ashish Pandey <aspandey@redhat.com>
14f8ab
Date: Tue, 18 Aug 2020 10:33:48 +0530
14f8ab
Subject: [PATCH 463/465] cluster/ec: Change handling of heal failure to avoid
14f8ab
 crash
14f8ab
14f8ab
Problem:
14f8ab
ec_getxattr_heal_cbk was called with NULL as second argument
14f8ab
in case heal was failing.
14f8ab
This function was dereferencing "cookie" argument which caused crash.
14f8ab
14f8ab
Solution:
14f8ab
Cookie is changed to carry the value that was supposed to be
14f8ab
stored in fop->data, so even in the case when fop is NULL in error
14f8ab
case, there won't be any NULL dereference.
14f8ab
14f8ab
Thanks to Xavi for the suggestion about the fix.
14f8ab
14f8ab
>Upstream patch: https://review.gluster.org/#/c/glusterfs/+/23050/
14f8ab
>fixes: bz#1729085
14f8ab
14f8ab
Change-Id: I0798000d5cadb17c3c2fbfa1baf77033ffc2bb8c
14f8ab
BUG: 1852736
14f8ab
Reviewed-on: https://code.engineering.redhat.com/gerrit/209012
14f8ab
Tested-by: Ashish Pandey <aspandey@redhat.com>
14f8ab
Tested-by: RHGS Build Bot <nigelb@redhat.com>
14f8ab
Reviewed-by: Xavi Hernandez Juan <xhernandez@redhat.com>
14f8ab
---
14f8ab
 xlators/cluster/ec/src/ec-heal.c       | 11 ++++++-----
14f8ab
 xlators/cluster/ec/src/ec-inode-read.c |  4 ++--
14f8ab
 2 files changed, 8 insertions(+), 7 deletions(-)
14f8ab
14f8ab
diff --git a/xlators/cluster/ec/src/ec-heal.c b/xlators/cluster/ec/src/ec-heal.c
14f8ab
index 7d25853..6e6948b 100644
14f8ab
--- a/xlators/cluster/ec/src/ec-heal.c
14f8ab
+++ b/xlators/cluster/ec/src/ec-heal.c
14f8ab
@@ -1966,7 +1966,7 @@ ec_manager_heal_block(ec_fop_data_t *fop, int32_t state)
14f8ab
 
14f8ab
         case EC_STATE_REPORT:
14f8ab
             if (fop->cbks.heal) {
14f8ab
-                fop->cbks.heal(fop->req_frame, fop, fop->xl, 0, 0,
14f8ab
+                fop->cbks.heal(fop->req_frame, fop->data, fop->xl, 0, 0,
14f8ab
                                (heal->good | heal->bad), heal->good, heal->bad,
14f8ab
                                0, NULL);
14f8ab
             }
14f8ab
@@ -2022,10 +2022,11 @@ ec_heal_block_done(call_frame_t *frame, void *cookie, xlator_t *this,
14f8ab
                    uintptr_t good, uintptr_t bad, uint32_t pending,
14f8ab
                    dict_t *xdata)
14f8ab
 {
14f8ab
-    ec_fop_data_t *fop = cookie;
14f8ab
-    ec_heal_t *heal = fop->data;
14f8ab
+    ec_heal_t *heal = cookie;
14f8ab
 
14f8ab
-    fop->heal = NULL;
14f8ab
+    if (heal->fop) {
14f8ab
+        heal->fop->heal = NULL;
14f8ab
+    }
14f8ab
     heal->fop = NULL;
14f8ab
     heal->error = op_ret < 0 ? op_errno : 0;
14f8ab
     syncbarrier_wake(heal->data);
14f8ab
@@ -2669,7 +2670,7 @@ ec_heal_do(xlator_t *this, void *data, loc_t *loc, int32_t partial)
14f8ab
 out:
14f8ab
     ec_reset_entry_healing(fop);
14f8ab
     if (fop->cbks.heal) {
14f8ab
-        fop->cbks.heal(fop->req_frame, fop, fop->xl, op_ret, op_errno,
14f8ab
+        fop->cbks.heal(fop->req_frame, fop->data, fop->xl, op_ret, op_errno,
14f8ab
                        ec_char_array_to_mask(participants, ec->nodes),
14f8ab
                        mgood & good, mbad & bad, pending, NULL);
14f8ab
     }
14f8ab
diff --git a/xlators/cluster/ec/src/ec-inode-read.c b/xlators/cluster/ec/src/ec-inode-read.c
14f8ab
index e82e8f6..c50d0ad 100644
14f8ab
--- a/xlators/cluster/ec/src/ec-inode-read.c
14f8ab
+++ b/xlators/cluster/ec/src/ec-inode-read.c
14f8ab
@@ -396,8 +396,8 @@ ec_getxattr_heal_cbk(call_frame_t *frame, void *cookie, xlator_t *xl,
14f8ab
                      uintptr_t good, uintptr_t bad, uint32_t pending,
14f8ab
                      dict_t *xdata)
14f8ab
 {
14f8ab
-    ec_fop_data_t *fop = cookie;
14f8ab
-    fop_getxattr_cbk_t func = fop->data;
14f8ab
+    fop_getxattr_cbk_t func = cookie;
14f8ab
+
14f8ab
     ec_t *ec = xl->private;
14f8ab
     dict_t *dict = NULL;
14f8ab
     char *str;
14f8ab
-- 
14f8ab
1.8.3.1
14f8ab