Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SMB1 fixes #399

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

mmakassikis
Copy link

A few fixes SMB1 fixes:

  • ksmbd: smb1: remove unused parameter in find_next()
  • ksmbd: smb1: use kasprintf() instead of kzalloc+snprintf+strncat
  • ksmbd: smb1: Fix potential memleak in smb_nt_create_andx
  • ksmbd: smb1: add buffer validation

The first 3 ones small fixes. The last one is big, but it is essentially the same pattern repeated over and over again.

I tried sending to the linux-cifsd-devel list, but it looks like the project has been deleted from sourceforge.

auth.c Outdated
@@ -330,16 +330,23 @@ static int calc_ntlmv2_hash(struct ksmbd_session *sess, char *ntlmv2_hash,
* ksmbd_auth_ntlm() - NTLM authentication handler
* @sess: session of connection
* @pw_buf: NTLM challenge response
* @passkey: user password
* @pw_len: buffer length
* @cryptkey: buffer length
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- * @cryptkey:	buffer length
+ * @cryptkey: server challenge

auth.c Outdated Show resolved Hide resolved
@namjaejeon
Copy link
Owner

I have applied 3 patches first. I need more time to review "ksmbd: smb1: add buffer validation" patch.

@namjaejeon namjaejeon force-pushed the master branch 2 times, most recently from 80f76a4 to cdd2c68 Compare May 16, 2022 07:35
@namjaejeon namjaejeon force-pushed the master branch 2 times, most recently from 598c4b4 to 9ef42e9 Compare June 19, 2022 00:10
@namjaejeon
Copy link
Owner

@mmakassikis Sorry for checking "ksmbd: smb1: add buffer validation" patch. I will check it on weekend.
@hclee Hyunchul, please join to review it together.

@hclee
Copy link
Contributor

hclee commented Jun 24, 2022

@mmakassikis Sorry for checking "ksmbd: smb1: add buffer validation" patch. I will check it on weekend. @hclee Hyunchul, please join to review it together.

Okay, I will review this patch on weekend.

smb1pdu.c Outdated
pr_err("Unable to strdup() treename or devtype uid %d\n",
rsp_hdr->Uid);
offset += offsetof(struct smb_com_tconx_req, Password);
offset += le16_to_cpu(req->PasswordLength);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested if req->PasswordLength is zero ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If req->PasswordLength is zero, offset is unchanged (incidentally, the current code works because req->PasswordLength == le16_to_cpu(req->PasswordLength)).

I don't see what problems can arise with req->PasswordLength.

smb1pdu.c Outdated Show resolved Hide resolved
smb1pdu.c Show resolved Hide resolved
smb1pdu.c Outdated
@@ -1007,6 +1036,12 @@ static int build_sess_rsp_extsec(struct ksmbd_conn *conn,
negblob = (struct negotiate_message *)req->SecurityBlob;
sz = le16_to_cpu(req->SecurityBlobLength);

if (offsetof(struct smb_com_session_setup_req, SecurityBlob) + sz >
get_rfc1002_len(req)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check can be moved to smb1misc.c ?

@namjaejeon
Copy link
Owner

@mmakassikis When I checked smb1 buffer validation patch, You need to move some of validation codes to smb1misc.c. I think that you can check codes in smb2misc.c

{
struct andx_block *andx_ptr = (struct andx_block *)(buf +
sizeof(struct smb_hdr) - 1);
struct andx_block *next;

/* AndXOffset does not include 4 byte RFC1002 header */
len -= 4;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the "len" include 4-byte RFC1002 header?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buf is the full request (RFC1002 header, followed by SMB2 header and payload). len should those 4 bytes.

The code here is correct, but the caller code is wrong as it uses get_rfc1002_len() which is the buffer length minus 4.
This mistake is present in most if not all changes in this patch.

smb1pdu.c Outdated
else {
oldname_len = strlen(oldname);
oldname_len++;
}

offset += oldname_len + 2;
if (offset > maxlen) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of offset > maxlen, offset >= maxlen?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Actually, I thought it was ok as we passed a calculated length to smb_get_name(), but if the request is malformed, it's possible to have offset > maxlen, in which case the negative "maxlen - offset" will cause an infinite loop in smb_utf16_bytes().

I will update the patch to check offset >= maxlen before calling smb_get_name().

smb1pdu.c Outdated Show resolved Hide resolved
smb1pdu.c Outdated Show resolved Hide resolved
smb1pdu.c Outdated
@@ -1936,9 +1982,18 @@ int smb_trans(struct ksmbd_work *work)
if (req->SetupCount)
setup_bytes_count = 2 * req->SetupCount;

maxlen = get_rfc1002_len(req);
offset = offsetof(struct smb_com_trans_req, Data);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't 1-byte, smb_com_trans_req.Data[1] need to be considered?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand.

Currently, the code parses up to 256 bytes starting from req->Data + setup_bytes_count. My change initializes the offset to req->Data. Whether the Data field is Data[0] or Data[1] doesn't matter, no ?

@namjaejeon namjaejeon force-pushed the master branch 7 times, most recently from d055654 to 7202068 Compare July 25, 2022 04:06
@namjaejeon namjaejeon force-pushed the master branch 9 times, most recently from c683c7d to 04bf112 Compare July 29, 2022 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants