summaryrefslogtreecommitdiffstats
path: root/xlators/mount/fuse
diff options
context:
space:
mode:
authorCsaba Henk <csaba@redhat.com>2017-07-05 17:48:37 +0200
committerJeff Darcy <jeff@pl.atyp.us>2017-07-06 18:26:08 +0000
commite14ea3f5c37475e12a3b7fb7bd3165b0a4e77c51 (patch)
tree7ef467ec7fa1761379a101ada475f504c479a42f /xlators/mount/fuse
parentfc73ae5f81ef5926e3dc2311db116250d0f2a321 (diff)
groups: don't allocate auxiliary gid list on stack
When glusterfs wants to retrieve the list of auxiliary gids of a user, it typically allocates a sufficiently big gid_t array on stack and calls getgrouplist(3) with it. However, "sufficiently big" means to be of maximum supported gid list size, which in GlusterFS is GF_MAX_AUX_GROUPS = 64k. That means a 64k * sizeof(gid_t) = 256k allocation, which is big enough to overflow the stack in certain cases. A further observation is that stack allocation of the gid list brings no gain, as in all cases the content of the gid list eventually gets copied over to a heap allocated buffer. So we add a convenience wrapper of getgrouplist to libglusterfs called gf_getgrouplist which calls getgrouplist with a sufficiently big heap allocated buffer (it takes care of the allocation too). We are porting all the getgrouplist invocations to gf_getgrouplist and thus eliminate the huge stack allocation. BUG: 1464327 Change-Id: Icea76d0d74dcf2f87d26cb299acc771ca3b32d2b Signed-off-by: Csaba Henk <csaba@redhat.com> Reviewed-on: https://review.gluster.org/17706 Smoke: Gluster Build System <jenkins@build.gluster.org> Reviewed-by: Niels de Vos <ndevos@redhat.com> Reviewed-by: Amar Tumballi <amarts@redhat.com> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
Diffstat (limited to 'xlators/mount/fuse')
-rw-r--r--xlators/mount/fuse/src/fuse-helpers.c20
1 files changed, 6 insertions, 14 deletions
diff --git a/xlators/mount/fuse/src/fuse-helpers.c b/xlators/mount/fuse/src/fuse-helpers.c
index b65e6ebfc7b..3fc6b16c41f 100644
--- a/xlators/mount/fuse/src/fuse-helpers.c
+++ b/xlators/mount/fuse/src/fuse-helpers.c
@@ -20,7 +20,6 @@
#include <sys/sysctl.h>
#endif
#include <pwd.h>
-#include <grp.h>
#include "fuse-bridge.h"
@@ -158,8 +157,8 @@ frame_fill_groups (call_frame_t *frame)
char *saveptr = NULL;
char *endptr = NULL;
int ret = 0;
- int ngroups = FUSE_MAX_AUX_GROUPS;
- gid_t mygroups[GF_MAX_AUX_GROUPS];
+ int ngroups = 0;
+ gid_t *mygroups = NULL;
if (priv->resolve_gids) {
struct passwd pwent;
@@ -173,23 +172,16 @@ frame_fill_groups (call_frame_t *frame)
return;
}
- ngroups = GF_MAX_AUX_GROUPS;
- if (getgrouplist (result->pw_name, frame->root->gid, mygroups,
- &ngroups) == -1) {
+ ngroups = gf_getgrouplist (result->pw_name, frame->root->gid,
+ &mygroups);
+ if (ngroups == -1) {
gf_log (this->name, GF_LOG_ERROR, "could not map %s to "
"group list (ngroups %d, max %d)",
result->pw_name, ngroups, GF_MAX_AUX_GROUPS);
return;
}
- if (call_stack_alloc_groups (frame->root, ngroups) != 0)
- goto out;
-
- /* Copy data to the frame. */
- for (idx = 0; idx < ngroups; ++idx) {
- frame->root->groups[idx] = mygroups[idx];
- }
- frame->root->ngrps = ngroups;
+ call_stack_set_groups (frame->root, ngroups, mygroups);
} else {
ret = snprintf (filename, sizeof filename, "/proc/%d/status",
frame->root->pid);