Re: [PATCH] mount.cifs: fix buffer overrun in set_password

Steve French
2026-03-31T23:56:17Z

added RB from Henrique and updated
git.samba.org/data/git/cifs-utils.git and
https://github.com/smfrench/smb3-utils for-next

On Mon, Mar 30, 2026 at 7:10 PM David Disseldorp <ddiss@suse.de> wrote:
>
> 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
>

--
Thanks,

Steve