All of lore.kernel.org
 help / color / mirror / Atom feed
From: Namjae Jeon <linkinjeon@kernel.org>
To: Marios Makassikis <mmakassikis@freebox.fr>
Cc: CIFS <linux-cifs@vger.kernel.org>
Subject: Re: [PATCH v2] ksmbd: add buffer validation in session setup
Date: Tue, 19 Oct 2021 08:17:12 +0900	[thread overview]
Message-ID: <CAKYAXd9tAmRBMLEwpb6RCOEchL58JNgUWABEv5KAsZ+uAoFWDg@mail.gmail.com> (raw)
In-Reply-To: <CAF6XXKWCn2bSV4o=r0q7gO3H029y-jLZ4CReHABEEOwk6S4T_g@mail.gmail.com>

2021-10-18 23:49 GMT+09:00, Marios Makassikis <mmakassikis@freebox.fr>:
> On Mon, Oct 18, 2021 at 4:04 PM Namjae Jeon <linkinjeon@kernel.org> wrote:
>>
>> Hi Marios,
>> > +     negblob_off = le16_to_cpu(req->SecurityBufferOffset);
>> > +     negblob_len = le16_to_cpu(req->SecurityBufferLength);
>> > +     if (negblob_off < (offsetof(struct smb2_sess_setup_req, Buffer) -
>> > 4))
>> > +             return -EINVAL;
>> Like the following code, negblob is still used without buffer check.
>> We need to add buffer check for it here ?
>>
>> if (negblob->MessageType == NtLmNegotiate) {
>>
>> } else if (negblob->MessageType == NtLmAuthenticate) {
>>
>> Thanks!
>>
> Hello Namjae,
>
> I'm not sure I understand what you mean. Should I change the check to
> something like this ?
>
> +       negblob_off = le16_to_cpu(req->SecurityBufferOffset);
> +       negblob_len = le16_to_cpu(req->SecurityBufferLength);
> +       if (negblob_off < (offsetof(struct smb2_sess_setup_req, Buffer) - 4)
> ||
> +           negblob_len < sizeof(struct negotiate_message))
negblob_len < offsetof(struct negotiate_message, NegotiateFlags))

Thanks!

>
> Marios
>
>> > +
>> >       negblob = (struct negotiate_message *)((char
>> > *)&req->hdr.ProtocolId +
>> > -                     le16_to_cpu(req->SecurityBufferOffset));
>> > +                     negblob_off);
>> >
>> > -     if (decode_negotiation_token(work, negblob) == 0) {
>> > +     if (decode_negotiation_token(conn, negblob, negblob_len) == 0) {
>> >               if (conn->mechToken)
>> >                       negblob = (struct negotiate_message
>> > *)conn->mechToken;
>> >       }
>> > @@ -1736,7 +1746,7 @@ int smb2_sess_setup(struct ksmbd_work *work)
>> >                       sess->Preauth_HashValue = NULL;
>> >               } else if (conn->preferred_auth_mech ==
>> > KSMBD_AUTH_NTLMSSP) {
>> >                       if (negblob->MessageType == NtLmNegotiate) {
>> > -                             rc = ntlm_negotiate(work, negblob);
>> > +                             rc = ntlm_negotiate(work, negblob,
>> > negblob_len);
>> >                               if (rc)
>> >                                       goto out_err;
>> >                               rsp->hdr.Status =
>> > --
>> > 2.25.1
>> >
>> >
>

      reply	other threads:[~2021-10-18 23:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-16 23:57 [PATCH v2] ksmbd: add buffer validation in session setup Marios Makassikis
2021-10-18 14:04 ` Namjae Jeon
2021-10-18 14:49   ` Marios Makassikis
2021-10-18 23:17     ` Namjae Jeon [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=CAKYAXd9tAmRBMLEwpb6RCOEchL58JNgUWABEv5KAsZ+uAoFWDg@mail.gmail.com \
    --to=linkinjeon@kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=mmakassikis@freebox.fr \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.