Skip to content

Commit

Permalink
ksmbd: don't align last entry offset in smb2 query directory
Browse files Browse the repository at this point in the history
[ Upstream commit 04e2609 ]

When checking smb2 query directory packets from other servers,
OutputBufferLength is different with ksmbd. Other servers add an unaligned
next offset to OutputBufferLength for the last entry.

Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
namjaejeon authored and gregkh committed Feb 23, 2022
1 parent 28b5031 commit 6fb73a6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 4 additions & 3 deletions fs/ksmbd/smb2pdu.c
Expand Up @@ -3423,9 +3423,9 @@ static int smb2_populate_readdir_entry(struct ksmbd_conn *conn, int info_level,
goto free_conv_name;
}

struct_sz = readdir_info_level_struct_sz(info_level);
next_entry_offset = ALIGN(struct_sz - 1 + conv_len,
KSMBD_DIR_INFO_ALIGNMENT);
struct_sz = readdir_info_level_struct_sz(info_level) - 1 + conv_len;
next_entry_offset = ALIGN(struct_sz, KSMBD_DIR_INFO_ALIGNMENT);
d_info->last_entry_off_align = next_entry_offset - struct_sz;

if (next_entry_offset > d_info->out_buf_len) {
d_info->out_buf_len = 0;
Expand Down Expand Up @@ -3977,6 +3977,7 @@ int smb2_query_dir(struct ksmbd_work *work)
((struct file_directory_info *)
((char *)rsp->Buffer + d_info.last_entry_offset))
->NextEntryOffset = 0;
d_info.data_count -= d_info.last_entry_off_align;

rsp->StructureSize = cpu_to_le16(9);
rsp->OutputBufferOffset = cpu_to_le16(72);
Expand Down
1 change: 1 addition & 0 deletions fs/ksmbd/vfs.h
Expand Up @@ -47,6 +47,7 @@ struct ksmbd_dir_info {
int last_entry_offset;
bool hide_dot_file;
int flags;
int last_entry_off_align;
};

struct ksmbd_readdir_data {
Expand Down

0 comments on commit 6fb73a6

Please sign in to comment.