14f8ab
From 5893e64ca8c147b7acfa12cd9824f254d53ee261 Mon Sep 17 00:00:00 2001
14f8ab
From: mohit84 <moagrawa@redhat.com>
14f8ab
Date: Wed, 4 Nov 2020 09:02:03 +0530
14f8ab
Subject: [PATCH 496/511] posix: Use MALLOC instead of alloca to allocate
14f8ab
 memory for xattrs list (#1730)
14f8ab
14f8ab
In case of file is having huge xattrs on backend a brick process is
14f8ab
crashed while alloca(size) limit has been crossed 256k because iot_worker
14f8ab
stack size is 256k.
14f8ab
14f8ab
> Fixes: #1699
14f8ab
> Signed-off-by: Mohit Agrawal <moagrawa@redhat.com>
14f8ab
> Change-Id: I100468234f83329a7d65b43cbe4e10450c1ccecd
14f8ab
> (Cherry pick from commit fd666caa35ac84dd1cba55399761982011b77112)
14f8ab
> (Reviewed on upstream link https://github.com/gluster/glusterfs/pull/1828)
14f8ab
14f8ab
Change-Id: I100468234f83329a7d65b43cbe4e10450c1ccecd
14f8ab
Bug: 1903468
14f8ab
Signed-off-by: Mohit Agrawal <moagrawa@redhat.com>
14f8ab
Reviewed-on: https://code.engineering.redhat.com/gerrit/220872
14f8ab
Tested-by: RHGS Build Bot <nigelb@redhat.com>
14f8ab
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
14f8ab
---
14f8ab
 xlators/storage/posix/src/posix-gfid-path.c    |  5 ++++-
14f8ab
 xlators/storage/posix/src/posix-helpers.c      |  3 ++-
14f8ab
 xlators/storage/posix/src/posix-inode-fd-ops.c | 12 +++++++++---
14f8ab
 3 files changed, 15 insertions(+), 5 deletions(-)
14f8ab
14f8ab
diff --git a/xlators/storage/posix/src/posix-gfid-path.c b/xlators/storage/posix/src/posix-gfid-path.c
14f8ab
index 64b5c6c..01315ac 100644
14f8ab
--- a/xlators/storage/posix/src/posix-gfid-path.c
14f8ab
+++ b/xlators/storage/posix/src/posix-gfid-path.c
14f8ab
@@ -195,7 +195,8 @@ posix_get_gfid2path(xlator_t *this, inode_t *inode, const char *real_path,
14f8ab
             if (size == 0)
14f8ab
                 goto done;
14f8ab
         }
14f8ab
-        list = alloca(size);
14f8ab
+
14f8ab
+        list = GF_MALLOC(size, gf_posix_mt_char);
14f8ab
         if (!list) {
14f8ab
             *op_errno = errno;
14f8ab
             goto err;
14f8ab
@@ -309,6 +310,7 @@ done:
14f8ab
             GF_FREE(paths[j]);
14f8ab
     }
14f8ab
     ret = 0;
14f8ab
+    GF_FREE(list);
14f8ab
     return ret;
14f8ab
 err:
14f8ab
     if (path)
14f8ab
@@ -317,5 +319,6 @@ err:
14f8ab
         if (paths[j])
14f8ab
             GF_FREE(paths[j]);
14f8ab
     }
14f8ab
+    GF_FREE(list);
14f8ab
     return ret;
14f8ab
 }
14f8ab
diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c
14f8ab
index 73a44be..ceac52a 100644
14f8ab
--- a/xlators/storage/posix/src/posix-helpers.c
14f8ab
+++ b/xlators/storage/posix/src/posix-helpers.c
14f8ab
@@ -349,7 +349,7 @@ _posix_get_marker_all_contributions(posix_xattr_filler_t *filler)
14f8ab
         goto out;
14f8ab
     }
14f8ab
 
14f8ab
-    list = alloca(size);
14f8ab
+    list = GF_MALLOC(size, gf_posix_mt_char);
14f8ab
     if (!list) {
14f8ab
         goto out;
14f8ab
     }
14f8ab
@@ -379,6 +379,7 @@ _posix_get_marker_all_contributions(posix_xattr_filler_t *filler)
14f8ab
     ret = 0;
14f8ab
 
14f8ab
 out:
14f8ab
+    GF_FREE(list);
14f8ab
     return ret;
14f8ab
 }
14f8ab
 
14f8ab
diff --git a/xlators/storage/posix/src/posix-inode-fd-ops.c b/xlators/storage/posix/src/posix-inode-fd-ops.c
14f8ab
index 21119ea..1d37aed 100644
14f8ab
--- a/xlators/storage/posix/src/posix-inode-fd-ops.c
14f8ab
+++ b/xlators/storage/posix/src/posix-inode-fd-ops.c
14f8ab
@@ -3305,7 +3305,7 @@ posix_get_ancestry_non_directory(xlator_t *this, inode_t *leaf_inode,
14f8ab
         goto out;
14f8ab
     }
14f8ab
 
14f8ab
-    list = alloca(size);
14f8ab
+    list = GF_MALLOC(size, gf_posix_mt_char);
14f8ab
     if (!list) {
14f8ab
         *op_errno = errno;
14f8ab
         goto out;
14f8ab
@@ -3385,6 +3385,7 @@ posix_get_ancestry_non_directory(xlator_t *this, inode_t *leaf_inode,
14f8ab
     op_ret = 0;
14f8ab
 
14f8ab
 out:
14f8ab
+    GF_FREE(list);
14f8ab
     return op_ret;
14f8ab
 }
14f8ab
 
14f8ab
@@ -3810,7 +3811,8 @@ posix_getxattr(call_frame_t *frame, xlator_t *this, loc_t *loc,
14f8ab
         if (size == 0)
14f8ab
             goto done;
14f8ab
     }
14f8ab
-    list = alloca(size);
14f8ab
+
14f8ab
+    list = GF_MALLOC(size, gf_posix_mt_char);
14f8ab
     if (!list) {
14f8ab
         op_errno = errno;
14f8ab
         goto out;
14f8ab
@@ -3937,6 +3939,7 @@ out:
14f8ab
         dict_unref(dict);
14f8ab
     }
14f8ab
 
14f8ab
+    GF_FREE(list);
14f8ab
     return 0;
14f8ab
 }
14f8ab
 
14f8ab
@@ -4136,7 +4139,8 @@ posix_fgetxattr(call_frame_t *frame, xlator_t *this, fd_t *fd, const char *name,
14f8ab
         if (size == 0)
14f8ab
             goto done;
14f8ab
     }
14f8ab
-    list = alloca(size + 1);
14f8ab
+
14f8ab
+    list = GF_MALLOC(size, gf_posix_mt_char);
14f8ab
     if (!list) {
14f8ab
         op_ret = -1;
14f8ab
         op_errno = ENOMEM;
14f8ab
@@ -4240,6 +4244,8 @@ out:
14f8ab
     if (dict)
14f8ab
         dict_unref(dict);
14f8ab
 
14f8ab
+    GF_FREE(list);
14f8ab
+
14f8ab
     return 0;
14f8ab
 }
14f8ab
 
14f8ab
-- 
14f8ab
1.8.3.1
14f8ab