Skip to content

Commit df070af

Browse files
Ronnie Sahlbergsmfrench
authored andcommitted
cifs: fix parsing of symbolic link error response
RHBZ: 1672539 In smb2_query_symlink(), if we are parsing the error buffer but it is not something we recognize as a symlink we should return -EINVAL and not -ENOENT. I.e. the entry does exist, it is just not something we recognize. Additionally, add check to verify that that the errortag and the reparsetag all make sense. Signed-off-by: Ronnie Sahlberg <[email protected]> Acked-by: Paulo Alcantara <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent f5f111c commit df070af

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

fs/cifs/smb2ops.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2605,26 +2605,32 @@ smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
26052605
err_buf = err_iov.iov_base;
26062606
if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) ||
26072607
err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE) {
2608-
rc = -ENOENT;
2608+
rc = -EINVAL;
2609+
goto querty_exit;
2610+
}
2611+
2612+
symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
2613+
if (le32_to_cpu(symlink->SymLinkErrorTag) != SYMLINK_ERROR_TAG ||
2614+
le32_to_cpu(symlink->ReparseTag) != IO_REPARSE_TAG_SYMLINK) {
2615+
rc = -EINVAL;
26092616
goto querty_exit;
26102617
}
26112618

26122619
/* open must fail on symlink - reset rc */
26132620
rc = 0;
2614-
symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
26152621
sub_len = le16_to_cpu(symlink->SubstituteNameLength);
26162622
sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
26172623
print_len = le16_to_cpu(symlink->PrintNameLength);
26182624
print_offset = le16_to_cpu(symlink->PrintNameOffset);
26192625

26202626
if (err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE + sub_offset + sub_len) {
2621-
rc = -ENOENT;
2627+
rc = -EINVAL;
26222628
goto querty_exit;
26232629
}
26242630

26252631
if (err_iov.iov_len <
26262632
SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) {
2627-
rc = -ENOENT;
2633+
rc = -EINVAL;
26282634
goto querty_exit;
26292635
}
26302636

fs/cifs/smb2pdu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ struct smb2_err_rsp {
166166
__u8 ErrorData[1]; /* variable length */
167167
} __packed;
168168

169+
#define SYMLINK_ERROR_TAG 0x4c4d5953
170+
169171
struct smb2_symlink_err_rsp {
170172
__le32 SymLinkLength;
171173
__le32 SymLinkErrorTag;

0 commit comments

Comments
 (0)