mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
To: Steve French <smfrench@gmail.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>,
	Steve French <sfrench@samba.org>,
	Stefan Metzmacher <metze@samba.org>,
	samba-technical <samba-technical@lists.samba.org>,
	LKML <linux-kernel@vger.kernel.org>,
	ronnie sahlberg <ronniesahlberg@gmail.com>
Subject: Re: [PATCH] cifs: potential buffer overflow in handling symlinks
Date: Wed, 13 Apr 2022 14:05:47 +0530	[thread overview]
Message-ID: <3cec4568-1a54-2ca9-57d6-ee6635d59a3b@oracle.com> (raw)
In-Reply-To: <CAH2r5mvBH8wO9rS2UwCpgjbhcLp89-RLbr1wxK76Pj=OprKwOA@mail.gmail.com>

Hi Steve,
On 13/04/22 4:02 am, Steve French wrote:
> Wouldn't it be easier and clearer to do the compare vs the maximum len ie
> 
> if (link_len > CIFS_MF_SYMLINK_LINK_MAXLEN)
> 
Yes, thats cleaner. Will send a v2 patch.

Thanks,
Harshit
> instead of
> 
> if (link_len > buf_len - CIFS_MF_SYMLINK_LINK_OFFSET)
> 
> since buf_len is  CIFS_MF_SYMLINK_FILE_SIZE and looking at link.c line
> 26 and 27 this means we can use CIFS_MF_SYMLINK_LINK_OFFSET for the
> comparison:
> 
> #define CIFS_MF_SYMLINK_LINK_MAXLEN (1024)
> #define CIFS_MF_SYMLINK_FILE_SIZE \
>          (CIFS_MF_SYMLINK_LINK_OFFSET + CIFS_MF_SYMLINK_LINK_MAXLEN)
> 
> On Tue, Apr 12, 2022 at 1:01 AM Harshit Mogalapalli
> <harshit.m.mogalapalli@oracle.com> wrote:
>>
>> Smatch printed a warning:
>>          arch/x86/crypto/poly1305_glue.c:198 poly1305_update_arch() error:
>>          __memcpy() 'dctx->buf' too small (16 vs u32max)
>>
>> It's caused because Smatch marks 'link_len' as untrusted since it comes
>> from sscanf(). Add a check to ensure that 'link_len' is not larger than
>> the size of the 'link_str' buffer.
>>
>> Fixes: c69c1b6eaea1 ("cifs: implement CIFSParseMFSymlink()")
>> Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
>> ---
>>   fs/cifs/link.c | 3 +++
>>   1 file changed, 3 insertions(+)
>>
>> diff --git a/fs/cifs/link.c b/fs/cifs/link.c
>> index 852e54e..ebfedae 100644
>> --- a/fs/cifs/link.c
>> +++ b/fs/cifs/link.c
>> @@ -85,6 +85,9 @@
>>          if (rc != 1)
>>                  return -EINVAL;
>>
>> +       if (link_len > buf_len - CIFS_MF_SYMLINK_LINK_OFFSET)
>> +               return -EINVAL;
>> +
>>          rc = symlink_hash(link_len, link_str, md5_hash);
>>          if (rc) {
>>                  cifs_dbg(FYI, "%s: MD5 hash failure: %d\n", __func__, rc);
>> --
>> 1.8.3.1
>>
> 
> 


      reply	other threads:[~2022-04-13  8:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-12  4:38 Harshit Mogalapalli
2022-04-12 22:32 ` Steve French
2022-04-13  8:35   ` Harshit Mogalapalli [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=3cec4568-1a54-2ca9-57d6-ee6635d59a3b@oracle.com \
    --to=harshit.m.mogalapalli@oracle.com \
    --cc=dan.carpenter@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=metze@samba.org \
    --cc=ronniesahlberg@gmail.com \
    --cc=samba-technical@lists.samba.org \
    --cc=sfrench@samba.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

all inboxes | Powered by JetHome®