public inbox for linux-cifs@vger.kernel.org
 help / color / mirror / Atom feed
From: David Disseldorp <ddiss@suse.de>
To: Henrique Carvalho <henrique.carvalho@suse.com>
Cc: Enzo Matsumiya <ematsumiya@suse.de>,
	linux-cifs@vger.kernel.org, Steve French <smfrench@gmail.com>,
	Bruno Bierbaumer <bruno@bierbaumer.net>
Subject: Re: [PATCH] mount.cifs: fix buffer overrun in set_password
Date: Thu, 2 Apr 2026 12:23:02 +1100	[thread overview]
Message-ID: <20260402122302.27553b2c.ddiss@suse.de> (raw)
In-Reply-To: <cauglxiqmzregxmz7qu3ervva3qiszmgs4xeiczmlpwuzmi4lk@6hgpziq22o6p>

Thanks for the feedback, Enzo and Henrique...

On Wed, 1 Apr 2026 12:24:37 -0300, Henrique Carvalho wrote:

> On Wed, Apr 01, 2026 at 10:40:41AM -0300, Enzo Matsumiya wrote:
> > Hi Dave,
> > 
> > On 03/31, David Disseldorp 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) {  
> > 
> > There is the overrun bug, yes, but unconditionally accounting for comma
> > expansion here will crop the password if it has at least 1 comma and
> > (unparsed) length == MOUNT_PASSWD_SIZE, e.g.:
> > 
> > (password here is <511 * 'a'> + ',')
> > 
> > # echo -e "username=administrator\npassword=$(printf 'a%.0s' {1..511})," > /tmp/creds
> > # ./mount.cifs -o credentials=/tmp/creds //w25.vm.test/test /mnt/test
> > Converted password too long!
> > error 1 (Operation not permitted) opening credential file /tmp/creds

Yes, it's a valid point. I did consider it, but decided against it as:
- it makes the code slightly more complex, and adds more
  password-content based logic
- length restrictions are already opaque and confusing
  + "it broke when I changed password from 300x ':' to 300x ',' - why?"
- we're cropping the field any way (oversize pws were previously still
  passed to the kernel)

> > Maybe password/password2 could be malloc'd with size
> > "strlen(src) + <number of commas in src>" and bounds checked against that?
> > Just a thought.
> >   
> 
> Maybe we could have buffers double the size, but that would represent a
> behavior change. Passwords containing commas were never guaranteed to
> fit in current MOUNT_PASSWD_SIZE sized buffers.

These options would still leave us with password-content specific
behaviour, which seems fragile (open to side-channels attacks, etc).
Shouldn't the new mount API allow for the password to be passed though
to the kernel individually, and in-turn completely avoid comma escaping?

> I believe this would be a separate chage.

Agreed.

      reply	other threads:[~2026-04-02  1:23 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260402122302.27553b2c.ddiss@suse.de \
    --to=ddiss@suse.de \
    --cc=bruno@bierbaumer.net \
    --cc=ematsumiya@suse.de \
    --cc=henrique.carvalho@suse.com \
    --cc=linux-cifs@vger.kernel.org \
    --cc=smfrench@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox