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