Skip to content

Commit 3639999

Browse files
namjaejeonSteve French
authored andcommitted
ksmbd: add the check to vaildate if stream protocol length exceeds maximum value
This patch add MAX_STREAM_PROT_LEN macro and check if stream protocol length exceeds maximum value. opencode pdu size check in ksmbd_pdu_size_has_room(). Cc: Tom Talpey <[email protected]> Cc: Ronnie Sahlberg <[email protected]> Cc: Ralph Böhme <[email protected]> Acked-by: Hyunchul Lee <[email protected]> Signed-off-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 9e1ff30 commit 3639999

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

fs/ksmbd/connection.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,12 @@ int ksmbd_conn_handler_loop(void *p)
296296
pdu_size = get_rfc1002_len(hdr_buf);
297297
ksmbd_debug(CONN, "RFC1002 header %u bytes\n", pdu_size);
298298

299-
/* make sure we have enough to get to SMB header end */
300-
if (!ksmbd_pdu_size_has_room(pdu_size)) {
301-
ksmbd_debug(CONN, "SMB request too short (%u bytes)\n",
302-
pdu_size);
299+
/*
300+
* Check if pdu size is valid (min : smb header size,
301+
* max : 0x00FFFFFF).
302+
*/
303+
if (pdu_size < __SMB2_HEADER_STRUCTURE_SIZE ||
304+
pdu_size > MAX_STREAM_PROT_LEN) {
303305
continue;
304306
}
305307

fs/ksmbd/smb_common.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ static const char basechars[43] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_-!@#$%";
2121
#define MAGIC_CHAR '~'
2222
#define PERIOD '.'
2323
#define mangle(V) ((char)(basechars[(V) % MANGLE_BASE]))
24-
#define KSMBD_MIN_SUPPORTED_HEADER_SIZE (sizeof(struct smb2_hdr))
2524

2625
struct smb_protocol {
2726
int index;
@@ -294,11 +293,6 @@ int ksmbd_init_smb_server(struct ksmbd_work *work)
294293
return 0;
295294
}
296295

297-
bool ksmbd_pdu_size_has_room(unsigned int pdu)
298-
{
299-
return (pdu >= KSMBD_MIN_SUPPORTED_HEADER_SIZE - 4);
300-
}
301-
302296
int ksmbd_populate_dot_dotdot_entries(struct ksmbd_work *work, int info_level,
303297
struct ksmbd_file *dir,
304298
struct ksmbd_dir_info *d_info,

fs/ksmbd/smb_common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
#define CIFS_DEFAULT_IOSIZE (64 * 1024)
4949
#define MAX_CIFS_SMALL_BUFFER_SIZE 448 /* big enough for most */
5050

51+
#define MAX_STREAM_PROT_LEN 0x00FFFFFF
52+
5153
/* Responses when opening a file. */
5254
#define F_SUPERSEDED 0
5355
#define F_OPENED 1
@@ -493,8 +495,6 @@ int ksmbd_lookup_dialect_by_id(__le16 *cli_dialects, __le16 dialects_count);
493495

494496
int ksmbd_init_smb_server(struct ksmbd_work *work);
495497

496-
bool ksmbd_pdu_size_has_room(unsigned int pdu);
497-
498498
struct ksmbd_kstat;
499499
int ksmbd_populate_dot_dotdot_entries(struct ksmbd_work *work,
500500
int info_level,

0 commit comments

Comments
 (0)