public inbox for linux-cifs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mount.cifs: fix buffer overrun in set_password
@ 2026-03-31  0:09 David Disseldorp
  2026-03-31 17:44 ` Henrique Carvalho
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: David Disseldorp @ 2026-03-31  0:09 UTC (permalink / raw)
  To: linux-cifs; +Cc: Steve French, David Disseldorp, Bruno Bierbaumer

The existing (j > pass_length) check is insufficient to avoid dst buffer
overrun into the start of the adjacent struct parsed_mount_info field.
Check for overrun before writing to dst, and account for comma-expansion
and null-termination.

Bug: https://bugzilla.samba.org/show_bug.cgi?id=16044

Reported-by: Bruno Bierbaumer <bruno@bierbaumer.net>
Signed-off-by: David Disseldorp <ddiss@suse.de>
---
 mount.cifs.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/mount.cifs.c b/mount.cifs.c
index 1923913..d41ca6a 100644
--- a/mount.cifs.c
+++ b/mount.cifs.c
@@ -350,13 +350,13 @@ set_password(struct parsed_mount_info *parsed_info, const char *src,
 	unsigned int i = 0, j = 0;
 
 	while (src[i]) {
-		if (src[i] == ',')
-			dst[j++] = ',';
-		dst[j++] = src[i++];
-		if (j > pass_length) {
+		if (j + 2 >= pass_length) {
 			fprintf(stderr, "Converted password too long!\n");
 			return EX_USAGE;
 		}
+		if (src[i] == ',')
+			dst[j++] = ',';
+		dst[j++] = src[i++];
 	}
 	dst[j] = '\0';
 	if (is_pass2)
-- 
2.51.0


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

end of thread, other threads:[~2026-04-02  1:23 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-31  0:09 [PATCH] mount.cifs: fix buffer overrun in set_password David Disseldorp
2026-03-31 17:44 ` Henrique Carvalho
2026-03-31 23:56 ` Steve French
2026-04-01  0:58   ` David Disseldorp
2026-04-01  2:03     ` Steve French
2026-04-01 13:40 ` Enzo Matsumiya
2026-04-01 15:24   ` Henrique Carvalho
2026-04-02  1:23     ` David Disseldorp

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