Skip to content

Commit 621be84

Browse files
namjaejeonsmfrench
authored andcommitted
ksmbd: throttle session setup failures to avoid dictionary attacks
To avoid dictionary attacks (repeated session setups rapidly sent) to connect to server, ksmbd make a delay of a 5 seconds on session setup failure to make it harder to send enough random connection requests to break into a server if a user insert the wrong password 10 times in a row. Signed-off-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 34061d6 commit 621be84

File tree

6 files changed

+31
-6
lines changed

6 files changed

+31
-6
lines changed

fs/ksmbd/ksmbd_netlink.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ struct ksmbd_tree_disconnect_request {
211211
*/
212212
struct ksmbd_logout_request {
213213
__s8 account[KSMBD_REQ_MAX_ACCOUNT_NAME_SZ]; /* user account name */
214+
__u32 account_flags;
214215
};
215216

216217
/*
@@ -317,6 +318,7 @@ enum KSMBD_TREE_CONN_STATUS {
317318
#define KSMBD_USER_FLAG_BAD_UID BIT(2)
318319
#define KSMBD_USER_FLAG_BAD_USER BIT(3)
319320
#define KSMBD_USER_FLAG_GUEST_ACCOUNT BIT(4)
321+
#define KSMBD_USER_FLAG_DELAY_SESSION BIT(5)
320322

321323
/*
322324
* Share config flags.

fs/ksmbd/mgmt/user_config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct ksmbd_user *ksmbd_alloc_user(struct ksmbd_login_response *resp)
5555

5656
void ksmbd_free_user(struct ksmbd_user *user)
5757
{
58-
ksmbd_ipc_logout_request(user->name);
58+
ksmbd_ipc_logout_request(user->name, user->flags);
5959
kfree(user->name);
6060
kfree(user->passkey);
6161
kfree(user);

fs/ksmbd/mgmt/user_config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ struct ksmbd_user {
1818

1919
size_t passkey_sz;
2020
char *passkey;
21+
unsigned int failed_login_count;
2122
};
2223

2324
static inline bool user_guest(struct ksmbd_user *user)

fs/ksmbd/smb2pdu.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,9 +1779,30 @@ int smb2_sess_setup(struct ksmbd_work *work)
17791779
conn->mechToken = NULL;
17801780
}
17811781

1782-
if (rc < 0 && sess) {
1783-
ksmbd_session_destroy(sess);
1784-
work->sess = NULL;
1782+
if (rc < 0) {
1783+
/*
1784+
* SecurityBufferOffset should be set to zero
1785+
* in session setup error response.
1786+
*/
1787+
rsp->SecurityBufferOffset = 0;
1788+
1789+
if (sess) {
1790+
bool try_delay = false;
1791+
1792+
/*
1793+
* To avoid dictionary attacks (repeated session setups rapidly sent) to
1794+
* connect to server, ksmbd make a delay of a 5 seconds on session setup
1795+
* failure to make it harder to send enough random connection requests
1796+
* to break into a server.
1797+
*/
1798+
if (sess->user && sess->user->flags & KSMBD_USER_FLAG_DELAY_SESSION)
1799+
try_delay = true;
1800+
1801+
ksmbd_session_destroy(sess);
1802+
work->sess = NULL;
1803+
if (try_delay)
1804+
ssleep(5);
1805+
}
17851806
}
17861807

17871808
return rc;

fs/ksmbd/transport_ipc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ int ksmbd_ipc_tree_disconnect_request(unsigned long long session_id,
601601
return ret;
602602
}
603603

604-
int ksmbd_ipc_logout_request(const char *account)
604+
int ksmbd_ipc_logout_request(const char *account, int flags)
605605
{
606606
struct ksmbd_ipc_msg *msg;
607607
struct ksmbd_logout_request *req;
@@ -616,6 +616,7 @@ int ksmbd_ipc_logout_request(const char *account)
616616

617617
msg->type = KSMBD_EVENT_LOGOUT_REQUEST;
618618
req = (struct ksmbd_logout_request *)msg->payload;
619+
req->account_flags = flags;
619620
strscpy(req->account, account, KSMBD_REQ_MAX_ACCOUNT_NAME_SZ);
620621

621622
ret = ipc_msg_send(msg);

fs/ksmbd/transport_ipc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ ksmbd_ipc_tree_connect_request(struct ksmbd_session *sess,
2525
struct sockaddr *peer_addr);
2626
int ksmbd_ipc_tree_disconnect_request(unsigned long long session_id,
2727
unsigned long long connect_id);
28-
int ksmbd_ipc_logout_request(const char *account);
28+
int ksmbd_ipc_logout_request(const char *account, int flags);
2929
struct ksmbd_share_config_response *
3030
ksmbd_ipc_share_config_request(const char *name);
3131
struct ksmbd_spnego_authen_response *

0 commit comments

Comments
 (0)