Skip to content

Commit e7a10ed

Browse files
authored
Merge pull request #66 from namjaejeon/cifsd-for-next
ksmbd-fixes
2 parents 456af43 + a9a27d4 commit e7a10ed

File tree

10 files changed

+128
-85
lines changed

10 files changed

+128
-85
lines changed

Documentation/filesystems/cifs/ksmbd.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ SMB3 encryption(CCM, GCM) Supported. (CCM and GCM128 supported, GCM256 in
8484
progress)
8585
SMB direct(RDMA) Partially Supported. SMB3 Multi-channel is
8686
required to connect to Windows client.
87-
SMB3 Multi-channel In Progress.
87+
SMB3 Multi-channel Partially Supported. Planned to implement
88+
replay/retry mechanisms for future.
8889
SMB3.1.1 POSIX extension Supported.
8990
ACLs Partially Supported. only DACLs available, SACLs
9091
(auditing) is planned for the future. For

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9945,6 +9945,7 @@ M: Steve French <[email protected]>
99459945
M: Hyunchul Lee <[email protected]>
99469946
99479947
S: Maintained
9948+
T: git git://git.samba.org/ksmbd.git
99489949
F: fs/ksmbd/
99499950

99509951
KERNEL UNIT TESTING FRAMEWORK (KUnit)

fs/ksmbd/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ config SMB_SERVER
1919
select CRYPTO_GCM
2020
select ASN1
2121
select OID_REGISTRY
22-
select FS_POSIX_ACL
2322
default n
2423
help
2524
Choose Y here if you want to allow SMB3 compliant clients

fs/ksmbd/smb2pdu.c

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,18 @@ static void __wbuf(struct ksmbd_work *work, void **req, void **rsp)
5858
*
5959
* Return: 1 if valid session id, otherwise 0
6060
*/
61-
static inline int check_session_id(struct ksmbd_conn *conn, u64 id)
61+
static inline bool check_session_id(struct ksmbd_conn *conn, u64 id)
6262
{
6363
struct ksmbd_session *sess;
6464

6565
if (id == 0 || id == -1)
66-
return 0;
66+
return false;
6767

6868
sess = ksmbd_session_lookup_all(conn, id);
6969
if (sess)
70-
return 1;
70+
return true;
7171
pr_err("Invalid user session id: %llu\n", id);
72-
return 0;
72+
return false;
7373
}
7474

7575
struct channel *lookup_chann_list(struct ksmbd_session *sess, struct ksmbd_conn *conn)
@@ -85,10 +85,11 @@ struct channel *lookup_chann_list(struct ksmbd_session *sess, struct ksmbd_conn
8585
}
8686

8787
/**
88-
* smb2_get_ksmbd_tcon() - get tree connection information for a tree id
88+
* smb2_get_ksmbd_tcon() - get tree connection information using a tree id.
8989
* @work: smb work
9090
*
91-
* Return: matching tree connection on success, otherwise error
91+
* Return: 0 if there is a tree connection matched or these are
92+
* skipable commands, otherwise error
9293
*/
9394
int smb2_get_ksmbd_tcon(struct ksmbd_work *work)
9495
{
@@ -105,14 +106,14 @@ int smb2_get_ksmbd_tcon(struct ksmbd_work *work)
105106

106107
if (xa_empty(&work->sess->tree_conns)) {
107108
ksmbd_debug(SMB, "NO tree connected\n");
108-
return -1;
109+
return -ENOENT;
109110
}
110111

111112
tree_id = le32_to_cpu(req_hdr->Id.SyncId.TreeId);
112113
work->tcon = ksmbd_tree_conn_lookup(work->sess, tree_id);
113114
if (!work->tcon) {
114115
pr_err("Invalid tid %d\n", tree_id);
115-
return -1;
116+
return -EINVAL;
116117
}
117118

118119
return 1;
@@ -145,45 +146,45 @@ void smb2_set_err_rsp(struct ksmbd_work *work)
145146
* is_smb2_neg_cmd() - is it smb2 negotiation command
146147
* @work: smb work containing smb header
147148
*
148-
* Return: 1 if smb2 negotiation command, otherwise 0
149+
* Return: true if smb2 negotiation command, otherwise false
149150
*/
150-
int is_smb2_neg_cmd(struct ksmbd_work *work)
151+
bool is_smb2_neg_cmd(struct ksmbd_work *work)
151152
{
152153
struct smb2_hdr *hdr = work->request_buf;
153154

154155
/* is it SMB2 header ? */
155156
if (hdr->ProtocolId != SMB2_PROTO_NUMBER)
156-
return 0;
157+
return false;
157158

158159
/* make sure it is request not response message */
159160
if (hdr->Flags & SMB2_FLAGS_SERVER_TO_REDIR)
160-
return 0;
161+
return false;
161162

162163
if (hdr->Command != SMB2_NEGOTIATE)
163-
return 0;
164+
return false;
164165

165-
return 1;
166+
return true;
166167
}
167168

168169
/**
169170
* is_smb2_rsp() - is it smb2 response
170171
* @work: smb work containing smb response buffer
171172
*
172-
* Return: 1 if smb2 response, otherwise 0
173+
* Return: true if smb2 response, otherwise false
173174
*/
174-
int is_smb2_rsp(struct ksmbd_work *work)
175+
bool is_smb2_rsp(struct ksmbd_work *work)
175176
{
176177
struct smb2_hdr *hdr = work->response_buf;
177178

178179
/* is it SMB2 header ? */
179180
if (hdr->ProtocolId != SMB2_PROTO_NUMBER)
180-
return 0;
181+
return false;
181182

182183
/* make sure it is response not request message */
183184
if (!(hdr->Flags & SMB2_FLAGS_SERVER_TO_REDIR))
184-
return 0;
185+
return false;
185186

186-
return 1;
187+
return true;
187188
}
188189

189190
/**
@@ -2385,11 +2386,14 @@ static void ksmbd_acls_fattr(struct smb_fattr *fattr, struct inode *inode)
23852386
fattr->cf_uid = inode->i_uid;
23862387
fattr->cf_gid = inode->i_gid;
23872388
fattr->cf_mode = inode->i_mode;
2389+
fattr->cf_acls = NULL;
23882390
fattr->cf_dacls = NULL;
23892391

2390-
fattr->cf_acls = get_acl(inode, ACL_TYPE_ACCESS);
2391-
if (S_ISDIR(inode->i_mode))
2392-
fattr->cf_dacls = get_acl(inode, ACL_TYPE_DEFAULT);
2392+
if (IS_ENABLED(CONFIG_FS_POSIX_ACL)) {
2393+
fattr->cf_acls = get_acl(inode, ACL_TYPE_ACCESS);
2394+
if (S_ISDIR(inode->i_mode))
2395+
fattr->cf_dacls = get_acl(inode, ACL_TYPE_DEFAULT);
2396+
}
23932397
}
23942398

23952399
/**
@@ -8291,7 +8295,7 @@ int smb3_encrypt_resp(struct ksmbd_work *work)
82918295
return rc;
82928296
}
82938297

8294-
int smb3_is_transform_hdr(void *buf)
8298+
bool smb3_is_transform_hdr(void *buf)
82958299
{
82968300
struct smb2_transform_hdr *trhdr = buf;
82978301

fs/ksmbd/smb2pdu.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,8 +1638,8 @@ void init_smb2_max_read_size(unsigned int sz);
16381638
void init_smb2_max_write_size(unsigned int sz);
16391639
void init_smb2_max_trans_size(unsigned int sz);
16401640

1641-
int is_smb2_neg_cmd(struct ksmbd_work *work);
1642-
int is_smb2_rsp(struct ksmbd_work *work);
1641+
bool is_smb2_neg_cmd(struct ksmbd_work *work);
1642+
bool is_smb2_rsp(struct ksmbd_work *work);
16431643

16441644
u16 get_smb2_cmd_val(struct ksmbd_work *work);
16451645
void set_smb2_rsp_status(struct ksmbd_work *work, __le32 err);
@@ -1664,7 +1664,7 @@ void smb2_send_interim_resp(struct ksmbd_work *work, __le32 status);
16641664
struct channel *lookup_chann_list(struct ksmbd_session *sess,
16651665
struct ksmbd_conn *conn);
16661666
void smb3_preauth_hash_rsp(struct ksmbd_work *work);
1667-
int smb3_is_transform_hdr(void *buf);
1667+
bool smb3_is_transform_hdr(void *buf);
16681668
int smb3_decrypt_req(struct ksmbd_work *work);
16691669
int smb3_encrypt_resp(struct ksmbd_work *work);
16701670
bool smb3_11_final_sess_setup_resp(struct ksmbd_work *work);

fs/ksmbd/smb_common.c

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct smb_protocol {
3030
__u16 prot_id;
3131
};
3232

33-
static struct smb_protocol smb_protos[] = {
33+
static struct smb_protocol smb1_protos[] = {
3434
{
3535
SMB21_PROT,
3636
"\2SMB 2.1",
@@ -43,6 +43,15 @@ static struct smb_protocol smb_protos[] = {
4343
"SMB2_22",
4444
SMB2X_PROT_ID
4545
},
46+
};
47+
48+
static struct smb_protocol smb2_protos[] = {
49+
{
50+
SMB21_PROT,
51+
"\2SMB 2.1",
52+
"SMB2_10",
53+
SMB21_PROT_ID
54+
},
4655
{
4756
SMB30_PROT,
4857
"\2SMB 3.0",
@@ -90,14 +99,24 @@ inline int ksmbd_max_protocol(void)
9099

91100
int ksmbd_lookup_protocol_idx(char *str)
92101
{
93-
int offt = ARRAY_SIZE(smb_protos) - 1;
102+
int offt = ARRAY_SIZE(smb1_protos) - 1;
94103
int len = strlen(str);
95104

96105
while (offt >= 0) {
97-
if (!strncmp(str, smb_protos[offt].prot, len)) {
106+
if (!strncmp(str, smb1_protos[offt].prot, len)) {
107+
ksmbd_debug(SMB, "selected %s dialect idx = %d\n",
108+
smb1_protos[offt].prot, offt);
109+
return smb1_protos[offt].index;
110+
}
111+
offt--;
112+
}
113+
114+
offt = ARRAY_SIZE(smb2_protos) - 1;
115+
while (offt >= 0) {
116+
if (!strncmp(str, smb2_protos[offt].prot, len)) {
98117
ksmbd_debug(SMB, "selected %s dialect idx = %d\n",
99-
smb_protos[offt].prot, offt);
100-
return smb_protos[offt].index;
118+
smb2_protos[offt].prot, offt);
119+
return smb2_protos[offt].index;
101120
}
102121
offt--;
103122
}
@@ -169,7 +188,7 @@ static int ksmbd_lookup_dialect_by_name(char *cli_dialects, __le16 byte_count)
169188
int i, seq_num, bcount, next;
170189
char *dialect;
171190

172-
for (i = ARRAY_SIZE(smb_protos) - 1; i >= 0; i--) {
191+
for (i = ARRAY_SIZE(smb1_protos) - 1; i >= 0; i--) {
173192
seq_num = 0;
174193
next = 0;
175194
dialect = cli_dialects;
@@ -178,14 +197,14 @@ static int ksmbd_lookup_dialect_by_name(char *cli_dialects, __le16 byte_count)
178197
dialect = next_dialect(dialect, &next);
179198
ksmbd_debug(SMB, "client requested dialect %s\n",
180199
dialect);
181-
if (!strcmp(dialect, smb_protos[i].name)) {
182-
if (supported_protocol(smb_protos[i].index)) {
200+
if (!strcmp(dialect, smb1_protos[i].name)) {
201+
if (supported_protocol(smb1_protos[i].index)) {
183202
ksmbd_debug(SMB,
184203
"selected %s dialect\n",
185-
smb_protos[i].name);
186-
if (smb_protos[i].index == SMB1_PROT)
204+
smb1_protos[i].name);
205+
if (smb1_protos[i].index == SMB1_PROT)
187206
return seq_num;
188-
return smb_protos[i].prot_id;
207+
return smb1_protos[i].prot_id;
189208
}
190209
}
191210
seq_num++;
@@ -201,27 +220,27 @@ int ksmbd_lookup_dialect_by_id(__le16 *cli_dialects, __le16 dialects_count)
201220
int i;
202221
int count;
203222

204-
for (i = ARRAY_SIZE(smb_protos) - 1; i >= 0; i--) {
223+
for (i = ARRAY_SIZE(smb2_protos) - 1; i >= 0; i--) {
205224
count = le16_to_cpu(dialects_count);
206225
while (--count >= 0) {
207226
ksmbd_debug(SMB, "client requested dialect 0x%x\n",
208227
le16_to_cpu(cli_dialects[count]));
209228
if (le16_to_cpu(cli_dialects[count]) !=
210-
smb_protos[i].prot_id)
229+
smb2_protos[i].prot_id)
211230
continue;
212231

213-
if (supported_protocol(smb_protos[i].index)) {
232+
if (supported_protocol(smb2_protos[i].index)) {
214233
ksmbd_debug(SMB, "selected %s dialect\n",
215-
smb_protos[i].name);
216-
return smb_protos[i].prot_id;
234+
smb2_protos[i].name);
235+
return smb2_protos[i].prot_id;
217236
}
218237
}
219238
}
220239

221240
return BAD_PROT_ID;
222241
}
223242

224-
int ksmbd_negotiate_smb_dialect(void *buf)
243+
static int ksmbd_negotiate_smb_dialect(void *buf)
225244
{
226245
__le32 proto;
227246

fs/ksmbd/smb_common.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ struct smb_version_ops {
473473
void (*set_sign_rsp)(struct ksmbd_work *work);
474474
int (*generate_signingkey)(struct ksmbd_session *sess, struct ksmbd_conn *conn);
475475
int (*generate_encryptionkey)(struct ksmbd_session *sess);
476-
int (*is_transform_hdr)(void *buf);
476+
bool (*is_transform_hdr)(void *buf);
477477
int (*decrypt_req)(struct ksmbd_work *work);
478478
int (*encrypt_resp)(struct ksmbd_work *work);
479479
};
@@ -498,7 +498,6 @@ bool ksmbd_smb_request(struct ksmbd_conn *conn);
498498

499499
int ksmbd_lookup_dialect_by_id(__le16 *cli_dialects, __le16 dialects_count);
500500

501-
int ksmbd_negotiate_smb_dialect(void *buf);
502501
int ksmbd_init_smb_server(struct ksmbd_work *work);
503502

504503
bool ksmbd_pdu_size_has_room(unsigned int pdu);

0 commit comments

Comments
 (0)