mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ovl: reject lowerdir ending with unescaped backslash
@ 2026-10-12  6:08 Guanglei Zhu
  2026-10-12  9:47 ` Amir Goldstein
  2026-10-12  9:55 ` [PATCH v2] " Guanglei Zhu
  0 siblings, 2 replies; 6+ messages in thread
From: Guanglei Zhu @ 2026-10-12  6:08 UTC (permalink / raw)
  To: Miklos Szeredi, Amir Goldstein; +Cc: linux-unionfs, linux-kernel, liuc63

In ovl_parse_param_split_lowerdirs() the escape handling consumes
the backslash and the character after it.  When the backslash is the
last character of the lowerdir value, the loop increment moves the
cursor past the NUL terminator, so the loop scans heap memory beyond
the kstrdup'd string until it happens to hit a zero byte; a colon
found there is written over as well.

A trailing unescaped backslash escapes nothing, so reject it with
EINVAL.

Signed-off-by: Guanglei Zhu <zhugl3@xiaopeng.com>
---
Found by code inspection.  Behavior check in a QEMU guest:
fsconfig(lowerdir="...\") on an unpatched kernel returns -ENOENT
after the loop scanned past the allocation; with this patch it
returns -EINVAL.

 fs/overlayfs/params.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/overlayfs/params.c b/fs/overlayfs/params.c
index c93fcaa45..5a15e5478 100644
--- a/fs/overlayfs/params.c
+++ b/fs/overlayfs/params.c
@@ -216,6 +216,9 @@ static ssize_t ovl_parse_param_split_lowerdirs(char *str)
 		if (*s == '\\') {
 			/* keep esc chars in split lowerdir */
 			*d++ = *s++;
+			/* A trailing backslash escapes nothing. */
+			if (!*s)
+				return -EINVAL;
 		} else if (*s == ':') {
 			bool next_colon = (*(s + 1) == ':');
 
-- 
2.43.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-10-12 10:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-12  6:08 [PATCH] ovl: reject lowerdir ending with unescaped backslash Guanglei Zhu
2026-10-12  9:47 ` Amir Goldstein
2026-10-12  9:55 ` [PATCH v2] " Guanglei Zhu
2026-10-12 10:11   ` Amir Goldstein
2026-10-12 10:45     ` Christian Brauner
2026-10-12 10:44   ` Christian Brauner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®