|
| 1 | +smb: client: fix parsing of SMB3.1.1 POSIX create context |
| 2 | + |
| 3 | +jira LE-1907 |
| 4 | +cve CVE-2023-52434 |
| 5 | +Rebuild_History Non-Buildable kernel-5.14.0-427.16.1.el9_4 |
| 6 | +commit-author Paulo Alcantara < [email protected]> |
| 7 | +commit 76025cc2285d9ede3d717fe4305d66f8be2d9346 |
| 8 | +Empty-Commit: Cherry-Pick Conflicts during history rebuild. |
| 9 | +Will be included in final tarball splat. Ref for failed cherry-pick at: |
| 10 | +ciq/ciq_backports/kernel-5.14.0-427.16.1.el9_4/76025cc2.failed |
| 11 | + |
| 12 | +The data offset for the SMB3.1.1 POSIX create context will always be |
| 13 | +8-byte aligned so having the check 'noff + nlen >= doff' in |
| 14 | +smb2_parse_contexts() is wrong as it will lead to -EINVAL because noff |
| 15 | ++ nlen == doff. |
| 16 | + |
| 17 | +Fix the sanity check to correctly handle aligned create context data. |
| 18 | + |
| 19 | +Fixes: af1689a9b770 ("smb: client: fix potential OOBs in smb2_parse_contexts()") |
| 20 | + Signed-off-by: Paulo Alcantara < [email protected]> |
| 21 | + Signed-off-by: Steve French < [email protected]> |
| 22 | +(cherry picked from commit 76025cc2285d9ede3d717fe4305d66f8be2d9346) |
| 23 | + Signed-off-by: Jonathan Maple < [email protected]> |
| 24 | + |
| 25 | +# Conflicts: |
| 26 | +# fs/smb/client/smb2pdu.c |
| 27 | +diff --cc fs/smb/client/smb2pdu.c |
| 28 | +index 456aa71f0a98,ec39dfbc3154..000000000000 |
| 29 | +--- a/fs/smb/client/smb2pdu.c |
| 30 | ++++ b/fs/smb/client/smb2pdu.c |
| 31 | +@@@ -2152,31 -2269,46 +2152,58 @@@ smb2_parse_contexts(struct TCP_Server_I |
| 32 | + if (buf) |
| 33 | + buf->IndexNumber = 0; |
| 34 | + |
| 35 | +++<<<<<<< HEAD |
| 36 | + + while (remaining >= sizeof(struct create_context)) { |
| 37 | + + name = le16_to_cpu(cc->NameOffset) + (char *)cc; |
| 38 | + + if (le16_to_cpu(cc->NameLength) == 4 && |
| 39 | + + strncmp(name, SMB2_CREATE_REQUEST_LEASE, 4) == 0) |
| 40 | + + *oplock = server->ops->parse_lease_buf(cc, epoch, |
| 41 | + + lease_key); |
| 42 | + + else if (buf && (le16_to_cpu(cc->NameLength) == 4) && |
| 43 | + + strncmp(name, SMB2_CREATE_QUERY_ON_DISK_ID, 4) == 0) |
| 44 | + + parse_query_id_ctxt(cc, buf); |
| 45 | + + else if ((le16_to_cpu(cc->NameLength) == 16)) { |
| 46 | + + if (posix && |
| 47 | + + memcmp(name, smb3_create_tag_posix, 16) == 0) |
| 48 | +++======= |
| 49 | ++ while (rem >= sizeof(*cc)) { |
| 50 | ++ doff = le16_to_cpu(cc->DataOffset); |
| 51 | ++ dlen = le32_to_cpu(cc->DataLength); |
| 52 | ++ if (check_add_overflow(doff, dlen, &len) || len > rem) |
| 53 | ++ return -EINVAL; |
| 54 | ++ |
| 55 | ++ noff = le16_to_cpu(cc->NameOffset); |
| 56 | ++ nlen = le16_to_cpu(cc->NameLength); |
| 57 | ++ if (noff + nlen > doff) |
| 58 | ++ return -EINVAL; |
| 59 | ++ |
| 60 | ++ name = (char *)cc + noff; |
| 61 | ++ switch (nlen) { |
| 62 | ++ case 4: |
| 63 | ++ if (!strncmp(name, SMB2_CREATE_REQUEST_LEASE, 4)) { |
| 64 | ++ *oplock = server->ops->parse_lease_buf(cc, epoch, |
| 65 | ++ lease_key); |
| 66 | ++ } else if (buf && |
| 67 | ++ !strncmp(name, SMB2_CREATE_QUERY_ON_DISK_ID, 4)) { |
| 68 | ++ parse_query_id_ctxt(cc, buf); |
| 69 | ++ } |
| 70 | ++ break; |
| 71 | ++ case 16: |
| 72 | ++ if (posix && !memcmp(name, smb3_create_tag_posix, 16)) |
| 73 | +++>>>>>>> 76025cc2285d (smb: client: fix parsing of SMB3.1.1 POSIX create context) |
| 74 | + parse_posix_ctxt(cc, buf, posix); |
| 75 | + - break; |
| 76 | + - default: |
| 77 | + - cifs_dbg(FYI, "%s: unhandled context (nlen=%zu dlen=%zu)\n", |
| 78 | + - __func__, nlen, dlen); |
| 79 | + - if (IS_ENABLED(CONFIG_CIFS_DEBUG2)) |
| 80 | + - cifs_dump_mem("context data: ", cc, dlen); |
| 81 | + - break; |
| 82 | + } |
| 83 | + - |
| 84 | + - off = le32_to_cpu(cc->Next); |
| 85 | + - if (!off) |
| 86 | + + /* else { |
| 87 | + + cifs_dbg(FYI, "Context not matched with len %d\n", |
| 88 | + + le16_to_cpu(cc->NameLength)); |
| 89 | + + cifs_dump_mem("Cctxt name: ", name, 4); |
| 90 | + + } */ |
| 91 | + + |
| 92 | + + next = le32_to_cpu(cc->Next); |
| 93 | + + if (!next) |
| 94 | + break; |
| 95 | + - if (check_sub_overflow(rem, off, &rem)) |
| 96 | + - return -EINVAL; |
| 97 | + - cc = (struct create_context *)((u8 *)cc + off); |
| 98 | + + remaining -= next; |
| 99 | + + cc = (struct create_context *)((char *)cc + next); |
| 100 | + } |
| 101 | + |
| 102 | + if (rsp->OplockLevel != SMB2_OPLOCK_LEVEL_LEASE) |
| 103 | +* Unmerged path fs/smb/client/smb2pdu.c |
0 commit comments