From: Sergey Senozhatsky <senozhatsky@chromium.org>
To: Namjae Jeon <linkinjeon@kernel.org>
Cc: Pumpkin <cc85nod@gmail.com>,
linux-cifs@vger.kernel.org, smfrench@gmail.com, tom@talpey.com,
atteh.mailbox@gmail.com,
Sergey Senozhatsky <senozhatsky@chromium.org>
Subject: Re: [PATCH 1/6] ksmbd: fix global-out-of-bounds in smb2_find_context_vals
Date: Tue, 9 May 2023 12:05:51 +0900 [thread overview]
Message-ID: <20230509030551.GE11511@google.com> (raw)
In-Reply-To: <CAKYAXd-upEqLP8zSqZbR0FcznGfWLejkqQ6QKLh=taxb0mMiLQ@mail.gmail.com>
On (23/05/08 21:58), Namjae Jeon wrote:
> 2023-05-08 10:05 GMT+09:00, Sergey Senozhatsky <senozhatsky@chromium.org>:
> > On (23/05/06 00:11), Namjae Jeon wrote:
> >> From: Pumpkin <cc85nod@gmail.com>
> >>
> >> If the length of CreateContext name is larger than the tag, it will
> >> access
> >> the data following the tag and trigger KASAN global-out-of-bounds.
> >>
> >> Currently all CreateContext names are defined as string, so we can use
> >> strcmp instead of memcmp to avoid the out-of-bound access.
> Hi Chih-Yen,
>
> Please reply to Sergey's review comment. If needed, please send v2
> patch after updating it.
Chih-Yen replied privately, but let me move the discussion back to
public list.
> >> +++ b/fs/ksmbd/oplock.c
> >> @@ -1492,7 +1492,7 @@ struct create_context *smb2_find_context_vals(void
> >> *open_req, const char *tag)
> >> return ERR_PTR(-EINVAL);
> >>
> >> name = (char *)cc + name_off;
> >> - if (memcmp(name, tag, name_len) == 0)
> >> + if (!strcmp(name, tag))
> >> return cc;
> >>
> >> remain_len -= next;
> >
> > I'm slightly surprised that that huge `if` before memcmp() doesn't catch
> > it
> >
> > if ((next & 0x7) != 0 ||
> > next > remain_len ||
> > name_off != offsetof(struct create_context, Buffer) ||
> > name_len < 4 ||
> > name_off + name_len > cc_len ||
> > (value_off & 0x7) != 0 ||
> > (value_off && (value_off < name_off + name_len)) ||
> > ((u64)value_off + value_len > cc_len))
> > return ERR_PTR(-EINVAL);
So the question is: why doesn't this `if` catch that problem?
I'd rather add one extra condition here, it doesn't make a lot
of sense to strcmp/memcmp if we know beforehand that two strings
have different sizes. So a simple "name len != context len" should
do the trick. No?
next prev parent reply other threads:[~2023-05-09 3:05 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-05 15:11 [PATCH 1/6] ksmbd: fix global-out-of-bounds in smb2_find_context_vals Namjae Jeon
2023-05-05 15:11 ` [PATCH 2/6] ksmbd: fix wrong UserName check in session_user Namjae Jeon
2023-05-06 3:10 ` Sergey Senozhatsky
2023-05-07 0:52 ` Namjae Jeon
2023-05-05 15:11 ` [PATCH 3/6] ksmbd: allocate one more byte for implied bcc[0] Namjae Jeon
2023-05-05 15:11 ` [PATCH 4/6] ksmbd: smb2: Allow messages padded to 8byte boundary Namjae Jeon
2023-05-05 15:11 ` [PATCH 5/6] ksmbd: remove unused ksmbd_tree_conn_share function Namjae Jeon
2023-05-08 1:07 ` Sergey Senozhatsky
2023-05-05 15:11 ` [PATCH 6/6] ksmbd: use kzalloc() instead of __GFP_ZERO Namjae Jeon
2023-05-08 1:06 ` Sergey Senozhatsky
2023-05-08 1:05 ` [PATCH 1/6] ksmbd: fix global-out-of-bounds in smb2_find_context_vals Sergey Senozhatsky
2023-05-08 12:58 ` Namjae Jeon
2023-05-09 3:05 ` Sergey Senozhatsky [this message]
[not found] ` <CAAn9K_vRCOtYZXRBDKY4GzPA-TyrQ_Zh-qssu51Vr6sTwg5w4w@mail.gmail.com>
2023-05-12 14:14 ` Namjae Jeon
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=20230509030551.GE11511@google.com \
--to=senozhatsky@chromium.org \
--cc=atteh.mailbox@gmail.com \
--cc=cc85nod@gmail.com \
--cc=linkinjeon@kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=smfrench@gmail.com \
--cc=tom@talpey.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 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.