summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarian Csontos <mcsontos@redhat.com>2014-09-16 17:23:11 +0200
committerMarian Csontos <mcsontos@redhat.com>2014-09-16 17:34:32 +0200
commit05716c2d8a68e5acc698daf1234bed5feb93b743 (patch)
tree204b0a49c21b21e37a9cd6a58f2c14a6f72dec8f
parent4a853361b01feda77031901eb2828c6ecabe760f (diff)
downloadlvm2-dev-mcsontos-clvmd-stack-overflow.tar.gz
clvmd: Fix stack overflow on 64 bit ARMdev-mcsontos-clvmd-stack-overflow
Seems the amount of allocated data on stack is dependent on page size. As the page size on aarch64 is 64kiB writing to memory allocated by alloca results in stack overflow as at the time of allocation the are already 2 pages allocated. Clearly 128kiB is not sufficient and at least 3 pages are needed.
-rw-r--r--daemons/clvmd/clvmd.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/daemons/clvmd/clvmd.c b/daemons/clvmd/clvmd.c
index 9b865f682..0684efbba 100644
--- a/daemons/clvmd/clvmd.c
+++ b/daemons/clvmd/clvmd.c
@@ -24,6 +24,7 @@
#include "clvmd.h"
#include "lvm-functions.h"
#include "lvm-version.h"
+#include "lvm-wrappers.h"
#include "refresh_clvmd.h"
#ifdef HAVE_COROSYNC_CONFDB_H
@@ -88,7 +89,7 @@ static debug_t debug = DEBUG_OFF;
static int foreground_mode = 0;
static pthread_t lvm_thread;
/* Stack size 128KiB for thread, must be bigger then DEFAULT_RESERVED_STACK */
-static const size_t STACK_SIZE = 128 * 1024;
+static const size_t MIN_STACK_SIZE = 128 * 1024;
static pthread_attr_t stack_attr;
static int lvm_thread_exit = 0;
static pthread_mutex_t lvm_thread_mutex;
@@ -358,6 +359,7 @@ int main(int argc, char *argv[])
int clusterwide_opt = 0;
mode_t old_mask;
int ret = 1;
+ size_t stack_size;
struct option longopts[] = {
{ "help", 0, 0, 'h' },
@@ -514,8 +516,10 @@ int main(int argc, char *argv[])
/* Initialise the LVM thread variables */
dm_list_init(&lvm_cmd_head);
+ stack_size = 3 * lvm_getpagesize();
+ stack_size = stack_size < MIN_STACK_SIZE ? MIN_STACK_SIZE : stack_size;
if (pthread_attr_init(&stack_attr) ||
- pthread_attr_setstacksize(&stack_attr, STACK_SIZE)) {
+ pthread_attr_setstacksize(&stack_attr, stack_size)) {
log_sys_error("pthread_attr_init", "");
exit(1);
}