- add changes for bug 2210899.

This commit is contained in:
Ian Kent 2023-06-16 08:13:26 +08:00
parent 149ba18839
commit e19dbd77a6
22 changed files with 3486 additions and 1 deletions

View File

@ -0,0 +1,104 @@
autofs-5.1.7 - add buffer length checks to autofs mount_mount()
From: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1
modules/mount_autofs.c | 59 +++++++++++++++++++++++++++++++++----------------
2 files changed, 41 insertions(+), 19 deletions(-)
--- autofs-5.1.7.orig/CHANGELOG
+++ autofs-5.1.7/CHANGELOG
@@ -138,6 +138,7 @@
- fix amd selector function matching.
- get rid entry thid field.
- continue expire immediately after submount check.
+- add buffer length checks to autofs mount_mount().
25/01/2021 autofs-5.1.7
- make bind mounts propagation slave by default.
--- autofs-5.1.7.orig/modules/mount_autofs.c
+++ autofs-5.1.7/modules/mount_autofs.c
@@ -50,8 +50,8 @@ int mount_mount(struct autofs_point *ap,
{
struct startup_cond suc;
pthread_t thid;
- char realpath[PATH_MAX];
- char mountpoint[PATH_MAX];
+ char realpath[PATH_MAX + 1];
+ char mountpoint[PATH_MAX + 1];
const char **argv;
int argc, status;
int nobind = ap->flags & MOUNT_FLAG_NOBIND;
@@ -68,32 +68,53 @@ int mount_mount(struct autofs_point *ap,
struct mnt_list *mnt;
char buf[MAX_ERR_BUF];
char *options, *p;
- int len, ret;
+ int err, ret;
int hosts = 0;
/* Root offset of multi-mount */
- len = strlen(root);
- if (root[len - 1] == '/') {
- strcpy(realpath, ap->path);
- strcat(realpath, "/");
- strcat(realpath, name);
- len--;
- strncpy(mountpoint, root, len);
- mountpoint[len] = '\0';
+ if (root[strlen(root) - 1] == '/') {
+ err = snprintf(realpath, PATH_MAX + 1, "%s/%s", ap->path, name);
+ if (err > PATH_MAX) {
+ error(ap->logopt, MODPREFIX "string too long for realpath");
+ return 1;
+ }
+ err = snprintf(mountpoint, PATH_MAX + 1, "%s", root);
+ if (err > PATH_MAX) {
+ error(ap->logopt, MODPREFIX "string too long for mountpoint");
+ return 1;
+ }
+ mountpoint[err - 1] = 0;
} else if (*name == '/') {
if (ap->flags & MOUNT_FLAG_REMOUNT) {
- strcpy(mountpoint, name);
- strcpy(realpath, name);
+ err = snprintf(mountpoint, PATH_MAX + 1, "%s", name);
+ if (err > PATH_MAX) {
+ error(ap->logopt, MODPREFIX "string too long for mountpoint");
+ return 1;
+ }
+ err = snprintf(realpath, PATH_MAX + 1, "%s", name);
+ if (err > PATH_MAX) {
+ error(ap->logopt, MODPREFIX "string too long for realpath");
+ return 1;
+ }
} else {
- strcpy(mountpoint, root);
- strcpy(realpath, name);
+ err = snprintf(mountpoint, PATH_MAX + 1, "%s", root);
+ if (err > PATH_MAX) {
+ error(ap->logopt, MODPREFIX "string too long for mountpoint");
+ return 1;
+ }
+ err = snprintf(realpath, PATH_MAX + 1, "%s", name);
+ if (err > PATH_MAX) {
+ error(ap->logopt, MODPREFIX "string too long for realpath");
+ return 1;
+ }
}
} else {
- strcpy(mountpoint, root);
- strcat(mountpoint, "/");
+ err = snprintf(mountpoint, PATH_MAX + 1, "%s/%s", root, name);
+ if (err > PATH_MAX) {
+ error(ap->logopt, MODPREFIX "string too long for mountpoint");
+ return 1;
+ }
strcpy(realpath, mountpoint);
- strcat(mountpoint, name);
- strcat(realpath, name);
}
options = NULL;

View File

@ -0,0 +1,82 @@
autofs-5.1.7 - eliminate buffer usage from handle_mounts_cleanup()
From: Ian Kent <raven@themaw.net>
This buffer was originally added because a SEGV was seen accessing
the ap->path field on shutdown.
But this was actually caused by calling master_remove_mapent() too
early which adds the map entry to the master map join list that leads
to freeing the autofs_point (ap in the code) which also frees ap->path.
But the master map join list is protected by the master map mutex which
is held until after all the accesses are completed. So whatever the
problem was it doesn't appear to be present any more.
Nevertheless, to be sure, delay the call to master_remove_mapent() until
after all accesses to ap->path are completed.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1 +
daemon/automount.c | 13 ++++++-------
2 files changed, 7 insertions(+), 7 deletions(-)
--- autofs-5.1.7.orig/CHANGELOG
+++ autofs-5.1.7/CHANGELOG
@@ -148,6 +148,7 @@
- change to use printf functions in amd parser.
- dont call umount_subtree_mounts() on parent at umount.
- dont take parent source lock at mount shutdown.
+- eliminate buffer usage from handle_mounts_cleanup().
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
@@ -1724,7 +1724,6 @@ void handle_mounts_startup_cond_destroy(
static void handle_mounts_cleanup(void *arg)
{
struct autofs_point *ap;
- char path[PATH_MAX + 1];
char buf[MAX_ERR_BUF];
unsigned int clean = 0, submount, logopt;
unsigned int pending = 0;
@@ -1734,7 +1733,6 @@ static void handle_mounts_cleanup(void *
logopt = ap->logopt;
submount = ap->submount;
- strcpy(path, ap->path);
if (!submount && strcmp(ap->path, "/-") &&
ap->flags & MOUNT_FLAG_DIR_CREATED)
clean = 1;
@@ -1756,8 +1754,8 @@ static void handle_mounts_cleanup(void *
/* Don't signal the handler if we have already done so */
if (!list_empty(&master_list->completed))
pending = 1;
- master_remove_mapent(ap->entry);
- master_source_unlock(ap->entry);
+
+ info(logopt, "shut down path %s", ap->path);
/*
* Submounts are detached threads and don't belong to the
@@ -1770,14 +1768,15 @@ static void handle_mounts_cleanup(void *
}
if (clean) {
- if (rmdir(path) == -1) {
+ if (rmdir(ap->path) == -1) {
char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
warn(logopt, "failed to remove dir %s: %s",
- path, estr);
+ ap->path, estr);
}
}
- info(logopt, "shut down path %s", path);
+ master_remove_mapent(ap->entry);
+ master_source_unlock(ap->entry);
/*
* If we are not a submount send a signal to the signal handler

View File

@ -0,0 +1,270 @@
autofs-5.1.8 - add ioctlfd open helper
From: Ian Kent <raven@themaw.net>
Add an ioctl fd open helper, it simplifies the code in some areas.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1
daemon/direct.c | 25 ++++++++--------
daemon/indirect.c | 9 ++---
include/mounts.h | 3 +
lib/mounts.c | 82 ++++++++++++++++++++++++++++++------------------------
5 files changed, 68 insertions(+), 52 deletions(-)
--- autofs-5.1.7.orig/CHANGELOG
+++ autofs-5.1.7/CHANGELOG
@@ -152,6 +152,7 @@
- fix possible use after free in handle_mounts_exit().
- make submount cleanup the same as top level mounts.
- add soucre parameter to module functions.
+- add ioctlfd open helper.
25/01/2021 autofs-5.1.7
- make bind mounts propagation slave by default.
--- autofs-5.1.7.orig/daemon/direct.c
+++ autofs-5.1.7/daemon/direct.c
@@ -121,7 +121,9 @@ int do_umount_autofs_direct(struct autof
}
ioctlfd = me->ioctlfd;
} else {
- ops->open(ap->logopt, &ioctlfd, me->dev, me->key);
+ ioctlfd = open_ioctlfd(ap, me->key, me->dev);
+ if (ioctlfd == -1)
+ return 1;
opened = 1;
}
@@ -317,8 +319,7 @@ int do_mount_autofs_direct(struct autofs
save_ioctlfd = ioctlfd = me->ioctlfd;
if (ioctlfd == -1)
- ops->open(ap->logopt,
- &ioctlfd, me->dev, me->key);
+ ioctlfd = open_ioctlfd(ap, me->key, me->dev);
if (ioctlfd < 0) {
error(ap->logopt,
@@ -416,7 +417,7 @@ int do_mount_autofs_direct(struct autofs
if (ap->mode && (err = chmod(me->key, ap->mode)))
warn(ap->logopt, "failed to change mode of %s", me->key);
- ops->open(ap->logopt, &ioctlfd, st.st_dev, me->key);
+ ioctlfd = open_ioctlfd(ap, me->key, me->dev);
if (ioctlfd < 0) {
crit(ap->logopt, "failed to create ioctl fd for %s", me->key);
goto out_umount;
@@ -540,7 +541,9 @@ int umount_autofs_offset(struct autofs_p
me->key);
return 0;
}
- ops->open(ap->logopt, &ioctlfd, me->dev, me->key);
+ ioctlfd = open_ioctlfd(ap, me->key, me->dev);
+ if (ioctlfd == -1)
+ return 1;
opened = 1;
}
@@ -770,11 +773,9 @@ int mount_autofs_offset(struct autofs_po
me->dev = st.st_dev;
me->ino = st.st_ino;
- ops->open(ap->logopt, &ioctlfd, st.st_dev, me->key);
- if (ioctlfd < 0) {
- crit(ap->logopt, "failed to create ioctl fd for %s", me->key);
+ ioctlfd = open_ioctlfd(ap, me->key, me->dev);
+ if (ioctlfd < 0)
goto out_umount;
- }
ops->timeout(ap->logopt, ioctlfd, timeout);
cache_set_ino_index(me->mc, me);
@@ -1059,9 +1060,9 @@ int handle_packet_expire_direct(struct a
/* Can't expire it if it isn't mounted */
if (me->ioctlfd == -1) {
int ioctlfd;
- ops->open(ap->logopt, &ioctlfd, me->dev, me->key);
+
+ ioctlfd = open_ioctlfd(ap, me->key, me->dev);
if (ioctlfd == -1) {
- crit(ap->logopt, "can't open ioctlfd for %s", me->key);
cache_unlock(mc);
master_source_unlock(ap->entry);
pthread_setcancelstate(state, NULL);
@@ -1355,8 +1356,8 @@ int handle_packet_missing_direct(struct
close(me->ioctlfd);
me->ioctlfd = -1;
}
- ops->open(ap->logopt, &ioctlfd, me->dev, me->key);
+ ioctlfd = open_ioctlfd(ap, me->key, me->dev);
if (ioctlfd == -1) {
cache_unlock(mc);
master_source_unlock(ap->entry);
--- autofs-5.1.7.orig/daemon/indirect.c
+++ autofs-5.1.7/daemon/indirect.c
@@ -124,18 +124,18 @@ static int do_mount_autofs_indirect(stru
"failed to stat mount for autofs path %s", ap->path);
goto out_umount;
}
+ ap->dev = st.st_dev; /* Device number for mount point checks */
if (ap->mode && (err = chmod(ap->path, ap->mode)))
warn(ap->logopt, "failed to change mode of %s", ap->path);
- if (ops->open(ap->logopt, &ap->ioctlfd, st.st_dev, ap->path)) {
+ ap->ioctlfd = open_ioctlfd(ap, ap->path, ap->dev);
+ if (ap->ioctlfd == -1) {
crit(ap->logopt,
"failed to create ioctl fd for autofs path %s", ap->path);
goto out_umount;
}
- ap->dev = st.st_dev; /* Device number for mount point checks */
-
ops->timeout(ap->logopt, ap->ioctlfd, timeout);
notify_mount_result(ap, ap->path, timeout, str_indirect);
@@ -284,8 +284,7 @@ int umount_autofs_indirect(struct autofs
return 0;
}
#endif
- ops->open(ap->logopt,
- &ap->ioctlfd, ap->dev, ap->path);
+ ap->ioctlfd = open_ioctlfd(ap, ap->path, ap->dev);
if (ap->ioctlfd < 0) {
warn(ap->logopt,
"could not recover autofs path %s",
--- autofs-5.1.7.orig/include/mounts.h
+++ autofs-5.1.7/include/mounts.h
@@ -151,6 +151,9 @@ void free_amd_entry_list(struct list_hea
unsigned int query_kproto_ver(void);
unsigned int get_kver_major(void);
unsigned int get_kver_minor(void);
+
+int open_ioctlfd(struct autofs_point *ap, const char *path, dev_t dev);
+
char *make_options_string(char *path, int pipefd,
const char *type, unsigned int flags);
char *make_mnt_name_string(char *path);
--- autofs-5.1.7.orig/lib/mounts.c
+++ autofs-5.1.7/lib/mounts.c
@@ -231,6 +231,32 @@ unsigned int get_kver_minor(void)
return kver.minor;
}
+int open_ioctlfd(struct autofs_point *ap, const char *path, dev_t dev)
+{
+ struct ioctl_ops *ops = get_ioctl_ops();
+ int fd = -1;
+ int error;
+
+ error = ops->open(ap->logopt, &fd, dev, path);
+ if (error == -1) {
+ char buf[MAX_ERR_BUF];
+ int err = errno;
+ char *estr;
+
+ if (errno == ENOENT)
+ return -1;
+
+ estr = strerror_r(errno, buf, MAX_ERR_BUF);
+ error(ap->logopt,
+ "failed to open ioctlfd for %s, error: %s",
+ path, estr);
+ errno = err;
+ return -1;
+ }
+
+ return fd;
+}
+
#ifdef HAVE_MOUNT_NFS
static int extract_version(char *start, struct nfs_mount_vers *vers)
{
@@ -2719,7 +2745,7 @@ static int remount_active_mount(struct a
*ioctlfd = -1;
/* Open failed, no mount present */
- ops->open(ap->logopt, &fd, devid, path);
+ fd = open_ioctlfd(ap, path, devid);
if (fd == -1)
return REMOUNT_OPEN_FAIL;
@@ -2918,10 +2944,9 @@ static int set_mount_catatonic(struct au
{
struct ioctl_ops *ops = get_ioctl_ops();
unsigned int opened = 0;
- char buf[MAX_ERR_BUF];
- char *path;
- int fd = -1;
- int error;
+ const char *path;
+ int fd;
+ int err;
dev_t dev;
path = ap->path;
@@ -2936,44 +2961,31 @@ static int set_mount_catatonic(struct au
else if (me && me->ioctlfd >= 0)
fd = me->ioctlfd;
else {
- error = ops->open(ap->logopt, &fd, dev, path);
- if (error == -1) {
- int err = errno;
- char *estr;
-
- if (errno == ENOENT)
- return 0;
-
- estr = strerror_r(errno, buf, MAX_ERR_BUF);
- error(ap->logopt,
- "failed to open ioctlfd for %s, error: %s",
- path, estr);
- return err;
- }
+ fd = open_ioctlfd(ap, path, dev);
+ if (fd == -1)
+ return (errno == ENOENT ? 0 : errno);
opened = 1;
}
- if (fd >= 0) {
- error = ops->catatonic(ap->logopt, fd);
- if (error == -1) {
- int err = errno;
- char *estr;
+ err = ops->catatonic(ap->logopt, fd);
+ if (err == -1) {
+ char buf[MAX_ERR_BUF];
+ char *estr;
- estr = strerror_r(errno, buf, MAX_ERR_BUF);
- error(ap->logopt,
- "failed to set %s catatonic, error: %s",
- path, estr);
- if (opened)
- ops->close(ap->logopt, fd);
- return err;
- }
- if (opened)
- ops->close(ap->logopt, fd);
+ err = errno;
+ estr = strerror_r(err, buf, MAX_ERR_BUF);
+ error(ap->logopt,
+ "failed to set %s catatonic, error: %s",
+ path, estr);
+ goto out;
}
debug(ap->logopt, "set %s catatonic", path);
+out:
+ if (opened)
+ ops->close(ap->logopt, fd);
- return 0;
+ return err;
}
static int set_offset_tree_catatonic_work(struct tree_node *n, void *ptr)

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,144 @@
autofs-5.1.8 - change to use printf functions in amd parser
From: Ian Kent <raven@themaw.net>
Change to use the printf(3) functions in the amd parser rather than
string functions. These functions seem to have less overhead and they
are a little more compact.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1 +
modules/parse_amd.c | 45 +++++++++++++++++----------------------------
2 files changed, 18 insertions(+), 28 deletions(-)
--- autofs-5.1.7.orig/CHANGELOG
+++ autofs-5.1.7/CHANGELOG
@@ -145,6 +145,7 @@
- get rid of strlen call in handle_packet_missing_direct().
- remove redundant stat call in lookup_ghost().
- set mapent dev and ino before adding to index.
+- change to use printf functions in amd parser.
25/01/2021 autofs-5.1.7
- make bind mounts propagation slave by default.
--- autofs-5.1.7.orig/modules/parse_amd.c
+++ autofs-5.1.7/modules/parse_amd.c
@@ -170,11 +170,9 @@ static struct substvar *add_lookup_vars(
if (*key == '/')
strcpy(path, key);
- else {
- strcpy(path, ap->path);
- strcat(path, "/");
- strcat(path, key);
- }
+ else
+ sprintf(path, "%s/%s", ap->path, key);
+
list = macro_addvar(list, "path", 4, path);
me = cache_lookup_distinct(source->mc, lkp_key);
@@ -1067,24 +1065,23 @@ static int do_auto_mount(struct autofs_p
struct amd_entry *entry, unsigned int flags)
{
char target[PATH_MAX + 1];
+ int len;
if (!entry->map_type) {
- if (strlen(entry->fs) > PATH_MAX) {
+ len = snprintf(target, PATH_MAX, "%s", entry->fs);
+ if (len > PATH_MAX) {
error(ap->logopt, MODPREFIX
"error: fs option length is too long");
return 0;
}
- strcpy(target, entry->fs);
} else {
- if (strlen(entry->fs) +
- strlen(entry->map_type) + 5 > PATH_MAX) {
+ len = snprintf(target, PATH_MAX,
+ "%s,amd:%s", entry->map_type, entry->fs);
+ if (len > PATH_MAX) {
error(ap->logopt, MODPREFIX
"error: fs + maptype options length is too long");
return 0;
}
- strcpy(target, entry->map_type);
- strcat(target, ",amd:");
- strcat(target, entry->fs);
}
return do_mount(ap, ap->path,
@@ -1207,17 +1204,15 @@ static int do_nfs_mount(struct autofs_po
char *opts = (entry->opts && *entry->opts) ? entry->opts : NULL;
unsigned int umount = 0;
int ret = 0;
+ int len;
- if (strlen(entry->rhost) + strlen(entry->rfs) + 1 > PATH_MAX) {
+ len = snprintf(target, PATH_MAX, "%s:%s", entry->rhost, entry->rfs);
+ if (len > PATH_MAX) {
error(ap->logopt, MODPREFIX
"error: rhost + rfs options length is too long");
return 1;
}
- strcpy(target, entry->rhost);
- strcat(target, ":");
- strcat(target, entry->rfs);
-
proximity = get_network_proximity(entry->rhost);
if (proximity == PROXIMITY_OTHER && entry->remopts && *entry->remopts)
opts = entry->remopts;
@@ -1319,7 +1314,7 @@ static int do_host_mount(struct autofs_p
*/
if (strcmp(name, entry->rhost)) {
char *target;
- size_t len;
+ int len;
len = ap->len + strlen(entry->rhost) + 2;
target = malloc(len);
@@ -1328,9 +1323,7 @@ static int do_host_mount(struct autofs_p
"failed to alloc target to hosts mount base");
goto out;
}
- strcpy(target, ap->path);
- strcat(target, "/");
- strcat(target, entry->rhost);
+ sprintf(target, "%s/%s", ap->path, entry->rhost);
if (entry->path)
free(entry->path);
entry->path = target;
@@ -1819,7 +1812,7 @@ static void normalize_sublink(unsigned i
struct amd_entry *entry, struct substvar *sv)
{
char *new;
- size_t len;
+ int len;
/* Normalizing sublink requires a non-blank fs option */
if (!*entry->fs)
@@ -1833,9 +1826,7 @@ static void normalize_sublink(unsigned i
"error: couldn't allocate storage for sublink");
return;
}
- strcpy(new, entry->fs);
- strcat(new, "/");
- strcat(new, entry->sublink);
+ sprintf(new, "%s/%s", entry->fs, entry->sublink);
debug(logopt, MODPREFIX
"rfs dequote(\"%.*s\") -> %s",
strlen(entry->sublink), entry->sublink, new);
@@ -1866,9 +1857,7 @@ static void update_prefix(struct autofs_
len = strlen(ap->pref) + strlen(name) + 2;
new = malloc(len);
if (new) {
- strcpy(new, ap->pref);
- strcat(new, name);
- strcat(new, "/");
+ sprintf(new, "%s%s/", ap->pref, name);
entry->pref = new;
}
}

View File

@ -0,0 +1,56 @@
autofs-5.1.8 - continue expire immediately after submount check
From: Ian Kent <raven@themaw.net>
The expire proc for both direct and indirect mounts doesn't immediately
continue after seeing an autofs submount and sending it a notification.
Add the "continue" to avoid some wasted overhead.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1 +
daemon/direct.c | 5 ++++-
daemon/indirect.c | 5 ++++-
3 files changed, 9 insertions(+), 2 deletions(-)
--- autofs-5.1.7.orig/CHANGELOG
+++ autofs-5.1.7/CHANGELOG
@@ -137,6 +137,7 @@
- include addtional log info for mounts.
- fix amd selector function matching.
- get rid entry thid field.
+- continue expire immediately after submount check.
25/01/2021 autofs-5.1.7
- make bind mounts propagation slave by default.
--- autofs-5.1.7.orig/daemon/direct.c
+++ autofs-5.1.7/daemon/direct.c
@@ -854,8 +854,11 @@ void *expire_proc_direct(void *arg)
* one of them and pass on state change.
*/
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
- if (mnt->flags & MNTS_AUTOFS)
+ if (mnt->flags & MNTS_AUTOFS) {
master_notify_submount(ap, mnt->mp, ap->state);
+ pthread_setcancelstate(cur_state, NULL);
+ continue;
+ }
if (me->ioctlfd == -1) {
pthread_setcancelstate(cur_state, NULL);
--- autofs-5.1.7.orig/daemon/indirect.c
+++ autofs-5.1.7/daemon/indirect.c
@@ -392,8 +392,11 @@ void *expire_proc_indirect(void *arg)
* one of them and pass on the state change.
*/
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
- if (mnt->flags & MNTS_AUTOFS)
+ if (mnt->flags & MNTS_AUTOFS) {
master_notify_submount(ap, mnt->mp, ap->state);
+ pthread_setcancelstate(cur_state, NULL);
+ continue;
+ }
/* An offset without a real mount, check for manual umount */
if (mnt->flags & MNTS_OFFSET &&

View File

@ -0,0 +1,40 @@
autofs-5.1.8 - dont call umount_subtree_mounts() on parent at umount
From: Ian Kent <raven@themaw.net>
There shouldn't be any multi-mount offsets mounted within a submount
because the submount will be a nesting point and offsets will be mounted
within it when it gets mounted and expired before it's umounted.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1 +
daemon/automount.c | 7 -------
2 files changed, 1 insertion(+), 7 deletions(-)
--- autofs-5.1.7.orig/CHANGELOG
+++ autofs-5.1.7/CHANGELOG
@@ -146,6 +146,7 @@
- remove redundant stat call in lookup_ghost().
- set mapent dev and ino before adding to index.
- change to use printf functions in amd parser.
+- dont call umount_subtree_mounts() on parent at umount.
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
@@ -706,13 +706,6 @@ int umount_multi(struct autofs_point *ap
left = 0;
- /*
- * If we are a submount we need to umount any offsets our
- * parent may have mounted over top of us.
- */
- if (ap->submount)
- left += umount_subtree_mounts(ap->parent, path, 1);
-
left += umount_subtree_mounts(ap, path, is_autofs_fs);
/* Delete detritus like unwanted mountpoints and symlinks */

View File

@ -0,0 +1,118 @@
autofs-5.1.8 - dont take parent source lock at mount shutdown
From: Ian Kent <raven@themaw.net>
There shouldn't be any need to take the parent source lock at autofs mount
shutdown so don't take it.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1
daemon/automount.c | 60 ++---------------------------------------------------
2 files changed, 4 insertions(+), 57 deletions(-)
--- autofs-5.1.7.orig/CHANGELOG
+++ autofs-5.1.7/CHANGELOG
@@ -147,6 +147,7 @@
- set mapent dev and ino before adding to index.
- change to use printf functions in amd parser.
- dont call umount_subtree_mounts() on parent at umount.
+- dont take parent source lock at mount shutdown.
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
@@ -1765,7 +1765,6 @@ static void handle_mounts_cleanup(void *
* here.
*/
if (submount) {
- master_source_unlock(ap->parent->entry);
master_free_mapent_sources(ap->entry, 1);
master_free_mapent(ap->entry);
}
@@ -1793,36 +1792,6 @@ static void handle_mounts_cleanup(void *
return;
}
-static int submount_source_writelock_nested(struct autofs_point *ap)
-{
- struct autofs_point *parent = ap->parent;
- int status;
-
- status = pthread_rwlock_trywrlock(&parent->entry->source_lock);
- if (status)
- goto done;
-
- status = pthread_rwlock_trywrlock(&ap->entry->source_lock);
- if (status)
- master_source_unlock(parent->entry);
-
-done:
- if (status && status != EBUSY) {
- logmsg("submount nested master_mapent source write lock failed");
- fatal(status);
- }
-
- return status;
-}
-
-static void submount_source_unlock_nested(struct autofs_point *ap)
-{
- struct autofs_point *parent = ap->parent;
-
- master_source_unlock(ap->entry);
- master_source_unlock(parent->entry);
-}
-
int handle_mounts_exit(struct autofs_point *ap)
{
int ret, cur_state;
@@ -1837,33 +1806,13 @@ int handle_mounts_exit(struct autofs_poi
master_mutex_lock();
- if (!ap->submount)
- master_source_writelock(ap->entry);
- else {
- /*
- * If a mount request arrives before the locks are
- * aquired just return to ready state.
- */
- ret = submount_source_writelock_nested(ap);
- if (ret) {
- warn(ap->logopt,
- "can't shutdown submount: mount in progress");
- /* Return to ST_READY is done immediately */
- st_add_task(ap, ST_READY);
- master_mutex_unlock();
- pthread_setcancelstate(cur_state, NULL);
- return 0;
- }
- }
+ master_source_writelock(ap->entry);
if (ap->state != ST_SHUTDOWN) {
conditional_alarm_add(ap, ap->exp_runfreq);
/* Return to ST_READY is done immediately */
st_add_task(ap, ST_READY);
- if (ap->submount)
- submount_source_unlock_nested(ap);
- else
- master_source_unlock(ap->entry);
+ master_source_unlock(ap->entry);
master_mutex_unlock();
pthread_setcancelstate(cur_state, NULL);
@@ -1904,10 +1853,7 @@ int handle_mounts_exit(struct autofs_poi
conditional_alarm_add(ap, ap->exp_runfreq);
/* Return to ST_READY is done immediately */
st_add_task(ap, ST_READY);
- if (ap->submount)
- submount_source_unlock_nested(ap);
- else
- master_source_unlock(ap->entry);
+ master_source_unlock(ap->entry);
master_mutex_unlock();
pthread_setcancelstate(cur_state, NULL);

View File

@ -0,0 +1,112 @@
autofs-5.1.8 - eliminate realpath from mount of submount
From: Ian Kent <raven@themaw.net>
None of the tests I have show that the realpath local variable in the
autofs submount mount function is needed, remove it.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1 +
modules/mount_autofs.c | 25 ++++---------------------
2 files changed, 5 insertions(+), 21 deletions(-)
--- autofs-5.1.7.orig/CHANGELOG
+++ autofs-5.1.7/CHANGELOG
@@ -139,6 +139,7 @@
- get rid entry thid field.
- continue expire immediately after submount check.
- add buffer length checks to autofs mount_mount().
+- eliminate realpath from mount of submount.
25/01/2021 autofs-5.1.7
- make bind mounts propagation slave by default.
--- autofs-5.1.7.orig/modules/mount_autofs.c
+++ autofs-5.1.7/modules/mount_autofs.c
@@ -50,7 +50,6 @@ int mount_mount(struct autofs_point *ap,
{
struct startup_cond suc;
pthread_t thid;
- char realpath[PATH_MAX + 1];
char mountpoint[PATH_MAX + 1];
const char **argv;
int argc, status;
@@ -73,11 +72,6 @@ int mount_mount(struct autofs_point *ap,
/* Root offset of multi-mount */
if (root[strlen(root) - 1] == '/') {
- err = snprintf(realpath, PATH_MAX + 1, "%s/%s", ap->path, name);
- if (err > PATH_MAX) {
- error(ap->logopt, MODPREFIX "string too long for realpath");
- return 1;
- }
err = snprintf(mountpoint, PATH_MAX + 1, "%s", root);
if (err > PATH_MAX) {
error(ap->logopt, MODPREFIX "string too long for mountpoint");
@@ -91,22 +85,12 @@ int mount_mount(struct autofs_point *ap,
error(ap->logopt, MODPREFIX "string too long for mountpoint");
return 1;
}
- err = snprintf(realpath, PATH_MAX + 1, "%s", name);
- if (err > PATH_MAX) {
- error(ap->logopt, MODPREFIX "string too long for realpath");
- return 1;
- }
} else {
err = snprintf(mountpoint, PATH_MAX + 1, "%s", root);
if (err > PATH_MAX) {
error(ap->logopt, MODPREFIX "string too long for mountpoint");
return 1;
}
- err = snprintf(realpath, PATH_MAX + 1, "%s", name);
- if (err > PATH_MAX) {
- error(ap->logopt, MODPREFIX "string too long for realpath");
- return 1;
- }
}
} else {
err = snprintf(mountpoint, PATH_MAX + 1, "%s/%s", root, name);
@@ -114,7 +98,6 @@ int mount_mount(struct autofs_point *ap,
error(ap->logopt, MODPREFIX "string too long for mountpoint");
return 1;
}
- strcpy(realpath, mountpoint);
}
options = NULL;
@@ -180,7 +163,7 @@ int mount_mount(struct autofs_point *ap,
master = ap->entry->master;
- entry = master_new_mapent(master, realpath, ap->entry->age);
+ entry = master_new_mapent(master, mountpoint, ap->entry->age);
if (!entry) {
error(ap->logopt,
MODPREFIX "failed to malloc master_mapent struct");
@@ -332,7 +315,7 @@ int mount_mount(struct autofs_point *ap,
mnt = mnts_add_submount(nap);
if (!mnt) {
crit(ap->logopt,
- MODPREFIX "failed to allocate mount %s", realpath);
+ MODPREFIX "failed to allocate mount %s", mountpoint);
handle_mounts_startup_cond_destroy(&suc);
master_free_map_source(source, 1);
master_free_mapent(entry);
@@ -349,7 +332,7 @@ int mount_mount(struct autofs_point *ap,
crit(ap->logopt,
MODPREFIX
"failed to create mount handler thread for %s",
- realpath);
+ mountpoint);
handle_mounts_startup_cond_destroy(&suc);
mnts_remove_submount(nap->path);
master_free_map_source(source, 1);
@@ -370,7 +353,7 @@ int mount_mount(struct autofs_point *ap,
if (suc.status) {
crit(ap->logopt,
- MODPREFIX "failed to create submount for %s", realpath);
+ MODPREFIX "failed to create submount for %s", mountpoint);
handle_mounts_startup_cond_destroy(&suc);
mnts_remove_submount(nap->path);
master_free_map_source(source, 1);

View File

@ -0,0 +1,396 @@
autofs-5.1.8 - eliminate root param from autofs mount and umount
From: Ian Kent <raven@themaw.net>
Eliminate the "root" parameter of both mount and umount of autofs mounts.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1
daemon/automount.c | 30 ++++++-------------------
daemon/indirect.c | 57 ++++++++++++++++++++-----------------------------
daemon/lookup.c | 4 +--
daemon/master.c | 1
daemon/state.c | 2 -
include/automount.h | 7 ++----
modules/mount_autofs.c | 1
8 files changed, 39 insertions(+), 64 deletions(-)
--- autofs-5.1.7.orig/CHANGELOG
+++ autofs-5.1.7/CHANGELOG
@@ -140,6 +140,7 @@
- continue expire immediately after submount check.
- add buffer length checks to autofs mount_mount().
- eliminate realpath from mount of submount.
+- eliminate root param from autofs mount and umount.
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
@@ -736,7 +736,7 @@ static void umount_all(struct autofs_poi
left, ap->path);
}
-static int umount_autofs(struct autofs_point *ap, const char *root)
+static int umount_autofs(struct autofs_point *ap)
{
int ret = 0;
@@ -745,7 +745,7 @@ static int umount_autofs(struct autofs_p
if (ap->type == LKP_INDIRECT) {
umount_all(ap);
- ret = umount_autofs_indirect(ap, root);
+ ret = umount_autofs_indirect(ap);
} else
ret = umount_autofs_direct(ap);
@@ -915,7 +915,7 @@ static int autofs_init_ap(struct autofs_
return 0;
}
-static int mount_autofs(struct autofs_point *ap, const char *root)
+static int mount_autofs(struct autofs_point *ap)
{
int status;
@@ -930,7 +930,7 @@ static int mount_autofs(struct autofs_po
if (ap->type == LKP_DIRECT)
status = mount_autofs_direct(ap);
else
- status = mount_autofs_indirect(ap, root);
+ status = mount_autofs_indirect(ap);
st_add_task(ap, ST_READY);
@@ -1888,7 +1888,7 @@ int handle_mounts_exit(struct autofs_poi
* to check for possible recovery.
*/
if (ap->type == LKP_DIRECT) {
- umount_autofs(ap, NULL);
+ umount_autofs(ap);
handle_mounts_cleanup(ap);
return 1;
}
@@ -1899,7 +1899,7 @@ int handle_mounts_exit(struct autofs_poi
* so we can continue. This can happen if a lookup
* occurs while we're trying to umount.
*/
- ret = umount_autofs(ap, NULL);
+ ret = umount_autofs(ap);
if (!ret) {
set_indirect_mount_tree_catatonic(ap);
handle_mounts_cleanup(ap);
@@ -1927,12 +1927,10 @@ void *handle_mounts(void *arg)
struct startup_cond *suc;
struct autofs_point *ap;
int cancel_state, status = 0;
- char *root;
suc = (struct startup_cond *) arg;
ap = suc->ap;
- root = strdup(suc->root);
pthread_cleanup_push(return_start_status, suc);
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancel_state);
@@ -1940,30 +1938,18 @@ void *handle_mounts(void *arg)
status = pthread_mutex_lock(&suc->mutex);
if (status) {
logerr("failed to lock startup condition mutex!");
- if (root)
- free(root);
fatal(status);
}
- if (!root) {
- crit(ap->logopt, "failed to alloc string root");
- suc->status = 1;
- pthread_setcancelstate(cancel_state, NULL);
- pthread_exit(NULL);
- }
-
- if (mount_autofs(ap, root) < 0) {
+ if (mount_autofs(ap) < 0) {
if (!(do_force_unlink & UNLINK_AND_EXIT))
crit(ap->logopt, "mount of %s failed!", ap->path);
suc->status = 1;
- umount_autofs(ap, root);
- free(root);
+ umount_autofs(ap);
pthread_setcancelstate(cancel_state, NULL);
pthread_exit(NULL);
}
- free(root);
-
if (ap->flags & MOUNT_FLAG_NOBIND)
info(ap->logopt, "bind mounts disabled");
--- autofs-5.1.7.orig/daemon/indirect.c
+++ autofs-5.1.7/daemon/indirect.c
@@ -40,7 +40,7 @@
/* Attribute to create detached thread */
extern pthread_attr_t th_attr_detached;
-static int do_mount_autofs_indirect(struct autofs_point *ap, const char *root)
+static int do_mount_autofs_indirect(struct autofs_point *ap)
{
const char *str_indirect = mount_type_str(t_indirect);
struct ioctl_ops *ops = get_ioctl_ops();
@@ -89,11 +89,11 @@ static int do_mount_autofs_indirect(stru
}
/* In case the directory doesn't exist, try to mkdir it */
- if (mkdir_path(root, mp_mode) < 0) {
+ if (mkdir_path(ap->path, mp_mode) < 0) {
if (errno != EEXIST && errno != EROFS) {
crit(ap->logopt,
"failed to create autofs directory %s",
- root);
+ ap->path);
goto out_err;
}
/* If we recieve an error, and it's EEXIST or EROFS we know
@@ -108,27 +108,27 @@ static int do_mount_autofs_indirect(stru
if (!type || strcmp(ap->entry->maps->type, "hosts"))
map_name = ap->entry->maps->argv[0];
- ret = mount(map_name, root, "autofs", MS_MGC_VAL, options);
+ ret = mount(map_name, ap->path, "autofs", MS_MGC_VAL, options);
if (ret) {
crit(ap->logopt,
- "failed to mount autofs path %s at %s", ap->path, root);
+ "failed to mount autofs at %s", ap->path);
goto out_rmdir;
}
free(options);
options = NULL;
- ret = stat(root, &st);
+ ret = stat(ap->path, &st);
if (ret == -1) {
crit(ap->logopt,
"failed to stat mount for autofs path %s", ap->path);
goto out_umount;
}
- if (ap->mode && (err = chmod(root, ap->mode)))
+ if (ap->mode && (err = chmod(ap->path, ap->mode)))
warn(ap->logopt, "failed to change mode of %s", ap->path);
- if (ops->open(ap->logopt, &ap->ioctlfd, st.st_dev, root)) {
+ if (ops->open(ap->logopt, &ap->ioctlfd, st.st_dev, ap->path)) {
crit(ap->logopt,
"failed to create ioctl fd for autofs path %s", ap->path);
goto out_umount;
@@ -137,18 +137,15 @@ static int do_mount_autofs_indirect(stru
ap->dev = st.st_dev; /* Device number for mount point checks */
ops->timeout(ap->logopt, ap->ioctlfd, timeout);
- if (ap->logopt & LOGOPT_DEBUG)
- notify_mount_result(ap, root, timeout, str_indirect);
- else
- notify_mount_result(ap, ap->path, timeout, str_indirect);
+ notify_mount_result(ap, ap->path, timeout, str_indirect);
return 0;
out_umount:
- umount(root);
+ umount(ap->path);
out_rmdir:
if (ap->flags & MOUNT_FLAG_DIR_CREATED)
- rmdir(root);
+ rmdir(ap->path);
out_err:
if (options)
free(options);
@@ -158,7 +155,7 @@ out_err:
return -1;
}
-int mount_autofs_indirect(struct autofs_point *ap, const char *root)
+int mount_autofs_indirect(struct autofs_point *ap)
{
time_t now = monotonic_time(NULL);
int status;
@@ -180,11 +177,11 @@ int mount_autofs_indirect(struct autofs_
}
}
- status = do_mount_autofs_indirect(ap, root);
+ status = do_mount_autofs_indirect(ap);
if (status < 0)
return -1;
- map = lookup_ghost(ap, root);
+ map = lookup_ghost(ap);
if (map & LKP_FAIL) {
if (map & LKP_DIRECT) {
error(ap->logopt,
@@ -223,19 +220,13 @@ void close_mount_fds(struct autofs_point
return;
}
-int umount_autofs_indirect(struct autofs_point *ap, const char *root)
+int umount_autofs_indirect(struct autofs_point *ap)
{
struct ioctl_ops *ops = get_ioctl_ops();
char buf[MAX_ERR_BUF];
- char mountpoint[PATH_MAX + 1];
int rv, retries;
unsigned int unused;
- if (root)
- strcpy(mountpoint, root);
- else
- strcpy(mountpoint, ap->path);
-
/* If we are trying to shutdown make sure we can umount */
rv = ops->askumount(ap->logopt, ap->ioctlfd, &unused);
if (rv == -1) {
@@ -257,7 +248,7 @@ int umount_autofs_indirect(struct autofs
sched_yield();
retries = UMOUNT_RETRIES;
- while ((rv = umount(mountpoint)) == -1 && retries--) {
+ while ((rv = umount(ap->path)) == -1 && retries--) {
struct timespec tm = {0, 50000000};
if (errno != EBUSY)
break;
@@ -269,13 +260,13 @@ int umount_autofs_indirect(struct autofs
case ENOENT:
case EINVAL:
error(ap->logopt,
- "mount point %s does not exist", mountpoint);
+ "mount point %s does not exist", ap->path);
close_mount_fds(ap);
return 0;
break;
case EBUSY:
debug(ap->logopt,
- "mount point %s is in use", mountpoint);
+ "mount point %s is in use", ap->path);
if (ap->state == ST_SHUTDOWN_FORCE) {
close_mount_fds(ap);
goto force_umount;
@@ -294,11 +285,11 @@ int umount_autofs_indirect(struct autofs
}
#endif
ops->open(ap->logopt,
- &ap->ioctlfd, ap->dev, mountpoint);
+ &ap->ioctlfd, ap->dev, ap->path);
if (ap->ioctlfd < 0) {
warn(ap->logopt,
"could not recover autofs path %s",
- mountpoint);
+ ap->path);
close_mount_fds(ap);
return 0;
}
@@ -323,12 +314,12 @@ int umount_autofs_indirect(struct autofs
force_umount:
if (rv != 0) {
warn(ap->logopt,
- "forcing umount of indirect mount %s", mountpoint);
- rv = umount2(mountpoint, MNT_DETACH);
+ "forcing umount of indirect mount %s", ap->path);
+ rv = umount2(ap->path, MNT_DETACH);
} else {
- info(ap->logopt, "umounting indirect mount %s succeeded", mountpoint);
+ info(ap->logopt, "umounting indirect mount %s succeeded", ap->path);
if (ap->submount)
- rm_unwanted(ap, mountpoint, 1);
+ rm_unwanted(ap, ap->path, 1);
}
return rv;
--- autofs-5.1.7.orig/daemon/lookup.c
+++ autofs-5.1.7/daemon/lookup.c
@@ -712,7 +712,7 @@ static char *make_browse_path(unsigned i
return path;
}
-int lookup_ghost(struct autofs_point *ap, const char *root)
+int lookup_ghost(struct autofs_point *ap)
{
struct master_mapent *entry = ap->entry;
struct map_source *map;
@@ -776,7 +776,7 @@ int lookup_ghost(struct autofs_point *ap
}
fullpath = make_browse_path(ap->logopt,
- root, me->key, ap->pref);
+ ap->path, me->key, ap->pref);
if (!fullpath)
goto next;
--- autofs-5.1.7.orig/daemon/master.c
+++ autofs-5.1.7/daemon/master.c
@@ -1384,7 +1384,6 @@ static int master_do_mount(struct master
}
suc.ap = ap;
- suc.root = ap->path;
suc.done = 0;
suc.status = 0;
--- autofs-5.1.7.orig/daemon/state.c
+++ autofs-5.1.7/daemon/state.c
@@ -429,7 +429,7 @@ static void *do_readmap(void *arg)
ap->exp_runfreq = (timeout + CHECK_RATIO - 1) / CHECK_RATIO;
ops->timeout(ap->logopt, ap->ioctlfd, timeout);
lookup_prune_cache(ap, now);
- status = lookup_ghost(ap, ap->path);
+ status = lookup_ghost(ap);
} else {
struct mapent *me;
unsigned int append_alarm = !ap->exp_runfreq;
--- autofs-5.1.7.orig/include/automount.h
+++ autofs-5.1.7/include/automount.h
@@ -270,7 +270,7 @@ int lookup_nss_read_master(struct master
int lookup_nss_read_map(struct autofs_point *ap, struct map_source *source, time_t age);
int lookup_enumerate(struct autofs_point *ap,
int (*fn)(struct autofs_point *,struct mapent *, int), time_t now);
-int lookup_ghost(struct autofs_point *ap, const char *root);
+int lookup_ghost(struct autofs_point *ap);
int lookup_nss_mount(struct autofs_point *ap, struct map_source *source, const char *name, int name_len);
void lookup_close_lookup(struct autofs_point *ap);
void lookup_prune_one_cache(struct autofs_point *ap, struct mapent_cache *mc, time_t age);
@@ -392,7 +392,6 @@ struct startup_cond {
pthread_mutex_t mutex;
pthread_cond_t cond;
struct autofs_point *ap;
- char *root;
unsigned int done;
unsigned int status;
};
@@ -589,13 +588,13 @@ int do_expire(struct autofs_point *ap, c
void *expire_proc_indirect(void *);
void *expire_proc_direct(void *);
int expire_offsets_direct(struct autofs_point *ap, struct mapent *me, int now);
-int mount_autofs_indirect(struct autofs_point *ap, const char *root);
+int mount_autofs_indirect(struct autofs_point *ap);
int do_mount_autofs_direct(struct autofs_point *ap, struct mapent *me, time_t timeout);
int mount_autofs_direct(struct autofs_point *ap);
int mount_autofs_offset(struct autofs_point *ap, struct mapent *me);
void submount_signal_parent(struct autofs_point *ap, unsigned int success);
void close_mount_fds(struct autofs_point *ap);
-int umount_autofs_indirect(struct autofs_point *ap, const char *root);
+int umount_autofs_indirect(struct autofs_point *ap);
int do_umount_autofs_direct(struct autofs_point *ap, struct mapent *me);
int umount_autofs_direct(struct autofs_point *ap);
int umount_autofs_offset(struct autofs_point *ap, struct mapent *me);
--- autofs-5.1.7.orig/modules/mount_autofs.c
+++ autofs-5.1.7/modules/mount_autofs.c
@@ -324,7 +324,6 @@ int mount_mount(struct autofs_point *ap,
suc.ap = nap;
- suc.root = mountpoint;
suc.done = 0;
suc.status = 0;

View File

@ -0,0 +1,49 @@
autofs-5.1.8 - fix amd selector function matching
From: Ian Kent <raven@themaw.net>
The top level lexical analyser matching of 1 and 2 arg selector
functions did not have enough context to match correctly.
This was causing it to attempt to match the selector function and its
parameter(s) against the selector function names which wasn't working.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1 +
modules/amd_tok.l | 8 +++++---
2 files changed, 6 insertions(+), 3 deletions(-)
--- autofs-5.1.7.orig/CHANGELOG
+++ autofs-5.1.7/CHANGELOG
@@ -135,6 +135,7 @@
- fix fix mount tree startup reconnect.
- fix use_ignore_mount_option description.
- include addtional log info for mounts.
+- fix amd selector function matching.
25/01/2021 autofs-5.1.7
- make bind mounts propagation slave by default.
--- autofs-5.1.7.orig/modules/amd_tok.l
+++ autofs-5.1.7/modules/amd_tok.l
@@ -159,15 +159,17 @@ CUTSEP (\|\||\/)
return SELECTOR;
}
- "!"/({SEL1ARG}|{SEL2ARG}) { return NOT; }
+ "!"/({SEL1ARG})(\([^,]+\)) { return NOT; }
- {SEL1ARG} {
+ "!"/({SEL2ARG})(\(([^,]+)(,([^,]+))?\)) { return NOT; }
+
+ ({SEL1ARG})/(\([^,]+\)) {
BEGIN(SELARGVAL);
amd_copy_buffer();
return SELECTOR;
}
- {SEL2ARG} {
+ ({SEL2ARG})/(\([^,]+)(,([^,]+))?\) {
BEGIN(SELARGVAL);
amd_copy_buffer();
return SELECTOR;

View File

@ -0,0 +1,58 @@
autofs-5.1.8 - fix possible use after free in handle_mounts_exit()
From: Ian Kent <raven@themaw.net>
Don't free the submount map entry until it's no longer used.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1 +
daemon/automount.c | 20 ++++++++++----------
2 files changed, 11 insertions(+), 10 deletions(-)
--- autofs-5.1.7.orig/CHANGELOG
+++ autofs-5.1.7/CHANGELOG
@@ -149,6 +149,7 @@
- dont call umount_subtree_mounts() on parent at umount.
- dont take parent source lock at mount shutdown.
- eliminate buffer usage from handle_mounts_cleanup().
+- fix possible use after free in handle_mounts_exit().
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
@@ -1757,16 +1757,6 @@ static void handle_mounts_cleanup(void *
info(logopt, "shut down path %s", ap->path);
- /*
- * Submounts are detached threads and don't belong to the
- * master map entry list so we need to free their resources
- * here.
- */
- if (submount) {
- master_free_mapent_sources(ap->entry, 1);
- master_free_mapent(ap->entry);
- }
-
if (clean) {
if (rmdir(ap->path) == -1) {
char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
@@ -1779,6 +1769,16 @@ static void handle_mounts_cleanup(void *
master_source_unlock(ap->entry);
/*
+ * Submounts are detached threads and don't belong to the
+ * master map entry list so we need to free their resources
+ * here.
+ */
+ if (submount) {
+ master_free_mapent_sources(ap->entry, 1);
+ master_free_mapent(ap->entry);
+ }
+
+ /*
* If we are not a submount send a signal to the signal handler
* so it can join with any completed handle_mounts() threads and
* perform final cleanup.

View File

@ -0,0 +1,56 @@
autofs-5.1.8 - fix use_ignore_mount_option description
From: Ian Kent <raven@themaw.net>
Fix a couple of grammer problem with the configuration setting
use_ignore_mount_option description.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1 +
redhat/autofs.conf.default.in | 4 ++--
samples/autofs.conf.default.in | 4 ++--
3 files changed, 5 insertions(+), 4 deletions(-)
--- autofs-5.1.7.orig/CHANGELOG
+++ autofs-5.1.7/CHANGELOG
@@ -133,6 +133,7 @@
- fix unterminated read in handle_cmd_pipe_fifo_message().
- fix memory leak in sasl_do_kinit()
- fix fix mount tree startup reconnect.
+- fix use_ignore_mount_option description.
25/01/2021 autofs-5.1.7
- make bind mounts propagation slave by default.
--- autofs-5.1.7.orig/redhat/autofs.conf.default.in
+++ autofs-5.1.7/redhat/autofs.conf.default.in
@@ -187,11 +187,11 @@ mount_nfs_default_protocol = 4
#disable_not_found_message = "no"
#
# use_ignore_mount_option - This option is used to enable the use of autofs
-# pseudo option "disable". This option is used as a
+# pseudo option "ignore". This option is used as a
# hint to user space that the mount entry should be
# ommitted from mount table listings. The default is
# "no" to avoid unexpected changes in behaviour and
-# so is an opt-in setting.
+# is an opt-in setting.
#
#use_ignore_mount_option = no
#
--- autofs-5.1.7.orig/samples/autofs.conf.default.in
+++ autofs-5.1.7/samples/autofs.conf.default.in
@@ -186,11 +186,11 @@ browse_mode = no
#disable_not_found_message = "no"
#
# use_ignore_mount_option - This option is used to enable the use of autofs
-# pseudo option "disable". This option is used as a
+# pseudo option "ignore". This option is used as a
# hint to user space that the mount entry should be
# ommitted from mount table listings. The default is
# "no" to avoid unexpected changes in behaviour and
-# so is an opt-in setting.
+# is an opt-in setting.
#
#use_ignore_mount_option = no
#

View File

@ -0,0 +1,62 @@
autofs-5.1.8 - get rid entry thid field
From: Ian Kent <raven@themaw.net>
Use the autofs_point structure thid and get rid of the copy in struct
master_mapent.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1 +
daemon/master.c | 5 ++---
include/master.h | 1 -
3 files changed, 3 insertions(+), 4 deletions(-)
--- autofs-5.1.7.orig/CHANGELOG
+++ autofs-5.1.7/CHANGELOG
@@ -136,6 +136,7 @@
- fix use_ignore_mount_option description.
- include addtional log info for mounts.
- fix amd selector function matching.
+- get rid entry thid field.
25/01/2021 autofs-5.1.7
- make bind mounts propagation slave by default.
--- autofs-5.1.7.orig/daemon/master.c
+++ autofs-5.1.7/daemon/master.c
@@ -831,7 +831,6 @@ struct master_mapent *master_new_mapent(
entry->path = tmp;
entry->len = strlen(tmp);
- entry->thid = 0;
entry->age = age;
entry->master = master;
entry->current = NULL;
@@ -1413,7 +1412,7 @@ static int master_do_mount(struct master
handle_mounts_startup_cond_destroy(&suc);
return 0;
}
- entry->thid = ap->thid = thid;
+ ap->thid = thid;
handle_mounts_startup_cond_destroy(&suc);
@@ -1969,7 +1968,7 @@ int master_done(struct master *master)
entry = list_entry(p, struct master_mapent, join);
p = p->next;
list_del(&entry->join);
- pthread_join(entry->thid, NULL);
+ pthread_join(entry->ap->thid, NULL);
master_free_mapent_sources(entry, 1);
master_free_mapent(entry);
}
--- autofs-5.1.7.orig/include/master.h
+++ autofs-5.1.7/include/master.h
@@ -46,7 +46,6 @@ struct map_source {
struct master_mapent {
char *path;
size_t len;
- pthread_t thid;
time_t age;
struct master *master;
pthread_rwlock_t source_lock;

View File

@ -0,0 +1,52 @@
autofs-5.1.8 - get rid of strlen call in handle_packet_missing_direct()
From: Ian Kent <raven@themaw.net>
There is a length field in struct mapent, use it.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1 +
daemon/direct.c | 7 +++----
2 files changed, 4 insertions(+), 4 deletions(-)
--- autofs-5.1.7.orig/CHANGELOG
+++ autofs-5.1.7/CHANGELOG
@@ -142,6 +142,7 @@
- eliminate realpath from mount of submount.
- eliminate root param from autofs mount and umount.
- remove redundant fstat from do_mount_direct().
+- get rid of strlen call in handle_packet_missing_direct().
25/01/2021 autofs-5.1.7
- make bind mounts propagation slave by default.
--- autofs-5.1.7.orig/daemon/direct.c
+++ autofs-5.1.7/daemon/direct.c
@@ -1288,7 +1288,7 @@ int handle_packet_missing_direct(struct
char buf[MAX_ERR_BUF];
int status = 0;
struct timespec wait;
- int ioctlfd, len, state;
+ int ioctlfd, state;
unsigned int kver_major = get_kver_major();
unsigned int kver_minor = get_kver_minor();
@@ -1390,8 +1390,7 @@ int handle_packet_missing_direct(struct
return 0;
}
- len = strlen(me->key);
- if (len >= PATH_MAX) {
+ if (me->len >= PATH_MAX) {
error(ap->logopt, "direct mount path too long %s", me->key);
ops->send_fail(ap->logopt,
ioctlfd, pkt->wait_queue_token, -ENAMETOOLONG);
@@ -1430,7 +1429,7 @@ int handle_packet_missing_direct(struct
mt->ioctlfd = ioctlfd;
mt->mc = mc;
strcpy(mt->name, me->key);
- mt->len = len;
+ mt->len = me->len;
mt->dev = me->dev;
mt->type = NFY_MOUNT;
mt->uid = pkt->uid;

View File

@ -0,0 +1,160 @@
autofs-5.1.8 - include addtional log info for mounts
From: Ian Kent <raven@themaw.net>
There has been a request to include some additional information when
logging mounts and umounts, specifically host and mount location path.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1 +
daemon/automount.c | 7 +++++--
daemon/indirect.c | 2 +-
daemon/spawn.c | 6 +++---
modules/mount_bind.c | 4 ++--
modules/mount_ext2.c | 2 +-
modules/mount_generic.c | 2 +-
modules/mount_nfs.c | 4 +++-
8 files changed, 17 insertions(+), 11 deletions(-)
--- autofs-5.1.7.orig/CHANGELOG
+++ autofs-5.1.7/CHANGELOG
@@ -134,6 +134,7 @@
- fix memory leak in sasl_do_kinit()
- fix fix mount tree startup reconnect.
- fix use_ignore_mount_option description.
+- include addtional log info for mounts.
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
@@ -857,14 +857,17 @@ static int get_pkt(struct autofs_point *
int do_expire(struct autofs_point *ap, const char *name, int namelen)
{
char buf[PATH_MAX];
+ const char *parent;
int len, ret;
if (*name != '/') {
len = ncat_path(buf, sizeof(buf), ap->path, name, namelen);
+ parent = ap->path;
} else {
len = snprintf(buf, PATH_MAX, "%s", name);
if (len >= PATH_MAX)
len = 0;
+ parent = name;
}
if (!len) {
@@ -872,13 +875,13 @@ int do_expire(struct autofs_point *ap, c
return 1;
}
- info(ap->logopt, "expiring path %s", buf);
+ info(ap->logopt, "expiring path %s on %s", buf, parent);
pthread_cleanup_push(master_source_lock_cleanup, ap->entry);
master_source_readlock(ap->entry);
ret = umount_multi(ap, buf, 1);
if (ret == 0)
- info(ap->logopt, "expired %s", buf);
+ info(ap->logopt, "umounting %s succeeded", buf);
else
warn(ap->logopt, "couldn't complete expire of %s", buf);
pthread_cleanup_pop(1);
--- autofs-5.1.7.orig/daemon/indirect.c
+++ autofs-5.1.7/daemon/indirect.c
@@ -326,7 +326,7 @@ force_umount:
"forcing umount of indirect mount %s", mountpoint);
rv = umount2(mountpoint, MNT_DETACH);
} else {
- info(ap->logopt, "umounted indirect mount %s", mountpoint);
+ info(ap->logopt, "umounting indirect mount %s succeeded", mountpoint);
if (ap->submount)
rm_unwanted(ap, mountpoint, 1);
}
--- autofs-5.1.7.orig/daemon/spawn.c
+++ autofs-5.1.7/daemon/spawn.c
@@ -541,7 +541,7 @@ done:
while (errp && (p = memchr(sp, '\n', errp))) {
*p++ = '\0';
if (sp[0]) /* Don't output empty lines */
- warn(logopt, ">> %s", sp);
+ debug(logopt, ">> %s", sp);
errp -= (p - sp);
sp = p;
}
@@ -552,7 +552,7 @@ done:
if (errp >= ERRBUFSIZ) {
/* Line too long, split */
errbuf[errp] = '\0';
- warn(logopt, ">> %s", errbuf);
+ debug(logopt, ">> %s", errbuf);
errp = 0;
}
}
@@ -566,7 +566,7 @@ done:
if (errp > 0) {
/* End of file without \n */
errbuf[errp] = '\0';
- warn(logopt, ">> %s", errbuf);
+ debug(logopt, ">> %s", errbuf);
}
if (waitpid(f, &ret, 0) != f)
--- autofs-5.1.7.orig/modules/mount_bind.c
+++ autofs-5.1.7/modules/mount_bind.c
@@ -177,7 +177,7 @@ int mount_mount(struct autofs_point *ap,
return err;
} else {
- debug(ap->logopt,
+ mountlog(ap->logopt,
MODPREFIX "mounted %s type %s on %s",
what, fstype, fullpath);
}
@@ -252,7 +252,7 @@ int mount_mount(struct autofs_point *ap,
}
return 1;
} else {
- debug(ap->logopt,
+ mountlog(ap->logopt,
MODPREFIX "symlinked %s -> %s", fullpath, what);
return 0;
}
--- autofs-5.1.7.orig/modules/mount_ext2.c
+++ autofs-5.1.7/modules/mount_ext2.c
@@ -140,7 +140,7 @@ int mount_mount(struct autofs_point *ap,
return 1;
} else {
- debug(ap->logopt,
+ mountlog(ap->logopt,
MODPREFIX "mounted %s type %s on %s",
what, fstype, fullpath);
return 0;
--- autofs-5.1.7.orig/modules/mount_generic.c
+++ autofs-5.1.7/modules/mount_generic.c
@@ -99,7 +99,7 @@ int mount_mount(struct autofs_point *ap,
return 1;
} else {
- debug(ap->logopt, MODPREFIX "mounted %s type %s on %s",
+ mountlog(ap->logopt, MODPREFIX "mounted %s type %s on %s",
what, fstype, fullpath);
return 0;
}
--- autofs-5.1.7.orig/modules/mount_nfs.c
+++ autofs-5.1.7/modules/mount_nfs.c
@@ -403,7 +403,9 @@ dont_probe:
}
if (!err) {
- debug(ap->logopt, MODPREFIX "mounted %s on %s", loc, fullpath);
+ mountlog(ap->logopt,
+ MODPREFIX "mounted %s type %s on %s",
+ loc, fstype, fullpath);
free(loc);
free_host_list(&hosts);
return 0;

View File

@ -0,0 +1,177 @@
autofs-5.1.8 - make open files limit configurable
From: Ian Kent <raven@themaw.net>
autofs can use quite a few file handles, particularly with very large
direct mount maps or many submounts as is often seen with amd maps.
So make the maximum number of open files configurable.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1 +
daemon/automount.c | 13 +++++++------
include/defaults.h | 2 ++
lib/defaults.c | 17 +++++++++++++++++
man/autofs.conf.5.in | 7 +++++++
redhat/autofs.conf.default.in | 11 +++++++++++
samples/autofs.conf.default.in | 11 +++++++++++
7 files changed, 56 insertions(+), 6 deletions(-)
--- autofs-5.1.7.orig/CHANGELOG
+++ autofs-5.1.7/CHANGELOG
@@ -153,6 +153,7 @@
- make submount cleanup the same as top level mounts.
- add soucre parameter to module functions.
- add ioctlfd open helper.
+- make open files limit configurable.
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
@@ -100,8 +100,6 @@ struct startup_cond suc = {
pthread_key_t key_thread_stdenv_vars;
pthread_key_t key_thread_attempt_id = (pthread_key_t) 0L;
-#define MAX_OPEN_FILES 20480
-
int aquire_flag_file(void);
void release_flag_file(void);
@@ -2205,6 +2203,7 @@ int main(int argc, char *argv[])
time_t timeout;
time_t age = monotonic_time(NULL);
struct rlimit rlim;
+ unsigned long max_open_files;
const char *options = "+hp:t:vmdD:SfVrO:l:n:CFUM:";
static const struct option long_options[] = {
{"help", 0, 0, 'h'},
@@ -2409,11 +2408,13 @@ int main(int argc, char *argv[])
exit(1);
}
+ max_open_files = defaults_get_open_file_limit();
+
res = getrlimit(RLIMIT_NOFILE, &rlim);
- if (res == -1 || rlim.rlim_cur <= MAX_OPEN_FILES) {
- rlim.rlim_cur = MAX_OPEN_FILES;
- if (rlim.rlim_max < MAX_OPEN_FILES)
- rlim.rlim_max = MAX_OPEN_FILES;
+ if (res == -1 || rlim.rlim_cur <= max_open_files) {
+ rlim.rlim_cur = max_open_files;
+ if (rlim.rlim_max < max_open_files)
+ rlim.rlim_max = max_open_files;
}
res = setrlimit(RLIMIT_NOFILE, &rlim);
if (res)
--- autofs-5.1.7.orig/include/defaults.h
+++ autofs-5.1.7/include/defaults.h
@@ -24,6 +24,7 @@
#define DEFAULT_MASTER_MAP_NAME "auto.master"
+#define DEFAULT_OPEN_FILE_LIMIT "20480"
#define DEFAULT_TIMEOUT "600"
#define DEFAULT_MASTER_WAIT "10"
#define DEFAULT_NEGATIVE_TIMEOUT "60"
@@ -157,6 +158,7 @@ unsigned int defaults_read_config(unsign
void defaults_conf_release(void);
const char *defaults_get_master_map(void);
int defaults_master_set(void);
+unsigned long defaults_get_open_file_limit(void);
unsigned int defaults_get_timeout(void);
int defaults_get_master_wait(void);
unsigned int defaults_get_negative_timeout(void);
--- autofs-5.1.7.orig/lib/defaults.c
+++ autofs-5.1.7/lib/defaults.c
@@ -47,6 +47,7 @@
#define NAME_MASTER_MAP "master_map_name"
+#define NAME_OPEN_FILE_LIMIT "open_file_limit"
#define NAME_TIMEOUT "timeout"
#define NAME_MASTER_WAIT "master_wait"
#define NAME_NEGATIVE_TIMEOUT "negative_timeout"
@@ -290,6 +291,11 @@ static int conf_load_autofs_defaults(voi
const char *sec = autofs_gbl_sec;
int ret;
+ ret = conf_update(sec, NAME_OPEN_FILE_LIMIT,
+ DEFAULT_OPEN_FILE_LIMIT, CONF_ENV);
+ if (ret == CFG_FAIL)
+ goto error;
+
ret = conf_update(sec, NAME_TIMEOUT,
DEFAULT_TIMEOUT, CONF_ENV);
if (ret == CFG_FAIL)
@@ -1670,6 +1676,17 @@ int defaults_master_set(void)
return 0;
}
+unsigned long defaults_get_open_file_limit(void)
+{
+ long limit;
+
+ limit = conf_get_number(autofs_gbl_sec, NAME_OPEN_FILE_LIMIT);
+ if (limit < 0)
+ limit = atol(DEFAULT_OPEN_FILE_LIMIT);
+
+ return limit;
+}
+
unsigned int defaults_get_timeout(void)
{
long timeout;
--- autofs-5.1.7.orig/man/autofs.conf.5.in
+++ autofs-5.1.7/man/autofs.conf.5.in
@@ -23,6 +23,13 @@ configuration settings.
.P
Configuration settings available are:
.TP
++.B open_file_limit
++.br
++Set the maximum number of open files. Note there may be other limits
++within the system that prevent this from being set, systemd for example
++may need a setting in the unit file to increase its default. The autofs
++default is 20480.
++.TP
.B timeout
.br
Sets the default mount timeout in seconds. The internal program
--- autofs-5.1.7.orig/redhat/autofs.conf.default.in
+++ autofs-5.1.7/redhat/autofs.conf.default.in
@@ -1,4 +1,15 @@
#
+# Global configuration options.
+#
+# open_file_limit - set the maximum number of open files. Note there
+# may be other limits within the system that prevent
+# this from being set, systemd for example may need
+# a setting in the unit file to increase its default.
+# The autofs default is 20480.
+#
+#open_file_limit = 20480
+#
+#
# Define default options for autofs.
#
[ autofs ]
--- autofs-5.1.7.orig/samples/autofs.conf.default.in
+++ autofs-5.1.7/samples/autofs.conf.default.in
@@ -1,4 +1,15 @@
#
+# Global configuration options.
+#
+# open_file_limit - set the maximum number of open files. Note there
+# may be other limits within the system that prevent
+# this from being set, systemd for example may need
+# a setting in the unit file to increase its default.
+# The autofs default is 20480.
+#
+#open_file_limit = 20480
+#
+#
# Define default options for autofs.
#
[ autofs ]

View File

@ -0,0 +1,131 @@
autofs-5.1.8 - make submount cleanup the same as top level mounts
From: Ian Kent <raven@themaw.net>
We often see segfaults when cleaning up resources at submount shutdown
after changes are made to resolve problems. It's always really hard to
work out what's causing these to happen.
But changing submounts to use the same final cleanup method as top level
mounts eliminates the faulting, at least in the case of the most recent
changes, hopefully this change in proceedure will continue to work.
Admitedly there's some setting of fields to NULL after freeing but that
didn't fix the problem until the procedure change was also made.
In any case the result is a consistency improvement.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1 +
daemon/automount.c | 17 +++--------------
daemon/master.c | 19 +++++++++++++++++--
modules/mount_autofs.c | 6 +++---
4 files changed, 24 insertions(+), 19 deletions(-)
--- autofs-5.1.7.orig/CHANGELOG
+++ autofs-5.1.7/CHANGELOG
@@ -150,6 +150,7 @@
- dont take parent source lock at mount shutdown.
- eliminate buffer usage from handle_mounts_cleanup().
- fix possible use after free in handle_mounts_exit().
+- make submount cleanup the same as top level mounts.
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
@@ -1769,21 +1769,10 @@ static void handle_mounts_cleanup(void *
master_source_unlock(ap->entry);
/*
- * Submounts are detached threads and don't belong to the
- * master map entry list so we need to free their resources
- * here.
+ * Send a signal to the signal handler so it can join with any
+ * completed handle_mounts() threads and perform final cleanup.
*/
- if (submount) {
- master_free_mapent_sources(ap->entry, 1);
- master_free_mapent(ap->entry);
- }
-
- /*
- * If we are not a submount send a signal to the signal handler
- * so it can join with any completed handle_mounts() threads and
- * perform final cleanup.
- */
- if (!submount && !pending)
+ if (!pending)
pthread_kill(signal_handler_thid, SIGTERM);
master_mutex_unlock();
--- autofs-5.1.7.orig/daemon/master.c
+++ autofs-5.1.7/daemon/master.c
@@ -384,11 +384,14 @@ static void __master_free_map_source(str
instance = source->instance;
while (instance) {
- if (instance->lookup)
+ if (instance->lookup) {
close_lookup(instance->lookup);
+ instance->lookup = NULL;
+ }
instance = instance->next;
}
close_lookup(source->lookup);
+ source->lookup = NULL;
}
if (source->argv)
free_argv(source->argc, source->argv);
@@ -401,6 +404,7 @@ static void __master_free_map_source(str
__master_free_map_source(instance, 0);
instance = next;
}
+ source->instance = NULL;
}
status = pthread_rwlock_destroy(&source->module_lock);
@@ -863,9 +867,20 @@ void master_add_mapent(struct master *ma
void master_remove_mapent(struct master_mapent *entry)
{
struct master *master = entry->master;
+ struct autofs_point *ap = entry->ap;
+
+ if (ap->submount) {
+ struct mnt_list *mnt;
- if (entry->ap->submount)
+ mnt = mnts_find_submount(ap->path);
+ if (mnt) {
+ warn(ap->logopt,
+ "map entry %s in use at shutdown", ap->path);
+ mnts_put_mount(mnt);
+ }
+ list_add(&entry->join, &master->completed);
return;
+ }
if (!list_empty(&entry->list)) {
list_del_init(&entry->list);
--- autofs-5.1.7.orig/modules/mount_autofs.c
+++ autofs-5.1.7/modules/mount_autofs.c
@@ -28,8 +28,8 @@
#define MODPREFIX "mount(autofs): "
-/* Attribute to create detached thread */
-extern pthread_attr_t th_attr_detached;
+/* Attributes to create handle_mounts() thread */
+extern pthread_attr_t th_attr;
extern struct startup_cond suc;
int mount_version = AUTOFS_MOUNT_VERSION; /* Required by protocol */
@@ -327,7 +327,7 @@ int mount_mount(struct autofs_point *ap,
suc.done = 0;
suc.status = 0;
- if (pthread_create(&thid, &th_attr_detached, handle_mounts, &suc)) {
+ if (pthread_create(&thid, &th_attr, handle_mounts, &suc)) {
crit(ap->logopt,
MODPREFIX
"failed to create mount handler thread for %s",

View File

@ -0,0 +1,58 @@
autofs-5.1.8 - remove redundant stat call in lookup_ghost()
From: Ian Kent <raven@themaw.net>
There's nothing to be gained by checking for existence of the path
here, just trust the mkdir_path() call will return the correct error
if the path exists.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1 +
daemon/lookup.c | 24 ++++++------------------
2 files changed, 7 insertions(+), 18 deletions(-)
--- autofs-5.1.7.orig/CHANGELOG
+++ autofs-5.1.7/CHANGELOG
@@ -143,6 +143,7 @@
- eliminate root param from autofs mount and umount.
- remove redundant fstat from do_mount_direct().
- get rid of strlen call in handle_packet_missing_direct().
+- remove redundant stat call in lookup_ghost().
25/01/2021 autofs-5.1.7
- make bind mounts propagation slave by default.
--- autofs-5.1.7.orig/daemon/lookup.c
+++ autofs-5.1.7/daemon/lookup.c
@@ -780,25 +780,13 @@ int lookup_ghost(struct autofs_point *ap
if (!fullpath)
goto next;
- ret = stat(fullpath, &st);
- if (ret == -1 && errno != ENOENT) {
- char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
- warn(ap->logopt, "stat error %s", estr);
- free(fullpath);
- goto next;
- }
-
- /* Directory already exists? */
- if (!ret) {
- free(fullpath);
- goto next;
- }
-
ret = mkdir_path(fullpath, mp_mode);
- if (ret < 0 && errno != EEXIST) {
- char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
- warn(ap->logopt,
- "mkdir_path %s failed: %s", fullpath, estr);
+ if (ret < 0) {
+ if (errno != EEXIST) {
+ char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
+ warn(ap->logopt,
+ "mkdir_path %s failed: %s", fullpath, estr);
+ }
free(fullpath);
goto next;
}

View File

@ -0,0 +1,48 @@
autofs-5.1.8 - remove redundant stat from do_mount_direct()
From: Ian Kent <raven@themaw.net>
In do_mount_direct() a stat() call is used to check mount point
attributes but the fstat() of the ioctlfd is for the same path so
the lower overhead fstat() call can be used to do these checks as
well.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1 +
daemon/direct.c | 10 +---------
2 files changed, 2 insertions(+), 9 deletions(-)
--- autofs-5.1.7.orig/CHANGELOG
+++ autofs-5.1.7/CHANGELOG
@@ -141,6 +141,7 @@
- add buffer length checks to autofs mount_mount().
- eliminate realpath from mount of submount.
- eliminate root param from autofs mount and umount.
+- remove redundant fstat from do_mount_direct().
25/01/2021 autofs-5.1.7
- make bind mounts propagation slave by default.
--- autofs-5.1.7.orig/daemon/direct.c
+++ autofs-5.1.7/daemon/direct.c
@@ -1197,19 +1197,11 @@ static void *do_mount_direct(void *arg)
}
status = fstat(mt.ioctlfd, &st);
- if (status == -1) {
- error(ap->logopt,
- "can't stat direct mount trigger %s", mt.name);
- mt.status = -ENOENT;
- pthread_setcancelstate(state, NULL);
- pthread_exit(NULL);
- }
-
- status = stat(mt.name, &st);
if (status != 0 || !S_ISDIR(st.st_mode) || st.st_dev != mt.dev) {
error(ap->logopt,
"direct trigger not valid or already mounted %s",
mt.name);
+ mt.status = -EINVAL;
pthread_setcancelstate(state, NULL);
pthread_exit(NULL);
}

View File

@ -0,0 +1,140 @@
autofs-5.1.8 - set mapent dev and ino before adding to index
From: Ian Kent <raven@themaw.net>
Set the struct fields dev and ino straight after getting them with
stat() or fstat() so they can be used in cache_set_ino_index() without
being passed in.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1 +
daemon/direct.c | 8 ++++++--
daemon/state.c | 2 +-
include/automount.h | 3 +--
lib/cache.c | 11 ++---------
lib/mounts.c | 16 +++++++++++++---
6 files changed, 24 insertions(+), 17 deletions(-)
--- autofs-5.1.7.orig/CHANGELOG
+++ autofs-5.1.7/CHANGELOG
@@ -144,6 +144,7 @@
- remove redundant fstat from do_mount_direct().
- get rid of strlen call in handle_packet_missing_direct().
- remove redundant stat call in lookup_ghost().
+- set mapent dev and ino before adding to index.
25/01/2021 autofs-5.1.7
- make bind mounts propagation slave by default.
--- autofs-5.1.7.orig/daemon/direct.c
+++ autofs-5.1.7/daemon/direct.c
@@ -410,6 +410,8 @@ int do_mount_autofs_direct(struct autofs
"failed to stat direct mount trigger %s", me->key);
goto out_umount;
}
+ me->dev = st.st_dev;
+ me->ino = st.st_ino;
if (ap->mode && (err = chmod(me->key, ap->mode)))
warn(ap->logopt, "failed to change mode of %s", me->key);
@@ -422,7 +424,7 @@ int do_mount_autofs_direct(struct autofs
ops->timeout(ap->logopt, ioctlfd, timeout);
notify_mount_result(ap, me->key, timeout, str_direct);
- cache_set_ino_index(me->mc, me->key, st.st_dev, st.st_ino);
+ cache_set_ino_index(me->mc, me);
ops->close(ap->logopt, ioctlfd);
debug(ap->logopt, "mounted trigger %s", me->key);
@@ -765,6 +767,8 @@ int mount_autofs_offset(struct autofs_po
goto out_umount;
goto out_err;
}
+ me->dev = st.st_dev;
+ me->ino = st.st_ino;
ops->open(ap->logopt, &ioctlfd, st.st_dev, me->key);
if (ioctlfd < 0) {
@@ -773,7 +777,7 @@ int mount_autofs_offset(struct autofs_po
}
ops->timeout(ap->logopt, ioctlfd, timeout);
- cache_set_ino_index(me->mc, me->key, st.st_dev, st.st_ino);
+ cache_set_ino_index(me->mc, me);
notify_mount_result(ap, me->key, timeout, str_offset);
ops->close(ap->logopt, ioctlfd);
--- autofs-5.1.7.orig/daemon/state.c
+++ autofs-5.1.7/daemon/state.c
@@ -362,7 +362,7 @@ static int do_readmap_mount(struct autof
valid->ioctlfd = me->ioctlfd;
me->ioctlfd = -1;
/* Set device and inode number of the new mapent */
- cache_set_ino_index(vmc, me->key, me->dev, me->ino);
+ cache_set_ino_index(vmc, me);
cache_unlock(vmc);
/* Set timeout and calculate the expire run frequency */
timeout = get_exp_timeout(ap, map);
--- autofs-5.1.7.orig/include/automount.h
+++ autofs-5.1.7/include/automount.h
@@ -199,8 +199,7 @@ int cache_push_mapent(struct mapent *me,
int cache_pop_mapent(struct mapent *me);
struct mapent_cache *cache_init(struct autofs_point *ap, struct map_source *map);
struct mapent_cache *cache_init_null_cache(struct master *master);
-int cache_set_ino_index(struct mapent_cache *mc, const char *key, dev_t dev, ino_t ino);
-/* void cache_set_ino(struct mapent *me, dev_t dev, ino_t ino); */
+int cache_set_ino_index(struct mapent_cache *mc, struct mapent *me);
struct mapent *cache_lookup_ino(struct mapent_cache *mc, dev_t dev, ino_t ino);
struct mapent *cache_lookup_first(struct mapent_cache *mc);
struct mapent *cache_lookup_next(struct mapent_cache *mc, struct mapent *me);
--- autofs-5.1.7.orig/lib/cache.c
+++ autofs-5.1.7/lib/cache.c
@@ -290,20 +290,13 @@ static u_int32_t ino_hash(dev_t dev, ino
return hashval % size;
}
-int cache_set_ino_index(struct mapent_cache *mc, const char *key, dev_t dev, ino_t ino)
+int cache_set_ino_index(struct mapent_cache *mc, struct mapent *me)
{
- u_int32_t ino_index = ino_hash(dev, ino, mc->size);
- struct mapent *me;
-
- me = cache_lookup_distinct(mc, key);
- if (!me)
- return 0;
+ u_int32_t ino_index = ino_hash(me->dev, me->ino, mc->size);
ino_index_lock(mc);
list_del_init(&me->ino_index);
list_add(&me->ino_index, &mc->ino_index[ino_index]);
- me->dev = dev;
- me->ino = ino;
ino_index_unlock(mc);
return 1;
--- autofs-5.1.7.orig/lib/mounts.c
+++ autofs-5.1.7/lib/mounts.c
@@ -2761,10 +2761,20 @@ static int remount_active_mount(struct a
ops->close(ap->logopt, fd);
return REMOUNT_STAT_FAIL;
}
- if (type != t_indirect)
- cache_set_ino_index(me->mc, path, st.st_dev, st.st_ino);
- else
+ if (type == t_indirect)
ap->dev = st.st_dev;
+ else {
+ if (strcmp(path, me->key)) {
+ error(ap->logopt,
+ "mount point path mismatch, path %s mapent %s", path, me->key);
+ debug(ap->logopt, "couldn't re-connect to mount %s", path);
+ ops->close(ap->logopt, fd);
+ return REMOUNT_STAT_FAIL;
+ }
+ me->dev = st.st_dev;
+ me->ino = st.st_ino;
+ cache_set_ino_index(me->mc, me);
+ }
notify_mount_result(ap, path, timeout, str_type);
*ioctlfd = fd;

View File

@ -12,7 +12,7 @@
Summary: A tool for automatically mounting and unmounting filesystems
Name: autofs
Version: 5.1.7
Release: 51%{?dist}
Release: 52%{?dist}
Epoch: 1
License: GPLv2+
Source: https://www.kernel.org/pub/linux/daemons/autofs/v5/autofs-%{version}-2.tar.gz
@ -161,6 +161,27 @@ Patch135: autofs-5.1.8-fix-unterminated-read-in-handle_cmd_pipe_fifo_message.pat
Patch150: autofs-5.1.8-fix-memory-leak-in-sasl_do_kinit.patch
Patch151: autofs-5.1.8-fix-fix-mount-tree-startup-reconnect.patch
Patch152: autofs-5.1.8-fix-use_ignore_mount_option-description.patch
Patch153: autofs-5.1.8-include-addtional-log-info-for-mounts.patch
Patch154: autofs-5.1.8-fix-amd-selector-function-matching.patch
Patch155: autofs-5.1.8-get-rid-entry-thid-field.patch
Patch156: autofs-5.1.8-continue-expire-immediately-after-submount-check.patch
Patch157: autofs-5.1.7-add-buffer-length-checks-to-autofs-mount_mount.patch
Patch158: autofs-5.1.8-eliminate-realpath-from-mount-of-submount.patch
Patch159: autofs-5.1.8-eliminate-root-param-from-autofs-mount-and-umount.patch
Patch160: autofs-5.1.8-remove-redundant-stat-from-do_mount_direct.patch
Patch161: autofs-5.1.8-get-rid-of-strlen-call-in-handle_packet_missing_direct.patch
Patch162: autofs-5.1.8-remove-redundant-stat-call-in-lookup_ghost.patch
Patch163: autofs-5.1.8-set-mapent-dev-and-ino-before-adding-to-index.patch
Patch164: autofs-5.1.8-change-to-use-printf-functions-in-amd-parser.patch
Patch165: autofs-5.1.8-dont-call-umount_subtree_mounts-on-parent-at-umount.patch
Patch166: autofs-5.1.8-dont-take-parent-source-lock-at-mount-shutdown.patch
Patch167: autofs-5.1.7-eliminate-buffer-usage-from-handle_mounts_cleanup.patch
Patch168: autofs-5.1.8-fix-possible-use-after-free-in-handle_mounts_exit.patch
Patch169: autofs-5.1.8-make-submount-cleanup-the-same-as-top-level-mounts.patch
Patch170: autofs-5.1.8-add-soucre-parameter-to-module-functions.patch
Patch171: autofs-5.1.8-add-ioctlfd-open-helper.patch
Patch172: autofs-5.1.8-make-open-files-limit-configurable.patch
%if %{with_systemd}
BuildRequires: systemd-units
@ -366,6 +387,27 @@ echo %{version}-%{release} > .version
%patch150 -p1
%patch151 -p1
%patch152 -p1
%patch153 -p1
%patch154 -p1
%patch155 -p1
%patch156 -p1
%patch157 -p1
%patch158 -p1
%patch159 -p1
%patch160 -p1
%patch161 -p1
%patch162 -p1
%patch163 -p1
%patch164 -p1
%patch165 -p1
%patch166 -p1
%patch167 -p1
%patch168 -p1
%patch169 -p1
%patch170 -p1
%patch171 -p1
%patch172 -p1
%build
LDFLAGS=-Wl,-z,now
@ -474,6 +516,31 @@ fi
%dir /etc/auto.master.d
%changelog
* Tue Jun 13 2023 Ian Kent <ikent@redhat.com> - 1:5.1.7-52
- bz2210899 - amd map format netgoup selector function not working
- fix use_ignore_mount_option description.
- include addtional log info for mounts.
- fix amd selector function matching.
- get rid entry thid field.
- continue expire immediately after submount check.
- add buffer length checks to autofs mount_mount().
- eliminate realpath from mount of submount.
- eliminate root param from autofs mount and umount.
- remove redundant fstat from do_mount_direct().
- get rid of strlen call in handle_packet_missing_direct().
- remove redundant stat call in lookup_ghost().
- set mapent dev and ino before adding to index.
- change to use printf functions in amd parser.
- dont call umount_subtree_mounts() on parent at umount.
- dont take parent source lock at mount shutdown.
- eliminate buffer usage from handle_mounts_cleanup().
- fix possible use after free in handle_mounts_exit().
- make submount cleanup the same as top level mounts.
- add soucre parameter to module functions.
- add ioctlfd open helper.
- make open files limit configurable.
- Resolves: rhbz#2210899
* Fri Jun 02 2023 Ian Kent <ikent@redhat.com> - 1:5.1.7-51
- bz2210161 - autofs fails to start with combination of +auto.master and
local direct map lookups after upgrading to 5.1.4-93.el8