Skip to content

Commit d2fec01

Browse files
committed
Merge tag '6.16-rc-ksmbd-server-fixes' of git://git.samba.org/ksmbd
Pull smb server updates from Steve French: "Four smb3 server fixes: - Fix for special character handling when mounting with "posix" - Fix for mounts from Mac for fs that don't provide unique inode numbers - Two cleanup patches (e.g. for crypto calls)" * tag '6.16-rc-ksmbd-server-fixes' of git://git.samba.org/ksmbd: ksmbd: allow a filename to contain special characters on SMB3.1.1 posix extension ksmbd: provide zero as a unique ID to the Mac client ksmbd: remove unnecessary softdep on crc32 ksmbd: use SHA-256 library API instead of crypto_shash API
2 parents ff0905b + dc3e0f1 commit d2fec01

File tree

10 files changed

+53
-93
lines changed

10 files changed

+53
-93
lines changed

fs/smb/server/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ config SMB_SERVER
1111
select CRYPTO_HMAC
1212
select CRYPTO_ECB
1313
select CRYPTO_LIB_DES
14+
select CRYPTO_LIB_SHA256
1415
select CRYPTO_SHA256
1516
select CRYPTO_CMAC
1617
select CRYPTO_SHA512

fs/smb/server/auth.c

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -979,40 +979,6 @@ int ksmbd_gen_preauth_integrity_hash(struct ksmbd_conn *conn, char *buf,
979979
return rc;
980980
}
981981

982-
int ksmbd_gen_sd_hash(struct ksmbd_conn *conn, char *sd_buf, int len,
983-
__u8 *pi_hash)
984-
{
985-
int rc;
986-
struct ksmbd_crypto_ctx *ctx = NULL;
987-
988-
ctx = ksmbd_crypto_ctx_find_sha256();
989-
if (!ctx) {
990-
ksmbd_debug(AUTH, "could not alloc sha256\n");
991-
return -ENOMEM;
992-
}
993-
994-
rc = crypto_shash_init(CRYPTO_SHA256(ctx));
995-
if (rc) {
996-
ksmbd_debug(AUTH, "could not init shashn");
997-
goto out;
998-
}
999-
1000-
rc = crypto_shash_update(CRYPTO_SHA256(ctx), sd_buf, len);
1001-
if (rc) {
1002-
ksmbd_debug(AUTH, "could not update with n\n");
1003-
goto out;
1004-
}
1005-
1006-
rc = crypto_shash_final(CRYPTO_SHA256(ctx), pi_hash);
1007-
if (rc) {
1008-
ksmbd_debug(AUTH, "Could not generate hash err : %d\n", rc);
1009-
goto out;
1010-
}
1011-
out:
1012-
ksmbd_release_crypto_ctx(ctx);
1013-
return rc;
1014-
}
1015-
1016982
static int ksmbd_get_encryption_key(struct ksmbd_work *work, __u64 ses_id,
1017983
int enc, u8 *key)
1018984
{

fs/smb/server/auth.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,4 @@ int ksmbd_gen_smb311_encryptionkey(struct ksmbd_conn *conn,
6666
struct ksmbd_session *sess);
6767
int ksmbd_gen_preauth_integrity_hash(struct ksmbd_conn *conn, char *buf,
6868
__u8 *pi_hash);
69-
int ksmbd_gen_sd_hash(struct ksmbd_conn *conn, char *sd_buf, int len,
70-
__u8 *pi_hash);
7169
#endif

fs/smb/server/connection.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ struct ksmbd_conn {
108108
__le16 signing_algorithm;
109109
bool binding;
110110
atomic_t refcnt;
111+
bool is_aapl;
111112
};
112113

113114
struct ksmbd_conn_ops {

fs/smb/server/crypto_ctx.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ static struct shash_desc *alloc_shash_desc(int id)
7575
case CRYPTO_SHASH_CMACAES:
7676
tfm = crypto_alloc_shash("cmac(aes)", 0, 0);
7777
break;
78-
case CRYPTO_SHASH_SHA256:
79-
tfm = crypto_alloc_shash("sha256", 0, 0);
80-
break;
8178
case CRYPTO_SHASH_SHA512:
8279
tfm = crypto_alloc_shash("sha512", 0, 0);
8380
break;
@@ -198,11 +195,6 @@ struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_cmacaes(void)
198195
return ____crypto_shash_ctx_find(CRYPTO_SHASH_CMACAES);
199196
}
200197

201-
struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_sha256(void)
202-
{
203-
return ____crypto_shash_ctx_find(CRYPTO_SHASH_SHA256);
204-
}
205-
206198
struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_sha512(void)
207199
{
208200
return ____crypto_shash_ctx_find(CRYPTO_SHASH_SHA512);

fs/smb/server/crypto_ctx.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ enum {
1313
CRYPTO_SHASH_HMACMD5 = 0,
1414
CRYPTO_SHASH_HMACSHA256,
1515
CRYPTO_SHASH_CMACAES,
16-
CRYPTO_SHASH_SHA256,
1716
CRYPTO_SHASH_SHA512,
1817
CRYPTO_SHASH_MAX,
1918
};
@@ -39,14 +38,12 @@ struct ksmbd_crypto_ctx {
3938
#define CRYPTO_HMACMD5(c) ((c)->desc[CRYPTO_SHASH_HMACMD5])
4039
#define CRYPTO_HMACSHA256(c) ((c)->desc[CRYPTO_SHASH_HMACSHA256])
4140
#define CRYPTO_CMACAES(c) ((c)->desc[CRYPTO_SHASH_CMACAES])
42-
#define CRYPTO_SHA256(c) ((c)->desc[CRYPTO_SHASH_SHA256])
4341
#define CRYPTO_SHA512(c) ((c)->desc[CRYPTO_SHASH_SHA512])
4442

4543
#define CRYPTO_HMACMD5_TFM(c) ((c)->desc[CRYPTO_SHASH_HMACMD5]->tfm)
4644
#define CRYPTO_HMACSHA256_TFM(c)\
4745
((c)->desc[CRYPTO_SHASH_HMACSHA256]->tfm)
4846
#define CRYPTO_CMACAES_TFM(c) ((c)->desc[CRYPTO_SHASH_CMACAES]->tfm)
49-
#define CRYPTO_SHA256_TFM(c) ((c)->desc[CRYPTO_SHASH_SHA256]->tfm)
5047
#define CRYPTO_SHA512_TFM(c) ((c)->desc[CRYPTO_SHASH_SHA512]->tfm)
5148

5249
#define CRYPTO_GCM(c) ((c)->ccmaes[CRYPTO_AEAD_AES_GCM])
@@ -57,7 +54,6 @@ struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_hmacmd5(void);
5754
struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_hmacsha256(void);
5855
struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_cmacaes(void);
5956
struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_sha512(void);
60-
struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_sha256(void);
6157
struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_gcm(void);
6258
struct ksmbd_crypto_ctx *ksmbd_crypto_ctx_find_ccm(void);
6359
void ksmbd_crypto_destroy(void);

fs/smb/server/server.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,5 @@ MODULE_SOFTDEP("pre: sha512");
631631
MODULE_SOFTDEP("pre: aead2");
632632
MODULE_SOFTDEP("pre: ccm");
633633
MODULE_SOFTDEP("pre: gcm");
634-
MODULE_SOFTDEP("pre: crc32");
635634
module_init(ksmbd_server_init)
636635
module_exit(ksmbd_server_exit)

fs/smb/server/smb2pdu.c

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2874,7 +2874,7 @@ int smb2_open(struct ksmbd_work *work)
28742874
int req_op_level = 0, open_flags = 0, may_flags = 0, file_info = 0;
28752875
int rc = 0;
28762876
int contxt_cnt = 0, query_disk_id = 0;
2877-
int maximal_access_ctxt = 0, posix_ctxt = 0;
2877+
bool maximal_access_ctxt = false, posix_ctxt = false;
28782878
int s_type = 0;
28792879
int next_off = 0;
28802880
char *name = NULL;
@@ -2903,6 +2903,27 @@ int smb2_open(struct ksmbd_work *work)
29032903
return create_smb2_pipe(work);
29042904
}
29052905

2906+
if (req->CreateContextsOffset && tcon->posix_extensions) {
2907+
context = smb2_find_context_vals(req, SMB2_CREATE_TAG_POSIX, 16);
2908+
if (IS_ERR(context)) {
2909+
rc = PTR_ERR(context);
2910+
goto err_out2;
2911+
} else if (context) {
2912+
struct create_posix *posix = (struct create_posix *)context;
2913+
2914+
if (le16_to_cpu(context->DataOffset) +
2915+
le32_to_cpu(context->DataLength) <
2916+
sizeof(struct create_posix) - 4) {
2917+
rc = -EINVAL;
2918+
goto err_out2;
2919+
}
2920+
ksmbd_debug(SMB, "get posix context\n");
2921+
2922+
posix_mode = le32_to_cpu(posix->Mode);
2923+
posix_ctxt = true;
2924+
}
2925+
}
2926+
29062927
if (req->NameLength) {
29072928
name = smb2_get_name((char *)req + le16_to_cpu(req->NameOffset),
29082929
le16_to_cpu(req->NameLength),
@@ -2925,9 +2946,11 @@ int smb2_open(struct ksmbd_work *work)
29252946
goto err_out2;
29262947
}
29272948

2928-
rc = ksmbd_validate_filename(name);
2929-
if (rc < 0)
2930-
goto err_out2;
2949+
if (posix_ctxt == false) {
2950+
rc = ksmbd_validate_filename(name);
2951+
if (rc < 0)
2952+
goto err_out2;
2953+
}
29312954

29322955
if (ksmbd_share_veto_filename(share, name)) {
29332956
rc = -ENOENT;
@@ -3085,28 +3108,6 @@ int smb2_open(struct ksmbd_work *work)
30853108
rc = -EBADF;
30863109
goto err_out2;
30873110
}
3088-
3089-
if (tcon->posix_extensions) {
3090-
context = smb2_find_context_vals(req,
3091-
SMB2_CREATE_TAG_POSIX, 16);
3092-
if (IS_ERR(context)) {
3093-
rc = PTR_ERR(context);
3094-
goto err_out2;
3095-
} else if (context) {
3096-
struct create_posix *posix =
3097-
(struct create_posix *)context;
3098-
if (le16_to_cpu(context->DataOffset) +
3099-
le32_to_cpu(context->DataLength) <
3100-
sizeof(struct create_posix) - 4) {
3101-
rc = -EINVAL;
3102-
goto err_out2;
3103-
}
3104-
ksmbd_debug(SMB, "get posix context\n");
3105-
3106-
posix_mode = le32_to_cpu(posix->Mode);
3107-
posix_ctxt = 1;
3108-
}
3109-
}
31103111
}
31113112

31123113
if (ksmbd_override_fsids(work)) {
@@ -3539,6 +3540,15 @@ int smb2_open(struct ksmbd_work *work)
35393540
ksmbd_debug(SMB, "get query on disk id context\n");
35403541
query_disk_id = 1;
35413542
}
3543+
3544+
if (conn->is_aapl == false) {
3545+
context = smb2_find_context_vals(req, SMB2_CREATE_AAPL, 4);
3546+
if (IS_ERR(context)) {
3547+
rc = PTR_ERR(context);
3548+
goto err_out1;
3549+
} else if (context)
3550+
conn->is_aapl = true;
3551+
}
35423552
}
35433553

35443554
rc = ksmbd_vfs_getattr(&path, &stat);
@@ -3978,7 +3988,10 @@ static int smb2_populate_readdir_entry(struct ksmbd_conn *conn, int info_level,
39783988
if (dinfo->EaSize)
39793989
dinfo->ExtFileAttributes = FILE_ATTRIBUTE_REPARSE_POINT_LE;
39803990
dinfo->Reserved = 0;
3981-
dinfo->UniqueId = cpu_to_le64(ksmbd_kstat->kstat->ino);
3991+
if (conn->is_aapl)
3992+
dinfo->UniqueId = 0;
3993+
else
3994+
dinfo->UniqueId = cpu_to_le64(ksmbd_kstat->kstat->ino);
39823995
if (d_info->hide_dot_file && d_info->name[0] == '.')
39833996
dinfo->ExtFileAttributes |= FILE_ATTRIBUTE_HIDDEN_LE;
39843997
memcpy(dinfo->FileName, conv_name, conv_len);
@@ -3995,7 +4008,10 @@ static int smb2_populate_readdir_entry(struct ksmbd_conn *conn, int info_level,
39954008
smb2_get_reparse_tag_special_file(ksmbd_kstat->kstat->mode);
39964009
if (fibdinfo->EaSize)
39974010
fibdinfo->ExtFileAttributes = FILE_ATTRIBUTE_REPARSE_POINT_LE;
3998-
fibdinfo->UniqueId = cpu_to_le64(ksmbd_kstat->kstat->ino);
4011+
if (conn->is_aapl)
4012+
fibdinfo->UniqueId = 0;
4013+
else
4014+
fibdinfo->UniqueId = cpu_to_le64(ksmbd_kstat->kstat->ino);
39994015
fibdinfo->ShortNameLength = 0;
40004016
fibdinfo->Reserved = 0;
40014017
fibdinfo->Reserved2 = cpu_to_le16(0);

fs/smb/server/smb2pdu.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ struct preauth_integrity_info {
6363

6464
#define SMB2_SESSION_TIMEOUT (10 * HZ)
6565

66+
/* Apple Defined Contexts */
67+
#define SMB2_CREATE_AAPL "AAPL"
68+
6669
struct create_durable_req_v2 {
6770
struct create_context_hdr ccontext;
6871
__u8 Name[8];

fs/smb/server/vfs.c

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Copyright (C) 2018 Samsung Electronics Co., Ltd.
55
*/
66

7+
#include <crypto/sha2.h>
78
#include <linux/kernel.h>
89
#include <linux/fs.h>
910
#include <linux/filelock.h>
@@ -1476,11 +1477,7 @@ int ksmbd_vfs_set_sd_xattr(struct ksmbd_conn *conn,
14761477
acl.sd_buf = (char *)pntsd;
14771478
acl.sd_size = len;
14781479

1479-
rc = ksmbd_gen_sd_hash(conn, acl.sd_buf, acl.sd_size, acl.hash);
1480-
if (rc) {
1481-
pr_err("failed to generate hash for ndr acl\n");
1482-
return rc;
1483-
}
1480+
sha256(acl.sd_buf, acl.sd_size, acl.hash);
14841481

14851482
smb_acl = ksmbd_vfs_make_xattr_posix_acl(idmap, inode,
14861483
ACL_TYPE_ACCESS);
@@ -1495,12 +1492,7 @@ int ksmbd_vfs_set_sd_xattr(struct ksmbd_conn *conn,
14951492
goto out;
14961493
}
14971494

1498-
rc = ksmbd_gen_sd_hash(conn, acl_ndr.data, acl_ndr.offset,
1499-
acl.posix_acl_hash);
1500-
if (rc) {
1501-
pr_err("failed to generate hash for ndr acl\n");
1502-
goto out;
1503-
}
1495+
sha256(acl_ndr.data, acl_ndr.offset, acl.posix_acl_hash);
15041496

15051497
rc = ndr_encode_v4_ntacl(&sd_ndr, &acl);
15061498
if (rc) {
@@ -1557,11 +1549,7 @@ int ksmbd_vfs_get_sd_xattr(struct ksmbd_conn *conn,
15571549
goto out_free;
15581550
}
15591551

1560-
rc = ksmbd_gen_sd_hash(conn, acl_ndr.data, acl_ndr.offset, cmp_hash);
1561-
if (rc) {
1562-
pr_err("failed to generate hash for ndr acl\n");
1563-
goto out_free;
1564-
}
1552+
sha256(acl_ndr.data, acl_ndr.offset, cmp_hash);
15651553

15661554
if (memcmp(cmp_hash, acl.posix_acl_hash, XATTR_SD_HASH_SIZE)) {
15671555
pr_err("hash value diff\n");

0 commit comments

Comments
 (0)