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