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