Commit 823d3249 authored by Namjae Jeon's avatar Namjae Jeon Committed by Zhong Jinghua
Browse files

ksmbd: add support for smb2 max credit parameter

mainline inclusion
from mainline-5.17-rc1
commit 004443b3
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I60T7G
CVE: NA

Reference: https://git.kernel.org/torvalds/linux/c/004443b3f6d7



-------------------------------

Add smb2 max credits parameter to adjust maximum credits value to limit
number of outstanding requests.

Signed-off-by: default avatarNamjae Jeon <linkinjeon@kernel.org>
Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
Signed-off-by: default avatarJason Yan <yanaijie@huawei.com>
Signed-off-by: default avatarZhong Jinghua <zhongjinghua@huawei.com>
parent 3656c49c
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -55,7 +55,6 @@ struct ksmbd_conn {
	/* References which are made for this Server object*/
	atomic_t			r_count;
	unsigned short			total_credits;
	unsigned short			max_credits;
	spinlock_t			credits_lock;
	wait_queue_head_t		req_running_q;
	wait_queue_head_t		r_count_q;
+1 −0
Original line number Diff line number Diff line
@@ -103,6 +103,7 @@ struct ksmbd_startup_request {
					 * we set the SPARSE_FILES bit (0x40).
					 */
	__u32	sub_auth[3];		/* Subauth value for Security ID */
	__u32	smb2_max_credits;	/* MAX credits */
	__u32	ifc_list_sz;		/* interfaces list size */
	__s8	____payload[];
};
+1 −1
Original line number Diff line number Diff line
@@ -322,7 +322,7 @@ static int smb2_validate_credit_charge(struct ksmbd_conn *conn,
		ksmbd_debug(SMB, "Insufficient credit charge, given: %d, needed: %d\n",
			    credit_charge, calc_credit_num);
		return 1;
	} else if (credit_charge > conn->max_credits) {
	} else if (credit_charge > conn->vals->max_credits) {
		ksmbd_debug(SMB, "Too large credit charge: %d\n", credit_charge);
		return 1;
	}
+12 −4
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ static struct smb_version_values smb21_server_values = {
	.max_read_size = SMB21_DEFAULT_IOSIZE,
	.max_write_size = SMB21_DEFAULT_IOSIZE,
	.max_trans_size = SMB21_DEFAULT_IOSIZE,
	.max_credits = SMB2_MAX_CREDITS,
	.large_lock_type = 0,
	.exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
	.shared_lock_type = SMB2_LOCKFLAG_SHARED,
@@ -45,6 +46,7 @@ static struct smb_version_values smb30_server_values = {
	.max_read_size = SMB3_DEFAULT_IOSIZE,
	.max_write_size = SMB3_DEFAULT_IOSIZE,
	.max_trans_size = SMB3_DEFAULT_TRANS_SIZE,
	.max_credits = SMB2_MAX_CREDITS,
	.large_lock_type = 0,
	.exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
	.shared_lock_type = SMB2_LOCKFLAG_SHARED,
@@ -71,6 +73,7 @@ static struct smb_version_values smb302_server_values = {
	.max_read_size = SMB3_DEFAULT_IOSIZE,
	.max_write_size = SMB3_DEFAULT_IOSIZE,
	.max_trans_size = SMB3_DEFAULT_TRANS_SIZE,
	.max_credits = SMB2_MAX_CREDITS,
	.large_lock_type = 0,
	.exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
	.shared_lock_type = SMB2_LOCKFLAG_SHARED,
@@ -97,6 +100,7 @@ static struct smb_version_values smb311_server_values = {
	.max_read_size = SMB3_DEFAULT_IOSIZE,
	.max_write_size = SMB3_DEFAULT_IOSIZE,
	.max_trans_size = SMB3_DEFAULT_TRANS_SIZE,
	.max_credits = SMB2_MAX_CREDITS,
	.large_lock_type = 0,
	.exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE,
	.shared_lock_type = SMB2_LOCKFLAG_SHARED,
@@ -198,7 +202,6 @@ void init_smb2_1_server(struct ksmbd_conn *conn)
	conn->ops = &smb2_0_server_ops;
	conn->cmds = smb2_0_server_cmds;
	conn->max_cmds = ARRAY_SIZE(smb2_0_server_cmds);
	conn->max_credits = SMB2_MAX_CREDITS;
	conn->signing_algorithm = SIGNING_ALG_HMAC_SHA256;

	if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_LEASES)
@@ -216,7 +219,6 @@ void init_smb3_0_server(struct ksmbd_conn *conn)
	conn->ops = &smb3_0_server_ops;
	conn->cmds = smb2_0_server_cmds;
	conn->max_cmds = ARRAY_SIZE(smb2_0_server_cmds);
	conn->max_credits = SMB2_MAX_CREDITS;
	conn->signing_algorithm = SIGNING_ALG_AES_CMAC;

	if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_LEASES)
@@ -241,7 +243,6 @@ void init_smb3_02_server(struct ksmbd_conn *conn)
	conn->ops = &smb3_0_server_ops;
	conn->cmds = smb2_0_server_cmds;
	conn->max_cmds = ARRAY_SIZE(smb2_0_server_cmds);
	conn->max_credits = SMB2_MAX_CREDITS;
	conn->signing_algorithm = SIGNING_ALG_AES_CMAC;

	if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_LEASES)
@@ -266,7 +267,6 @@ int init_smb3_11_server(struct ksmbd_conn *conn)
	conn->ops = &smb3_11_server_ops;
	conn->cmds = smb2_0_server_cmds;
	conn->max_cmds = ARRAY_SIZE(smb2_0_server_cmds);
	conn->max_credits = SMB2_MAX_CREDITS;
	conn->signing_algorithm = SIGNING_ALG_AES_CMAC;

	if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_LEASES)
@@ -305,3 +305,11 @@ void init_smb2_max_trans_size(unsigned int sz)
	smb302_server_values.max_trans_size = sz;
	smb311_server_values.max_trans_size = sz;
}

void init_smb2_max_credits(unsigned int sz)
{
	smb21_server_values.max_credits = sz;
	smb30_server_values.max_credits = sz;
	smb302_server_values.max_credits = sz;
	smb311_server_values.max_credits = sz;
}
+4 −4
Original line number Diff line number Diff line
@@ -309,7 +309,7 @@ int smb2_set_rsp_credits(struct ksmbd_work *work)

	hdr->CreditCharge = req_hdr->CreditCharge;

	if (conn->total_credits > conn->max_credits) {
	if (conn->total_credits > conn->vals->max_credits) {
		hdr->CreditRequest = 0;
		pr_err("Total credits overflow: %d\n", conn->total_credits);
		return -EINVAL;
@@ -330,12 +330,12 @@ int smb2_set_rsp_credits(struct ksmbd_work *work)
	if (hdr->Command == SMB2_NEGOTIATE)
		aux_max = 0;
	else
		aux_max = conn->max_credits - credit_charge;
		aux_max = conn->vals->max_credits - credit_charge;
	aux_credits = min_t(unsigned short, aux_credits, aux_max);
	credits_granted = credit_charge + aux_credits;

	if (conn->max_credits - conn->total_credits < credits_granted)
		credits_granted = conn->max_credits -
	if (conn->vals->max_credits - conn->total_credits < credits_granted)
		credits_granted = conn->vals->max_credits -
			conn->total_credits;

	conn->total_credits += credits_granted;
Loading