- add changes for bug 1984813.

This commit is contained in:
Ian Kent 2021-07-30 14:45:13 +08:00
parent 0bb27b7d95
commit 03cd024ae2
3 changed files with 318 additions and 1 deletions

View File

@ -0,0 +1,187 @@
autofs-5.1.7 - eliminate some more alloca usage
From: Ian Kent <raven@themaw.net>
Quite a bit of the alloca(3) usage has been eliminated over time.
Use malloc(3) for some more cases that might need to allocate a largish
amount of storage.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1 +
modules/lookup_program.c | 11 ++++++++++-
modules/lookup_yp.c | 22 +++++++++++++++++++---
modules/parse_sun.c | 13 +++++++++++--
modules/replicated.c | 15 ++++-----------
5 files changed, 45 insertions(+), 17 deletions(-)
--- autofs-5.1.7.orig/CHANGELOG
+++ autofs-5.1.7/CHANGELOG
@@ -78,6 +78,7 @@
- add missing description of null map option.
- fix nonstrict offset mount fail handling.
- fix concat_options() error handling.
+- eliminate some more alloca usage.
25/01/2021 autofs-5.1.7
- make bind mounts propagation slave by default.
--- autofs-5.1.7.orig/modules/lookup_program.c
+++ autofs-5.1.7/modules/lookup_program.c
@@ -636,7 +636,14 @@ int lookup_mount(struct autofs_point *ap
char *ent = NULL;
if (me->mapent) {
- ent = alloca(strlen(me->mapent) + 1);
+ ent = malloc(strlen(me->mapent) + 1);
+ if (!ent) {
+ char buf[MAX_ERR_BUF];
+ char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
+ error(ap->logopt, MODPREFIX "malloc: %s", estr);
+ cache_unlock(mc);
+ goto out_free;
+ }
strcpy(ent, me->mapent);
}
cache_unlock(mc);
@@ -644,6 +651,8 @@ int lookup_mount(struct autofs_point *ap
ap->entry->current = source;
ret = ctxt->parse->parse_mount(ap, name,
name_len, ent, ctxt->parse->context);
+ if (ent)
+ free(ent);
goto out_free;
} else {
if (IS_MM(me) && !IS_MM_ROOT(me)) {
--- autofs-5.1.7.orig/modules/lookup_yp.c
+++ autofs-5.1.7/modules/lookup_yp.c
@@ -254,7 +254,7 @@ int yp_all_master_callback(int status, c
len = ypkeylen + 1 + vallen + 2;
- buffer = alloca(len);
+ buffer = malloc(len);
if (!buffer) {
error(logopt, MODPREFIX "could not malloc parse buffer");
return 0;
@@ -267,6 +267,8 @@ int yp_all_master_callback(int status, c
master_parse_entry(buffer, timeout, logging, age);
+ free(buffer);
+
return 0;
}
@@ -368,7 +370,12 @@ int yp_all_callback(int status, char *yp
return 0;
}
- mapent = alloca(vallen + 1);
+ mapent = malloc(vallen + 1);
+ if (!mapent) {
+ error(logopt, MODPREFIX "could not malloc mapent buffer");
+ free(key);
+ return 0;
+ }
strncpy(mapent, val, vallen);
*(mapent + vallen) = '\0';
@@ -377,6 +384,7 @@ int yp_all_callback(int status, char *yp
cache_unlock(mc);
free(key);
+ free(mapent);
if (ret == CHE_FAIL)
return -1;
@@ -904,7 +912,14 @@ int lookup_mount(struct autofs_point *ap
}
if (me && (me->source == source || *me->key == '/')) {
mapent_len = strlen(me->mapent);
- mapent = alloca(mapent_len + 1);
+ mapent = malloc(mapent_len + 1);
+ if (!mapent) {
+ char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
+ error(ap->logopt, MODPREFIX "malloc: %s", estr);
+ cache_unlock(mc);
+ free(lkp_key);
+ return NSS_STATUS_TRYAGAIN;
+ }
strcpy(mapent, me->mapent);
}
}
@@ -929,6 +944,7 @@ int lookup_mount(struct autofs_point *ap
ret = ctxt->parse->parse_mount(ap, key, key_len,
mapent, ctxt->parse->context);
+ free(mapent);
if (ret) {
/* Don't update negative cache when re-connecting */
if (ap->flags & MOUNT_FLAG_REMOUNT)
--- autofs-5.1.7.orig/modules/parse_sun.c
+++ autofs-5.1.7/modules/parse_sun.c
@@ -668,9 +668,16 @@ static int sun_mount(struct autofs_point
}
}
+ what = malloc(loclen + 1);
+ if (!what) {
+ char buf[MAX_ERR_BUF];
+ char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
+ error(ap->logopt, MODPREFIX "malloc: %s", estr);
+ return 1;
+ }
+
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
if (!strcmp(fstype, "nfs") || !strcmp(fstype, "nfs4")) {
- what = alloca(loclen + 1);
memcpy(what, loc, loclen);
what[loclen] = '\0';
@@ -709,7 +716,6 @@ static int sun_mount(struct autofs_point
if (!loclen)
what = NULL;
else {
- what = alloca(loclen + 1);
if (*loc == ':') {
loclen--;
memcpy(what, loc + 1, loclen);
@@ -728,6 +734,9 @@ static int sun_mount(struct autofs_point
/* Generic mount routine */
rv = do_mount(ap, root, name, namelen, what, fstype, options);
}
+ if (what)
+ free(what);
+
pthread_setcancelstate(cur_state, NULL);
if (nonstrict && rv)
--- autofs-5.1.7.orig/modules/replicated.c
+++ autofs-5.1.7/modules/replicated.c
@@ -1044,22 +1044,15 @@ done:
static int add_path(struct host *hosts, const char *path, int len)
{
struct host *this;
- char *tmp, *tmp2;
-
- tmp = alloca(len + 1);
- if (!tmp)
- return 0;
-
- strncpy(tmp, path, len);
- tmp[len] = '\0';
+ char *tmp;
this = hosts;
while (this) {
if (!this->path) {
- tmp2 = strdup(tmp);
- if (!tmp2)
+ tmp = strdup(path);
+ if (!tmp)
return 0;
- this->path = tmp2;
+ this->path = tmp;
}
this = this->next;
}

View File

@ -0,0 +1,120 @@
autofs-5.1.7 - use default stack size for threads
From: Ian Kent <raven@themaw.net>
autofs uses PTHREAD_STACK_MIN to set the stack size for threads it
creates.
In two cases it is used to reduce the stack size for long running
service threads while it's used to allocate a larger stack for worker
threads that can have larger memory requirements.
In recent glibc releases PTHREAD_STACK_MIN is no longer a constant
which can lead to unexpectedly different stack sizes on different
architectures and the autofs assumption it's a constant causes a
compile failure.
The need to alter the stack size was due to observed stack overflow
which was thought to be due the thread stack being too small for autofs
and glibc alloca(3) usage.
Quite a bit of that alloca(3) usage has been eliminated from autofs now,
particularly those that might be allocating largish amounts of storage,
and there has been a lot of change in glibc too so using the thread
default stack should be ok.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1 +
daemon/automount.c | 29 -----------------------------
daemon/state.c | 6 +-----
lib/alarm.c | 6 +-----
4 files changed, 3 insertions(+), 39 deletions(-)
--- autofs-5.1.7.orig/CHANGELOG
+++ autofs-5.1.7/CHANGELOG
@@ -79,6 +79,7 @@
- fix nonstrict offset mount fail handling.
- fix concat_options() error handling.
- eliminate some more alloca usage.
+- use default stack size for threads.
25/01/2021 autofs-5.1.7
- make bind mounts propagation slave by default.
--- autofs-5.1.7.orig/daemon/automount.c
+++ autofs-5.1.7/daemon/automount.c
@@ -84,7 +84,6 @@ static size_t kpkt_len;
/* Attributes for creating detached and joinable threads */
pthread_attr_t th_attr;
pthread_attr_t th_attr_detached;
-size_t detached_thread_stack_size = PTHREAD_STACK_MIN * 144;
struct master_readmap_cond mrc = {
PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0, NULL, 0, 0, 0, 0};
@@ -2614,34 +2613,6 @@ int main(int argc, char *argv[])
if (start_pipefd[1] != -1) {
res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat));
close(start_pipefd[1]);
- }
- release_flag_file();
- macro_free_global_table();
- exit(1);
- }
-
-#ifdef _POSIX_THREAD_ATTR_STACKSIZE
- if (pthread_attr_setstacksize(
- &th_attr_detached, detached_thread_stack_size)) {
- logerr("%s: failed to set stack size thread attribute!",
- program);
- if (start_pipefd[1] != -1) {
- res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat));
- close(start_pipefd[1]);
- }
- release_flag_file();
- macro_free_global_table();
- exit(1);
- }
-#endif
-
- if (pthread_attr_getstacksize(
- &th_attr_detached, &detached_thread_stack_size)) {
- logerr("%s: failed to get detached thread stack size!",
- program);
- if (start_pipefd[1] != -1) {
- res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat));
- close(start_pipefd[1]);
}
release_flag_file();
macro_free_global_table();
--- autofs-5.1.7.orig/daemon/state.c
+++ autofs-5.1.7/daemon/state.c
@@ -1177,12 +1177,8 @@ int st_start_handler(void)
status = pthread_attr_init(pattrs);
if (status)
pattrs = NULL;
- else {
+ else
pthread_attr_setdetachstate(pattrs, PTHREAD_CREATE_DETACHED);
-#ifdef _POSIX_THREAD_ATTR_STACKSIZE
- pthread_attr_setstacksize(pattrs, PTHREAD_STACK_MIN*4);
-#endif
- }
status = pthread_create(&thid, pattrs, st_queue_handler, NULL);
--- autofs-5.1.7.orig/lib/alarm.c
+++ autofs-5.1.7/lib/alarm.c
@@ -270,12 +270,8 @@ int alarm_start_handler(void)
status = pthread_attr_init(pattrs);
if (status)
pattrs = NULL;
- else {
+ else
pthread_attr_setdetachstate(pattrs, PTHREAD_CREATE_DETACHED);
-#ifdef _POSIX_THREAD_ATTR_STACKSIZE
- pthread_attr_setstacksize(pattrs, PTHREAD_STACK_MIN*4);
-#endif
- }
status = pthread_condattr_init(&condattrs);
if (status)

View File

@ -12,7 +12,7 @@
Summary: A tool for automatically mounting and unmounting filesystems
Name: autofs
Version: 5.1.7
Release: 21%{?dist}
Release: 22%{?dist}
Epoch: 1
License: GPLv2+
Source: https://www.kernel.org/pub/linux/daemons/autofs/v5/autofs-%{version}-2.tar.gz
@ -99,6 +99,8 @@ Patch76: autofs-5.1.7-fix-lookup_prune_one_cache-refactoring-change.patch
Patch77: autofs-5.1.7-add-missing-description-of-null-map-option.patch
Patch78: autofs-5.1.7-fix-nonstrict-offset-mount-fail-handling.patch
Patch79: autofs-5.1.7-fix-concat_options-error-handling.patch
Patch80: autofs-5.1.7-eliminate-some-more-alloca-usage.patch
Patch81: autofs-5.1.7-use-default-stack-size-for-threads.patch
%if %{with_systemd}
BuildRequires: systemd-units
@ -244,6 +246,8 @@ echo %{version}-%{release} > .version
%patch77 -p1
%patch78 -p1
%patch79 -p1
%patch80 -p1
%patch81 -p1
%build
LDFLAGS=-Wl,-z,now
@ -352,6 +356,12 @@ fi
%dir /etc/auto.master.d
%changelog
* Fri Jul 30 2021 Ian Kent <ikent@redhat.com> - 1:5.1.7-22
- bz1984813 - autofs: FTBFS due to dynamic PTHREAD_STACK_MIN (glibc 2.34 related)
- eliminate some more alloca usage.
- use default stack size for threads.
- Resolves: rhbz#1984813
* Fri Jul 02 2021 Ian Kent <ikent@redhat.com> - 1:5.1.7-21
- bz1938682 - review of important potential issues detected by static analyzers
in autofs-5.1.7-2.el9