[packages/autofs] Rel 7. Add upstream memory safety fixes.

arekm arekm at pld-linux.org
Wed Nov 11 23:34:08 CET 2026


commit dde55ddcf7c6c8cdf4ea9ce4b29b70d50725d5cf
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Wed Nov 11 23:10:39 2026 +0100

    Rel 7. Add upstream memory safety fixes.
    
    Fixes stack overflows in prepend_opt() (AMD map options) and
    merge_options(), heap overflow in LDAP match_key(), off-by-one in
    macro_init(), from upstream patches-5.2.0.

 ...-5.1.9-fix-buffer-overflow-in-prepend_opt.patch | 129 +++++++++++++++++++++
 ...1.9-fix-incorrect-allocation-in-match_key.patch |  23 ++++
 ...-5.1.9-fix-off-by-one-error-in-macro_init.patch |  39 +++++++
 ...-fix-string-length-check-in-merge_options.patch |  79 +++++++++++++
 autofs.spec                                        |  10 +-
 5 files changed, 279 insertions(+), 1 deletion(-)
---
diff --git a/autofs.spec b/autofs.spec
index be1d7d5..3529169 100644
--- a/autofs.spec
+++ b/autofs.spec
@@ -14,7 +14,7 @@ Summary(pt_BR.UTF-8):	Servidor autofs
 Summary(tr.UTF-8):	autofs sunucu süreci
 Name:		autofs
 Version:	5.1.9
-Release:	6
+Release:	7
 Epoch:		1
 License:	GPL v2+
 Group:		Daemons
@@ -46,6 +46,10 @@ Patch115:	autofs-5.1.9-refactor-amd-mount-options-handling.patch
 Patch116:	autofs-5.1.9-add-some-unimplemented-amd-map-options.patch
 Patch117:	autofs-5.1.9-fix-get-parent-multi-mount-check-in-try_remount.patch
 Patch118:	autofs-5.1.9-fix-deadlock-in-remount.patch
+Patch119:	autofs-5.1.9-fix-string-length-check-in-merge_options.patch
+Patch120:	autofs-5.1.9-fix-off-by-one-error-in-macro_init.patch
+Patch121:	autofs-5.1.9-fix-incorrect-allocation-in-match_key.patch
+Patch122:	autofs-5.1.9-fix-buffer-overflow-in-prepend_opt.patch
 URL:		https://git.kernel.org/pub/scm/linux/storage/autofs/autofs.git
 BuildRequires:	autoconf >= 2.50
 BuildRequires:	automake
@@ -154,6 +158,10 @@ przechowywanych na serwerze LDAP.
 %patch -P116 -p1
 %patch -P117 -p1
 %patch -P118 -p1
+%patch -P119 -p1
+%patch -P120 -p1
+%patch -P121 -p1
+%patch -P122 -p1
 
 %build
 %{__autoconf}
diff --git a/autofs-5.1.9-fix-buffer-overflow-in-prepend_opt.patch b/autofs-5.1.9-fix-buffer-overflow-in-prepend_opt.patch
new file mode 100644
index 0000000..3d972e0
--- /dev/null
+++ b/autofs-5.1.9-fix-buffer-overflow-in-prepend_opt.patch
@@ -0,0 +1,129 @@
+autofs-5.1.9 - fix buffer overflow in prepend_opt()
+
+From: Ian Kent <raven at themaw.net>
+
+A stack buffer overflow and missing NULL terminator in prepend_opt()
+which affects autofs versions from 5.1.0 has been identified.
+
+When building mount options an oversized AMD map `OPTION` token can
+overflow the fixed 1024-byte stack buffer used to build mount options
+and the copied-back string also loses its terminating NULL during AMD
+map parsing.
+
+Fix it by making prepend_opt() bounded, copy back the terminating
+`\0`, and fail parsing when the combined option string would exceed
+`MAX_OPTS_LEN`.
+
+This patch was provided as part of a vulnerability report which was
+generated using AI technology.
+
+Reported-By: AISLE Research
+Fixes: 6f065977a6 ("autofs-5.0.9 - amd lookup add parse_amd.c")
+Signed-off-by: Ian Kent <raven at themaw.net>
+[PLD: CHANGELOG hunk dropped to apply outside upstream patch_order]
+---
+diff --git a/modules/amd_parse.y b/modules/amd_parse.y
+index 416f2289f..d606b6293 100644
+--- a/modules/amd_parse.y
++++ b/modules/amd_parse.y
+@@ -67,7 +67,7 @@ static struct list_head *entries;
+ static struct autofs_point *pap;
+ struct substvar *psv;
+ static char opts[MAX_OPTS_LEN];
+-static void prepend_opt(char *, char *);
++static int prepend_opt(char *, char *);
+ static char msg_buf[MAX_ERR_LEN];
+ 
+ #define YYDEBUG 0
+@@ -438,18 +438,24 @@ option_assignment: MAP_OPTION OPTION_ASSIGN FS_TYPE
+ 
+ options: OPTION
+ 	{
+-		if (match_mnt_option($1, opts))
+-			prepend_opt(opts, $1);
++		if (match_mnt_option($1, opts) && !prepend_opt(opts, $1)) {
++			amd_msg("mount options too long");
++			YYABORT;
++		}
+ 	}
+ 	| OPTION COMMA options
+ 	{
+-		if (match_mnt_option($1, opts))
+-			prepend_opt(opts, $1);
++		if (match_mnt_option($1, opts) && !prepend_opt(opts, $1)) {
++			amd_msg("mount options too long");
++			YYABORT;
++		}
+ 	}
+ 	| OPTION COMMA
+ 	{
+-		if (match_mnt_option($1, opts))
+-			prepend_opt(opts, $1);
++		if (match_mnt_option($1, opts) && !prepend_opt(opts, $1)) {
++			amd_msg("mount options too long");
++			YYABORT;
++		}
+ 	}
+ 	;
+ 
+@@ -663,9 +669,10 @@ static int match_mnt_option(char *option, char *options)
+ 		entry.flags &= ~AMD_MOUNT_OPT_NOUNMOUNT;
+ 		entry.flags |= AMD_MOUNT_OPT_UNMOUNT;
+ 	} else if (!strcmp(option, "nounmount")) {
+-		if (entry.flags & AMD_MOUNT_TYPE_AUTO)
+-			prepend_opt(opts, "timeout=0");
+-		else {
++		if (entry.flags & AMD_MOUNT_TYPE_AUTO) {
++			if (!prepend_opt(opts, "timeout=0"))
++				goto out;
++		} else {
+ 			entry.flags &= ~AMD_MOUNT_OPT_UNMOUNT;
+ 			entry.flags |= AMD_MOUNT_OPT_NOUNMOUNT;
+ 			entry.utimeout = 0;
+@@ -677,9 +684,10 @@ static int match_mnt_option(char *option, char *options)
+ 		 * the root so there's no need for special handling,
+ 		 * just pass the timeout=<seconds> autofs option.
+ 		 */
+-		if (entry.flags & AMD_MOUNT_TYPE_AUTO)
+-			prepend_opt(options, ++option);
+-		else {
++		if (entry.flags & AMD_MOUNT_TYPE_AUTO) {
++			if (!prepend_opt(options, ++option))
++				goto out;
++		} else {
+ 			if (strchr(option, '=')) {
+ 				unsigned long tout;
+ 				int ret;
+@@ -693,19 +701,24 @@ static int match_mnt_option(char *option, char *options)
+ 		}
+ 	} else
+ 		ret = 1;
+-
++out:
+ 	return ret;
+ }
+ 
+-static void prepend_opt(char *dest, char *opt)
++static int prepend_opt(char *dest, char *opt)
+ {
+ 	char new[MAX_OPTS_LEN];
+-	strcpy(new, opt);
+-	if (*dest != '\0') {
+-		strcat(new, ",");
+-		strcat(new, dest);
+-	}
+-	memmove(dest, new, strlen(new));
++	int n;
++
++	if (!dest || !opt)
++		return 0;
++
++	n = snprintf(new, sizeof(new), (*dest != '\0') ? "%s,%s" : "%s", opt, dest);
++	if (n < 0 || n >= (int) sizeof(new))
++		return 0;
++
++	memmove(dest, new, (size_t) n + 1);
++	return 1;
+ }
+ 
+ #if YYDEBUG
diff --git a/autofs-5.1.9-fix-incorrect-allocation-in-match_key.patch b/autofs-5.1.9-fix-incorrect-allocation-in-match_key.patch
new file mode 100644
index 0000000..2ca7758
--- /dev/null
+++ b/autofs-5.1.9-fix-incorrect-allocation-in-match_key.patch
@@ -0,0 +1,23 @@
+autofs-5.1.9 - fix incorrect allocation in match_key()
+
+From: Ian Kent <raven at themaw.net>
+
+There's a mistake in the length of the string used in matching
+amd map keys in the ldap module match_key() function.
+
+Signed-off-by: Ian Kent <raven at themaw.net>
+[PLD: CHANGELOG hunk dropped to apply outside upstream patch_order]
+---
+diff --git a/modules/lookup_ldap.c b/modules/lookup_ldap.c
+index 53416c6fc..d27a6bb83 100644
+--- a/modules/lookup_ldap.c
++++ b/modules/lookup_ldap.c
+@@ -3721,7 +3721,7 @@ static int match_key(struct autofs_point *ap,
+ 		char *match;
+ 		size_t len;
+ 		*prefix = '\0';
+-		len = strlen(lkp_key + 3);
++		len = strlen(lkp_key) + 3;
+ 		match = malloc(len);
+ 		if (!match) {
+ 			char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
diff --git a/autofs-5.1.9-fix-off-by-one-error-in-macro_init.patch b/autofs-5.1.9-fix-off-by-one-error-in-macro_init.patch
new file mode 100644
index 0000000..666ee10
--- /dev/null
+++ b/autofs-5.1.9-fix-off-by-one-error-in-macro_init.patch
@@ -0,0 +1,39 @@
+autofs-5.1.9 - fix off by one error in macro_init()
+
+From: Ian Kent <raven at themaw.net>
+
+If gethostname() succeeds then the NULL terminated host name is returned
+up to the maximum length of the passed in buffer. But in the man page it
+isn't specified whether the NULL terminator is included in that length.
+
+In any case the host plus domain name in total cannot be greater than
+HOST_NAME_MAX + 1, including a NULL terminator.
+
+Since short name may take the full length of the array it should be
+HOST_NAME_MAX + 1 not HOST_NAME_MAX.
+
+Signed-off-by: Ian Kent <raven at themaw.net>
+[PLD: CHANGELOG hunk dropped to apply outside upstream patch_order]
+---
+diff --git a/lib/macros.c b/lib/macros.c
+index 5def26da8..b1f36596d 100644
+--- a/lib/macros.c
++++ b/lib/macros.c
+@@ -25,7 +25,7 @@
+ static struct utsname un;
+ static char processor[65];		/* Not defined on Linux, so we make our own */
+ static char hostname[HOST_NAME_MAX + 1];
+-static char host[HOST_NAME_MAX];
++static char host[HOST_NAME_MAX + 1];
+ static char domain[HOST_NAME_MAX];
+ static char hostd[HOST_NAME_MAX + 1];
+ static char endian[] = "unknown";
+@@ -80,7 +80,7 @@ void macro_init(void)
+ 	char *local_domain;
+ 
+ 	memset(hostname, 0, HOST_NAME_MAX + 1);
+-	memset(host, 0, HOST_NAME_MAX);
++	memset(host, 0, HOST_NAME_MAX + 1);
+ 	memset(domain, 0, HOST_NAME_MAX);
+ 	memset(hostd, 0, HOST_NAME_MAX + 1);
+ 
diff --git a/autofs-5.1.9-fix-string-length-check-in-merge_options.patch b/autofs-5.1.9-fix-string-length-check-in-merge_options.patch
new file mode 100644
index 0000000..a7245cd
--- /dev/null
+++ b/autofs-5.1.9-fix-string-length-check-in-merge_options.patch
@@ -0,0 +1,79 @@
+autofs-5.1.9 - fix string length check in merge_options()
+
+From: Ian Kent <raven at themaw.net>
+
+In function merge_options() an incorrect variable is used for a length
+check.
+
+Fix this and also initialize the local variable before use as well as
+store it's length to avoid multiple strlen() calls.
+
+Signed-off-by: Ian Kent <raven at themaw.net>
+[PLD: CHANGELOG hunk dropped to apply outside upstream patch_order]
+---
+diff --git a/lib/parse_subs.c b/lib/parse_subs.c
+index d48fdee2a..2acb056ba 100644
+--- a/lib/parse_subs.c
++++ b/lib/parse_subs.c
+@@ -971,9 +971,10 @@ char *merge_options(const char *opt1, const char *opt2)
+ 	if (!strcmp(opt1, opt2))
+ 		return strdup(opt1);
+ 
+-	if (strlen(str) > MAX_OPTIONS_LEN)
++	if (strlen(opt1) > MAX_OPTIONS_LEN)
+ 		return NULL;
+ 	memset(result, 0, sizeof(result));
++	str[0] = 0;
+ 	strcpy(str, opt1);
+ 
+ 	resultlen = 0;
+@@ -981,10 +982,12 @@ char *merge_options(const char *opt1, const char *opt2)
+ 	while (tok) {
+ 		const char *this = (const char *) tok;
+ 		char *eq = strchr(this, '=');
++		size_t this_len = strlen(this);
++
+ 		if (eq) {
+ 			*eq = '\0';
+ 			if (!hasopt(opt2, this)) {
+-				if (resultlen + strlen(this) > MAX_OPTIONS_LEN)
++				if (resultlen + this_len > MAX_OPTIONS_LEN)
+ 					return NULL;
+ 				*eq = '=';
+ 				if (!*result)
+@@ -992,7 +995,7 @@ char *merge_options(const char *opt1, const char *opt2)
+ 				else
+ 					strcat(result, this);
+ 				strcat(result, ",");
+-				resultlen += strlen(this) + 1;
++				resultlen += this_len + 1;
+ 				goto next;
+ 			}
+ 		}
+@@ -1019,7 +1022,7 @@ char *merge_options(const char *opt1, const char *opt2)
+ 			if (hasopt(opt2, neg))
+ 				goto next;
+ 		} else {
+-			if ((strlen(this) + 2) > MAX_OPTION_LEN)
++			if ((this_len + 2) > MAX_OPTION_LEN)
+ 				return NULL;
+ 			strcpy(neg, "no");
+ 			strcat(neg, this);
+@@ -1030,7 +1033,7 @@ char *merge_options(const char *opt1, const char *opt2)
+ 		if (hasopt(opt2, tok))
+ 			goto next;
+ 
+-		if (resultlen + strlen(this) + 1 > MAX_OPTIONS_LEN)
++		if ((resultlen + this_len + 1) > MAX_OPTIONS_LEN)
+ 			return NULL;
+ 
+ 		if (!*result)
+@@ -1038,7 +1041,7 @@ char *merge_options(const char *opt1, const char *opt2)
+ 		else
+ 			strcat(result, this);
+ 		strcat(result, ",");
+-		resultlen =+ strlen(this) + 1;
++		resultlen += this_len + 1;
+ next:
+ 		tok = strtok_r(NULL, ",", &ptr);
+ 	}
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/autofs.git/commitdiff/dde55ddcf7c6c8cdf4ea9ce4b29b70d50725d5cf



More information about the pld-cvs-commit mailing list