Commit 0613ed91 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag '5.10-rc-smb3-fixes-part1' of git://git.samba.org/sfrench/cifs-2.6

Pull cifs updates from Steve French:

 - add support for recognizing special file types (char/block/fifo/
   symlink) for files created by Linux on WSL (a format we plan to move
   to as the default for creating special files on Linux, as it has
   advantages over the other current option, the SFU format) in readdir.

 - fix double queries to root directory when directory leases not
   supported (e.g. Samba)

 - fix querying mode bits (modefromsid mount option) for special file
   types

 - stronger encryption (gcm256), disabled by default until tested more
   broadly

 - allow querying owner when server reports 'well known SID' on query
   dir with SMB3.1.1 POSIX extensions

* tag '5.10-rc-smb3-fixes-part1' of git://git.samba.org/sfrench/cifs-2.6: (30 commits)
  SMB3: add support for recognizing WSL reparse tags
  cifs: remove bogus debug code
  smb3.1.1: fix typo in compression flag
  cifs: move smb version mount options into fs_context.c
  cifs: move cache mount options to fs_context.ch
  cifs: move security mount options into fs_context.ch
  cifs: add files to host new mount api
  smb3: do not try to cache root directory if dir leases not supported
  smb3: fix stat when special device file and mounted with modefromsid
  cifs: Print the address and port we are connecting to in generic_ip_connect()
  SMB3: Resolve data corruption of TCP server info fields
  cifs: make const array static, makes object smaller
  SMB3.1.1: Fix ids returned in POSIX query dir
  smb3: add dynamic trace point to trace when credits obtained
  smb3.1.1: do not fail if no encryption required but server doesn't support it
  cifs: Return the error from crypt_message when enc/dec key not found.
  smb3.1.1: set gcm256 when requested
  smb3.1.1: rename nonces used for GCM and CCM encryption
  smb3.1.1: print warning if server does not support requested encryption type
  smb3.1.1: add new module load parm enable_gcm_256
  ...
parents c4728cfb 13909d96
...@@ -10,7 +10,7 @@ cifs-y := trace.o cifsfs.o cifssmb.o cifs_debug.o connect.o dir.o file.o \ ...@@ -10,7 +10,7 @@ cifs-y := trace.o cifsfs.o cifssmb.o cifs_debug.o connect.o dir.o file.o \
cifs_unicode.o nterr.o cifsencrypt.o \ cifs_unicode.o nterr.o cifsencrypt.o \
readdir.o ioctl.o sess.o export.o smb1ops.o winucase.o \ readdir.o ioctl.o sess.o export.o smb1ops.o winucase.o \
smb2ops.o smb2maperror.o smb2transport.o \ smb2ops.o smb2maperror.o smb2transport.o \
smb2misc.o smb2pdu.o smb2inode.o smb2file.o cifsacl.o smb2misc.o smb2pdu.o smb2inode.o smb2file.o cifsacl.o fs_context.o
cifs-$(CONFIG_CIFS_XATTR) += xattr.o cifs-$(CONFIG_CIFS_XATTR) += xattr.o
......
...@@ -530,8 +530,8 @@ decode_negTokenInit(unsigned char *security_blob, int length, ...@@ -530,8 +530,8 @@ decode_negTokenInit(unsigned char *security_blob, int length,
return 0; return 0;
} else if ((cls != ASN1_CTX) || (con != ASN1_CON) } else if ((cls != ASN1_CTX) || (con != ASN1_CON)
|| (tag != ASN1_EOC)) { || (tag != ASN1_EOC)) {
cifs_dbg(FYI, "cls = %d con = %d tag = %d end = %p (%d) exit 0\n", cifs_dbg(FYI, "cls = %d con = %d tag = %d end = %p exit 0\n",
cls, con, tag, end, *end); cls, con, tag, end);
return 0; return 0;
} }
...@@ -541,8 +541,8 @@ decode_negTokenInit(unsigned char *security_blob, int length, ...@@ -541,8 +541,8 @@ decode_negTokenInit(unsigned char *security_blob, int length,
return 0; return 0;
} else if ((cls != ASN1_UNI) || (con != ASN1_CON) } else if ((cls != ASN1_UNI) || (con != ASN1_CON)
|| (tag != ASN1_SEQ)) { || (tag != ASN1_SEQ)) {
cifs_dbg(FYI, "cls = %d con = %d tag = %d end = %p (%d) exit 1\n", cifs_dbg(FYI, "cls = %d con = %d tag = %d end = %p exit 1\n",
cls, con, tag, end, *end); cls, con, tag, end);
return 0; return 0;
} }
...@@ -552,8 +552,8 @@ decode_negTokenInit(unsigned char *security_blob, int length, ...@@ -552,8 +552,8 @@ decode_negTokenInit(unsigned char *security_blob, int length,
return 0; return 0;
} else if ((cls != ASN1_CTX) || (con != ASN1_CON) } else if ((cls != ASN1_CTX) || (con != ASN1_CON)
|| (tag != ASN1_EOC)) { || (tag != ASN1_EOC)) {
cifs_dbg(FYI, "cls = %d con = %d tag = %d end = %p (%d) exit 0\n", cifs_dbg(FYI, "cls = %d con = %d tag = %d end = %p exit 0\n",
cls, con, tag, end, *end); cls, con, tag, end);
return 0; return 0;
} }
...@@ -564,8 +564,8 @@ decode_negTokenInit(unsigned char *security_blob, int length, ...@@ -564,8 +564,8 @@ decode_negTokenInit(unsigned char *security_blob, int length,
return 0; return 0;
} else if ((cls != ASN1_UNI) || (con != ASN1_CON) } else if ((cls != ASN1_UNI) || (con != ASN1_CON)
|| (tag != ASN1_SEQ)) { || (tag != ASN1_SEQ)) {
cifs_dbg(FYI, "cls = %d con = %d tag = %d end = %p (%d) exit 1\n", cifs_dbg(FYI, "cls = %d con = %d tag = %d sequence_end = %p exit 1\n",
cls, con, tag, end, *end); cls, con, tag, sequence_end);
return 0; return 0;
} }
......
...@@ -488,7 +488,13 @@ cifsConvertToUTF16(__le16 *target, const char *source, int srclen, ...@@ -488,7 +488,13 @@ cifsConvertToUTF16(__le16 *target, const char *source, int srclen,
else if (map_chars == SFM_MAP_UNI_RSVD) { else if (map_chars == SFM_MAP_UNI_RSVD) {
bool end_of_string; bool end_of_string;
if (i == srclen - 1) /**
* Remap spaces and periods found at the end of every
* component of the path. The special cases of '.' and
* '..' do not need to be dealt with explicitly because
* they are addressed in namei.c:link_path_walk().
**/
if ((i == srclen - 1) || (source[i+1] == '\\'))
end_of_string = true; end_of_string = true;
else else
end_of_string = false; end_of_string = false;
......
...@@ -338,7 +338,7 @@ id_to_sid(unsigned int cid, uint sidtype, struct cifs_sid *ssid) ...@@ -338,7 +338,7 @@ id_to_sid(unsigned int cid, uint sidtype, struct cifs_sid *ssid)
goto out_key_put; goto out_key_put;
} }
static int int
sid_to_id(struct cifs_sb_info *cifs_sb, struct cifs_sid *psid, sid_to_id(struct cifs_sb_info *cifs_sb, struct cifs_sid *psid,
struct cifs_fattr *fattr, uint sidtype) struct cifs_fattr *fattr, uint sidtype)
{ {
...@@ -359,7 +359,8 @@ sid_to_id(struct cifs_sb_info *cifs_sb, struct cifs_sid *psid, ...@@ -359,7 +359,8 @@ sid_to_id(struct cifs_sb_info *cifs_sb, struct cifs_sid *psid,
return -EIO; return -EIO;
} }
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UID_FROM_ACL) { if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UID_FROM_ACL) ||
(cifs_sb_master_tcon(cifs_sb)->posix_extensions)) {
uint32_t unix_id; uint32_t unix_id;
bool is_group; bool is_group;
......
...@@ -71,6 +71,8 @@ bool enable_oplocks = true; ...@@ -71,6 +71,8 @@ bool enable_oplocks = true;
bool linuxExtEnabled = true; bool linuxExtEnabled = true;
bool lookupCacheEnabled = true; bool lookupCacheEnabled = true;
bool disable_legacy_dialects; /* false by default */ bool disable_legacy_dialects; /* false by default */
bool enable_gcm_256; /* false by default, change when more servers support it */
bool require_gcm_256; /* false by default */
unsigned int global_secflags = CIFSSEC_DEF; unsigned int global_secflags = CIFSSEC_DEF;
/* unsigned int ntlmv2_support = 0; */ /* unsigned int ntlmv2_support = 0; */
unsigned int sign_CIFS_PDUs = 1; unsigned int sign_CIFS_PDUs = 1;
...@@ -104,6 +106,12 @@ MODULE_PARM_DESC(slow_rsp_threshold, "Amount of time (in seconds) to wait " ...@@ -104,6 +106,12 @@ MODULE_PARM_DESC(slow_rsp_threshold, "Amount of time (in seconds) to wait "
module_param(enable_oplocks, bool, 0644); module_param(enable_oplocks, bool, 0644);
MODULE_PARM_DESC(enable_oplocks, "Enable or disable oplocks. Default: y/Y/1"); MODULE_PARM_DESC(enable_oplocks, "Enable or disable oplocks. Default: y/Y/1");
module_param(enable_gcm_256, bool, 0644);
MODULE_PARM_DESC(enable_gcm_256, "Enable requesting strongest (256 bit) GCM encryption. Default: n/N/0");
module_param(require_gcm_256, bool, 0644);
MODULE_PARM_DESC(require_gcm_256, "Require strongest (256 bit) GCM encryption. Default: n/N/0");
module_param(disable_legacy_dialects, bool, 0644); module_param(disable_legacy_dialects, bool, 0644);
MODULE_PARM_DESC(disable_legacy_dialects, "To improve security it may be " MODULE_PARM_DESC(disable_legacy_dialects, "To improve security it may be "
"helpful to restrict the ability to " "helpful to restrict the ability to "
......
...@@ -195,18 +195,6 @@ struct smb_rqst { ...@@ -195,18 +195,6 @@ struct smb_rqst {
unsigned int rq_tailsz; /* length of last page */ unsigned int rq_tailsz; /* length of last page */
}; };
enum smb_version {
Smb_1 = 1,
Smb_20,
Smb_21,
Smb_30,
Smb_302,
Smb_311,
Smb_3any,
Smb_default,
Smb_version_err
};
struct mid_q_entry; struct mid_q_entry;
struct TCP_Server_Info; struct TCP_Server_Info;
struct cifsFileInfo; struct cifsFileInfo;
...@@ -510,6 +498,8 @@ struct smb_version_operations { ...@@ -510,6 +498,8 @@ struct smb_version_operations {
struct fiemap_extent_info *, u64, u64); struct fiemap_extent_info *, u64, u64);
/* version specific llseek implementation */ /* version specific llseek implementation */
loff_t (*llseek)(struct file *, struct cifs_tcon *, loff_t, int); loff_t (*llseek)(struct file *, struct cifs_tcon *, loff_t, int);
/* Check for STATUS_IO_TIMEOUT */
bool (*is_status_io_timeout)(char *buf);
}; };
struct smb_version_values { struct smb_version_values {
...@@ -1954,6 +1944,8 @@ extern bool lookupCacheEnabled; ...@@ -1954,6 +1944,8 @@ extern bool lookupCacheEnabled;
extern unsigned int global_secflags; /* if on, session setup sent extern unsigned int global_secflags; /* if on, session setup sent
with more secure ntlmssp2 challenge/resp */ with more secure ntlmssp2 challenge/resp */
extern unsigned int sign_CIFS_PDUs; /* enable smb packet signing */ extern unsigned int sign_CIFS_PDUs; /* enable smb packet signing */
extern bool enable_gcm_256; /* allow optional negotiate of strongest signing (aes-gcm-256) */
extern bool require_gcm_256; /* require use of strongest signing (aes-gcm-256) */
extern bool linuxExtEnabled;/*enable Linux/Unix CIFS extensions*/ extern bool linuxExtEnabled;/*enable Linux/Unix CIFS extensions*/
extern unsigned int CIFSMaxBufSize; /* max size not including hdr */ extern unsigned int CIFSMaxBufSize; /* max size not including hdr */
extern unsigned int cifs_min_rcv; /* min size of big ntwrk buf pool */ extern unsigned int cifs_min_rcv; /* min size of big ntwrk buf pool */
......
...@@ -209,6 +209,8 @@ extern int cifs_set_file_info(struct inode *inode, struct iattr *attrs, ...@@ -209,6 +209,8 @@ extern int cifs_set_file_info(struct inode *inode, struct iattr *attrs,
extern int cifs_rename_pending_delete(const char *full_path, extern int cifs_rename_pending_delete(const char *full_path,
struct dentry *dentry, struct dentry *dentry,
const unsigned int xid); const unsigned int xid);
extern int sid_to_id(struct cifs_sb_info *cifs_sb, struct cifs_sid *psid,
struct cifs_fattr *fattr, uint sidtype);
extern int cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb, extern int cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb,
struct cifs_fattr *fattr, struct inode *inode, struct cifs_fattr *fattr, struct inode *inode,
bool get_mode_from_special_sid, bool get_mode_from_special_sid,
......
...@@ -61,6 +61,7 @@ ...@@ -61,6 +61,7 @@
#ifdef CONFIG_CIFS_DFS_UPCALL #ifdef CONFIG_CIFS_DFS_UPCALL
#include "dfs_cache.h" #include "dfs_cache.h"
#endif #endif
#include "fs_context.h"
extern mempool_t *cifs_req_poolp; extern mempool_t *cifs_req_poolp;
extern bool disable_legacy_dialects; extern bool disable_legacy_dialects;
...@@ -69,6 +70,9 @@ extern bool disable_legacy_dialects; ...@@ -69,6 +70,9 @@ extern bool disable_legacy_dialects;
#define TLINK_ERROR_EXPIRE (1 * HZ) #define TLINK_ERROR_EXPIRE (1 * HZ)
#define TLINK_IDLE_EXPIRE (600 * HZ) #define TLINK_IDLE_EXPIRE (600 * HZ)
/* Drop the connection to not overload the server */
#define NUM_STATUS_IO_TIMEOUT 5
enum { enum {
/* Mount options that take no arguments */ /* Mount options that take no arguments */
Opt_user_xattr, Opt_nouser_xattr, Opt_user_xattr, Opt_nouser_xattr,
...@@ -276,66 +280,6 @@ static const match_table_t cifs_mount_option_tokens = { ...@@ -276,66 +280,6 @@ static const match_table_t cifs_mount_option_tokens = {
{ Opt_err, NULL } { Opt_err, NULL }
}; };
enum {
Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
Opt_sec_ntlmsspi, Opt_sec_ntlmssp,
Opt_ntlm, Opt_sec_ntlmi, Opt_sec_ntlmv2,
Opt_sec_ntlmv2i, Opt_sec_lanman,
Opt_sec_none,
Opt_sec_err
};
static const match_table_t cifs_secflavor_tokens = {
{ Opt_sec_krb5, "krb5" },
{ Opt_sec_krb5i, "krb5i" },
{ Opt_sec_krb5p, "krb5p" },
{ Opt_sec_ntlmsspi, "ntlmsspi" },
{ Opt_sec_ntlmssp, "ntlmssp" },
{ Opt_ntlm, "ntlm" },
{ Opt_sec_ntlmi, "ntlmi" },
{ Opt_sec_ntlmv2, "nontlm" },
{ Opt_sec_ntlmv2, "ntlmv2" },
{ Opt_sec_ntlmv2i, "ntlmv2i" },
{ Opt_sec_lanman, "lanman" },
{ Opt_sec_none, "none" },
{ Opt_sec_err, NULL }
};
/* cache flavors */
enum {
Opt_cache_loose,
Opt_cache_strict,
Opt_cache_none,
Opt_cache_ro,
Opt_cache_rw,
Opt_cache_err
};
static const match_table_t cifs_cacheflavor_tokens = {
{ Opt_cache_loose, "loose" },
{ Opt_cache_strict, "strict" },
{ Opt_cache_none, "none" },
{ Opt_cache_ro, "ro" },
{ Opt_cache_rw, "singleclient" },
{ Opt_cache_err, NULL }
};
static const match_table_t cifs_smb_version_tokens = {
{ Smb_1, SMB1_VERSION_STRING },
{ Smb_20, SMB20_VERSION_STRING},
{ Smb_21, SMB21_VERSION_STRING },
{ Smb_30, SMB30_VERSION_STRING },
{ Smb_302, SMB302_VERSION_STRING },
{ Smb_302, ALT_SMB302_VERSION_STRING },
{ Smb_311, SMB311_VERSION_STRING },
{ Smb_311, ALT_SMB311_VERSION_STRING },
{ Smb_3any, SMB3ANY_VERSION_STRING },
{ Smb_default, SMBDEFAULT_VERSION_STRING },
{ Smb_version_err, NULL }
};
static int ip_connect(struct TCP_Server_Info *server); static int ip_connect(struct TCP_Server_Info *server);
static int generic_ip_connect(struct TCP_Server_Info *server); static int generic_ip_connect(struct TCP_Server_Info *server);
static void tlink_rb_insert(struct rb_root *root, struct tcon_link *new_tlink); static void tlink_rb_insert(struct rb_root *root, struct tcon_link *new_tlink);
...@@ -1117,7 +1061,7 @@ cifs_demultiplex_thread(void *p) ...@@ -1117,7 +1061,7 @@ cifs_demultiplex_thread(void *p)
struct task_struct *task_to_wake = NULL; struct task_struct *task_to_wake = NULL;
struct mid_q_entry *mids[MAX_COMPOUND]; struct mid_q_entry *mids[MAX_COMPOUND];
char *bufs[MAX_COMPOUND]; char *bufs[MAX_COMPOUND];
unsigned int noreclaim_flag; unsigned int noreclaim_flag, num_io_timeout = 0;
noreclaim_flag = memalloc_noreclaim_save(); noreclaim_flag = memalloc_noreclaim_save();
cifs_dbg(FYI, "Demultiplex PID: %d\n", task_pid_nr(current)); cifs_dbg(FYI, "Demultiplex PID: %d\n", task_pid_nr(current));
...@@ -1213,6 +1157,16 @@ cifs_demultiplex_thread(void *p) ...@@ -1213,6 +1157,16 @@ cifs_demultiplex_thread(void *p)
continue; continue;
} }
if (server->ops->is_status_io_timeout &&
server->ops->is_status_io_timeout(buf)) {
num_io_timeout++;
if (num_io_timeout > NUM_STATUS_IO_TIMEOUT) {
cifs_reconnect(server);
num_io_timeout = 0;
continue;
}
}
server->lstrp = jiffies; server->lstrp = jiffies;
for (i = 0; i < num_mids; i++) { for (i = 0; i < num_mids; i++) {
...@@ -1359,177 +1313,6 @@ static int get_option_gid(substring_t args[], kgid_t *result) ...@@ -1359,177 +1313,6 @@ static int get_option_gid(substring_t args[], kgid_t *result)
return 0; return 0;
} }
static int cifs_parse_security_flavors(char *value,
struct smb_vol *vol)
{
substring_t args[MAX_OPT_ARGS];
/*
* With mount options, the last one should win. Reset any existing
* settings back to default.
*/
vol->sectype = Unspecified;
vol->sign = false;
switch (match_token(value, cifs_secflavor_tokens, args)) {
case Opt_sec_krb5p:
cifs_dbg(VFS, "sec=krb5p is not supported!\n");
return 1;
case Opt_sec_krb5i:
vol->sign = true;
fallthrough;
case Opt_sec_krb5:
vol->sectype = Kerberos;
break;
case Opt_sec_ntlmsspi:
vol->sign = true;
fallthrough;
case Opt_sec_ntlmssp:
vol->sectype = RawNTLMSSP;
break;
case Opt_sec_ntlmi:
vol->sign = true;
fallthrough;
case Opt_ntlm:
vol->sectype = NTLM;
break;
case Opt_sec_ntlmv2i:
vol->sign = true;
fallthrough;
case Opt_sec_ntlmv2:
vol->sectype = NTLMv2;
break;
#ifdef CONFIG_CIFS_WEAK_PW_HASH
case Opt_sec_lanman:
vol->sectype = LANMAN;
break;
#endif
case Opt_sec_none:
vol->nullauth = 1;
break;
default:
cifs_dbg(VFS, "bad security option: %s\n", value);
return 1;
}
return 0;
}
static int
cifs_parse_cache_flavor(char *value, struct smb_vol *vol)
{
substring_t args[MAX_OPT_ARGS];
switch (match_token(value, cifs_cacheflavor_tokens, args)) {
case Opt_cache_loose:
vol->direct_io = false;
vol->strict_io = false;
vol->cache_ro = false;
vol->cache_rw = false;
break;
case Opt_cache_strict:
vol->direct_io = false;
vol->strict_io = true;
vol->cache_ro = false;
vol->cache_rw = false;
break;
case Opt_cache_none:
vol->direct_io = true;
vol->strict_io = false;
vol->cache_ro = false;
vol->cache_rw = false;
break;
case Opt_cache_ro:
vol->direct_io = false;
vol->strict_io = false;
vol->cache_ro = true;
vol->cache_rw = false;
break;
case Opt_cache_rw:
vol->direct_io = false;
vol->strict_io = false;
vol->cache_ro = false;
vol->cache_rw = true;
break;
default:
cifs_dbg(VFS, "bad cache= option: %s\n", value);
return 1;
}
return 0;
}
static int
cifs_parse_smb_version(char *value, struct smb_vol *vol, bool is_smb3)
{
substring_t args[MAX_OPT_ARGS];
switch (match_token(value, cifs_smb_version_tokens, args)) {
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
case Smb_1:
if (disable_legacy_dialects) {
cifs_dbg(VFS, "mount with legacy dialect disabled\n");
return 1;
}
if (is_smb3) {
cifs_dbg(VFS, "vers=1.0 (cifs) not permitted when mounting with smb3\n");
return 1;
}
cifs_dbg(VFS, "Use of the less secure dialect vers=1.0 is not recommended unless required for access to very old servers\n");
vol->ops = &smb1_operations;
vol->vals = &smb1_values;
break;
case Smb_20:
if (disable_legacy_dialects) {
cifs_dbg(VFS, "mount with legacy dialect disabled\n");
return 1;
}
if (is_smb3) {
cifs_dbg(VFS, "vers=2.0 not permitted when mounting with smb3\n");
return 1;
}
vol->ops = &smb20_operations;
vol->vals = &smb20_values;
break;
#else
case Smb_1:
cifs_dbg(VFS, "vers=1.0 (cifs) mount not permitted when legacy dialects disabled\n");
return 1;
case Smb_20:
cifs_dbg(VFS, "vers=2.0 mount not permitted when legacy dialects disabled\n");
return 1;
#endif /* CIFS_ALLOW_INSECURE_LEGACY */
case Smb_21:
vol->ops = &smb21_operations;
vol->vals = &smb21_values;
break;
case Smb_30:
vol->ops = &smb30_operations;
vol->vals = &smb30_values;
break;
case Smb_302:
vol->ops = &smb30_operations; /* currently identical with 3.0 */
vol->vals = &smb302_values;
break;
case Smb_311:
vol->ops = &smb311_operations;
vol->vals = &smb311_values;
break;
case Smb_3any:
vol->ops = &smb30_operations; /* currently identical with 3.0 */
vol->vals = &smb3any_values;
break;
case Smb_default:
vol->ops = &smb30_operations; /* currently identical with 3.0 */
vol->vals = &smbdefault_values;
break;
default:
cifs_dbg(VFS, "Unknown vers= option specified: %s\n", value);
return 1;
}
return 0;
}
/* /*
* Parse a devname into substrings and populate the vol->UNC and vol->prepath * Parse a devname into substrings and populate the vol->UNC and vol->prepath
* fields with the result. Returns 0 on success and an error otherwise. * fields with the result. Returns 0 on success and an error otherwise.
...@@ -3595,7 +3378,10 @@ cifs_get_tcon(struct cifs_ses *ses, struct smb_vol *volume_info) ...@@ -3595,7 +3378,10 @@ cifs_get_tcon(struct cifs_ses *ses, struct smb_vol *volume_info)
*/ */
tcon->retry = volume_info->retry; tcon->retry = volume_info->retry;
tcon->nocase = volume_info->nocase; tcon->nocase = volume_info->nocase;
tcon->nohandlecache = volume_info->nohandlecache; if (ses->server->capabilities & SMB2_GLOBAL_CAP_DIRECTORY_LEASING)
tcon->nohandlecache = volume_info->nohandlecache;
else
tcon->nohandlecache = 1;
tcon->nodelete = volume_info->nodelete; tcon->nodelete = volume_info->nodelete;
tcon->local_lease = volume_info->local_lease; tcon->local_lease = volume_info->local_lease;
INIT_LIST_HEAD(&tcon->pending_opens); INIT_LIST_HEAD(&tcon->pending_opens);
...@@ -3889,13 +3675,21 @@ generic_ip_connect(struct TCP_Server_Info *server) ...@@ -3889,13 +3675,21 @@ generic_ip_connect(struct TCP_Server_Info *server)
saddr = (struct sockaddr *) &server->dstaddr; saddr = (struct sockaddr *) &server->dstaddr;
if (server->dstaddr.ss_family == AF_INET6) { if (server->dstaddr.ss_family == AF_INET6) {
sport = ((struct sockaddr_in6 *) saddr)->sin6_port; struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)&server->dstaddr;
sport = ipv6->sin6_port;
slen = sizeof(struct sockaddr_in6); slen = sizeof(struct sockaddr_in6);
sfamily = AF_INET6; sfamily = AF_INET6;
cifs_dbg(FYI, "%s: connecting to [%pI6]:%d\n", __func__, &ipv6->sin6_addr,
ntohs(sport));
} else { } else {
sport = ((struct sockaddr_in *) saddr)->sin_port; struct sockaddr_in *ipv4 = (struct sockaddr_in *)&server->dstaddr;
sport = ipv4->sin_port;
slen = sizeof(struct sockaddr_in); slen = sizeof(struct sockaddr_in);
sfamily = AF_INET; sfamily = AF_INET;
cifs_dbg(FYI, "%s: connecting to %pI4:%d\n", __func__, &ipv4->sin_addr,
ntohs(sport));
} }
if (socket == NULL) { if (socket == NULL) {
......
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2020, Microsoft Corporation.
*
* Author(s): Steve French <stfrench@microsoft.com>
* David Howells <dhowells@redhat.com>
*/
#include "cifsglob.h"
#include "cifs_debug.h"
#include "fs_context.h"
static const match_table_t cifs_smb_version_tokens = {
{ Smb_1, SMB1_VERSION_STRING },
{ Smb_20, SMB20_VERSION_STRING},
{ Smb_21, SMB21_VERSION_STRING },
{ Smb_30, SMB30_VERSION_STRING },
{ Smb_302, SMB302_VERSION_STRING },
{ Smb_302, ALT_SMB302_VERSION_STRING },
{ Smb_311, SMB311_VERSION_STRING },
{ Smb_311, ALT_SMB311_VERSION_STRING },
{ Smb_3any, SMB3ANY_VERSION_STRING },
{ Smb_default, SMBDEFAULT_VERSION_STRING },
{ Smb_version_err, NULL }
};
int
cifs_parse_smb_version(char *value, struct smb_vol *vol, bool is_smb3)
{
substring_t args[MAX_OPT_ARGS];
switch (match_token(value, cifs_smb_version_tokens, args)) {
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
case Smb_1:
if (disable_legacy_dialects) {
cifs_dbg(VFS, "mount with legacy dialect disabled\n");
return 1;
}
if (is_smb3) {
cifs_dbg(VFS, "vers=1.0 (cifs) not permitted when mounting with smb3\n");
return 1;
}
cifs_dbg(VFS, "Use of the less secure dialect vers=1.0 is not recommended unless required for access to very old servers\n");
vol->ops = &smb1_operations;
vol->vals = &smb1_values;
break;
case Smb_20:
if (disable_legacy_dialects) {
cifs_dbg(VFS, "mount with legacy dialect disabled\n");
return 1;
}
if (is_smb3) {
cifs_dbg(VFS, "vers=2.0 not permitted when mounting with smb3\n");
return 1;
}
vol->ops = &smb20_operations;
vol->vals = &smb20_values;
break;
#else
case Smb_1:
cifs_dbg(VFS, "vers=1.0 (cifs) mount not permitted when legacy dialects disabled\n");
return 1;
case Smb_20:
cifs_dbg(VFS, "vers=2.0 mount not permitted when legacy dialects disabled\n");
return 1;
#endif /* CIFS_ALLOW_INSECURE_LEGACY */
case Smb_21:
vol->ops = &smb21_operations;
vol->vals = &smb21_values;
break;
case Smb_30:
vol->ops = &smb30_operations;
vol->vals = &smb30_values;
break;
case Smb_302:
vol->ops = &smb30_operations; /* currently identical with 3.0 */
vol->vals = &smb302_values;
break;
case Smb_311:
vol->ops = &smb311_operations;
vol->vals = &smb311_values;
break;
case Smb_3any:
vol->ops = &smb30_operations; /* currently identical with 3.0 */
vol->vals = &smb3any_values;
break;
case Smb_default:
vol->ops = &smb30_operations; /* currently identical with 3.0 */
vol->vals = &smbdefault_values;
break;
default:
cifs_dbg(VFS, "Unknown vers= option specified: %s\n", value);
return 1;
}
return 0;
}
static const match_table_t cifs_secflavor_tokens = {
{ Opt_sec_krb5, "krb5" },
{ Opt_sec_krb5i, "krb5i" },
{ Opt_sec_krb5p, "krb5p" },
{ Opt_sec_ntlmsspi, "ntlmsspi" },
{ Opt_sec_ntlmssp, "ntlmssp" },
{ Opt_ntlm, "ntlm" },
{ Opt_sec_ntlmi, "ntlmi" },
{ Opt_sec_ntlmv2, "nontlm" },
{ Opt_sec_ntlmv2, "ntlmv2" },
{ Opt_sec_ntlmv2i, "ntlmv2i" },
{ Opt_sec_lanman, "lanman" },
{ Opt_sec_none, "none" },
{ Opt_sec_err, NULL }
};
int cifs_parse_security_flavors(char *value, struct smb_vol *vol)
{
substring_t args[MAX_OPT_ARGS];
/*
* With mount options, the last one should win. Reset any existing
* settings back to default.
*/
vol->sectype = Unspecified;
vol->sign = false;
switch (match_token(value, cifs_secflavor_tokens, args)) {
case Opt_sec_krb5p:
cifs_dbg(VFS, "sec=krb5p is not supported!\n");
return 1;
case Opt_sec_krb5i:
vol->sign = true;
fallthrough;
case Opt_sec_krb5:
vol->sectype = Kerberos;
break;
case Opt_sec_ntlmsspi:
vol->sign = true;
fallthrough;
case Opt_sec_ntlmssp:
vol->sectype = RawNTLMSSP;
break;
case Opt_sec_ntlmi:
vol->sign = true;
fallthrough;
case Opt_ntlm:
vol->sectype = NTLM;
break;
case Opt_sec_ntlmv2i:
vol->sign = true;
fallthrough;
case Opt_sec_ntlmv2:
vol->sectype = NTLMv2;
break;
#ifdef CONFIG_CIFS_WEAK_PW_HASH
case Opt_sec_lanman:
vol->sectype = LANMAN;
break;
#endif
case Opt_sec_none:
vol->nullauth = 1;
break;
default:
cifs_dbg(VFS, "bad security option: %s\n", value);
return 1;
}
return 0;
}
static const match_table_t cifs_cacheflavor_tokens = {
{ Opt_cache_loose, "loose" },
{ Opt_cache_strict, "strict" },
{ Opt_cache_none, "none" },
{ Opt_cache_ro, "ro" },
{ Opt_cache_rw, "singleclient" },
{ Opt_cache_err, NULL }
};
int
cifs_parse_cache_flavor(char *value, struct smb_vol *vol)
{
substring_t args[MAX_OPT_ARGS];
switch (match_token(value, cifs_cacheflavor_tokens, args)) {
case Opt_cache_loose:
vol->direct_io = false;
vol->strict_io = false;
vol->cache_ro = false;
vol->cache_rw = false;
break;
case Opt_cache_strict:
vol->direct_io = false;
vol->strict_io = true;
vol->cache_ro = false;
vol->cache_rw = false;
break;
case Opt_cache_none:
vol->direct_io = true;
vol->strict_io = false;
vol->cache_ro = false;
vol->cache_rw = false;
break;
case Opt_cache_ro:
vol->direct_io = false;
vol->strict_io = false;
vol->cache_ro = true;
vol->cache_rw = false;
break;
case Opt_cache_rw:
vol->direct_io = false;
vol->strict_io = false;
vol->cache_ro = false;
vol->cache_rw = true;
break;
default:
cifs_dbg(VFS, "bad cache= option: %s\n", value);
return 1;
}
return 0;
}
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (C) 2020, Microsoft Corporation.
*
* Author(s): Steve French <stfrench@microsoft.com>
* David Howells <dhowells@redhat.com>
*/
#ifndef _FS_CONTEXT_H
#define _FS_CONTEXT_H
#include <linux/parser.h>
#include "cifsglob.h"
enum smb_version {
Smb_1 = 1,
Smb_20,
Smb_21,
Smb_30,
Smb_302,
Smb_311,
Smb_3any,
Smb_default,
Smb_version_err
};
int cifs_parse_smb_version(char *value, struct smb_vol *vol, bool is_smb3);
enum {
Opt_cache_loose,
Opt_cache_strict,
Opt_cache_none,
Opt_cache_ro,
Opt_cache_rw,
Opt_cache_err
};
int cifs_parse_cache_flavor(char *value, struct smb_vol *vol);
enum cifs_sec_param {
Opt_sec_krb5,
Opt_sec_krb5i,
Opt_sec_krb5p,
Opt_sec_ntlmsspi,
Opt_sec_ntlmssp,
Opt_ntlm,
Opt_sec_ntlmi,
Opt_sec_ntlmv2,
Opt_sec_ntlmv2i,
Opt_sec_lanman,
Opt_sec_none,
Opt_sec_err
};
int cifs_parse_security_flavors(char *value, struct smb_vol *vol);
#endif
...@@ -2883,13 +2883,18 @@ cifs_setattr(struct dentry *direntry, struct iattr *attrs) ...@@ -2883,13 +2883,18 @@ cifs_setattr(struct dentry *direntry, struct iattr *attrs)
{ {
struct cifs_sb_info *cifs_sb = CIFS_SB(direntry->d_sb); struct cifs_sb_info *cifs_sb = CIFS_SB(direntry->d_sb);
struct cifs_tcon *pTcon = cifs_sb_master_tcon(cifs_sb); struct cifs_tcon *pTcon = cifs_sb_master_tcon(cifs_sb);
int rc, retries = 0;
if (pTcon->unix_ext) do {
return cifs_setattr_unix(direntry, attrs); if (pTcon->unix_ext)
rc = cifs_setattr_unix(direntry, attrs);
return cifs_setattr_nounix(direntry, attrs); else
rc = cifs_setattr_nounix(direntry, attrs);
retries++;
} while (is_retryable_error(rc) && retries < 2);
/* BB: add cifs_setattr_legacy for really old servers */ /* BB: add cifs_setattr_legacy for really old servers */
return rc;
} }
#if 0 #if 0
......
...@@ -168,10 +168,33 @@ cifs_fill_common_info(struct cifs_fattr *fattr, struct cifs_sb_info *cifs_sb) ...@@ -168,10 +168,33 @@ cifs_fill_common_info(struct cifs_fattr *fattr, struct cifs_sb_info *cifs_sb)
fattr->cf_uid = cifs_sb->mnt_uid; fattr->cf_uid = cifs_sb->mnt_uid;
fattr->cf_gid = cifs_sb->mnt_gid; fattr->cf_gid = cifs_sb->mnt_gid;
/*
* The IO_REPARSE_TAG_LX_ tags originally were used by WSL but they
* are preferred by the Linux client in some cases since, unlike
* the NFS reparse tag (or EAs), they don't require an extra query
* to determine which type of special file they represent.
* TODO: go through all documented reparse tags to see if we can
* reasonably map some of them to directories vs. files vs. symlinks
*/
if (fattr->cf_cifsattrs & ATTR_DIRECTORY) { if (fattr->cf_cifsattrs & ATTR_DIRECTORY) {
fattr->cf_mode = S_IFDIR | cifs_sb->mnt_dir_mode; fattr->cf_mode = S_IFDIR | cifs_sb->mnt_dir_mode;
fattr->cf_dtype = DT_DIR; fattr->cf_dtype = DT_DIR;
} else { } else if (fattr->cf_cifstag == IO_REPARSE_TAG_LX_SYMLINK) {
fattr->cf_mode |= S_IFLNK | cifs_sb->mnt_file_mode;
fattr->cf_dtype = DT_LNK;
} else if (fattr->cf_cifstag == IO_REPARSE_TAG_LX_FIFO) {
fattr->cf_mode |= S_IFIFO | cifs_sb->mnt_file_mode;
fattr->cf_dtype = DT_FIFO;
} else if (fattr->cf_cifstag == IO_REPARSE_TAG_AF_UNIX) {
fattr->cf_mode |= S_IFSOCK | cifs_sb->mnt_file_mode;
fattr->cf_dtype = DT_SOCK;
} else if (fattr->cf_cifstag == IO_REPARSE_TAG_LX_CHR) {
fattr->cf_mode |= S_IFCHR | cifs_sb->mnt_file_mode;
fattr->cf_dtype = DT_CHR;
} else if (fattr->cf_cifstag == IO_REPARSE_TAG_LX_BLK) {
fattr->cf_mode |= S_IFBLK | cifs_sb->mnt_file_mode;
fattr->cf_dtype = DT_BLK;
} else { /* TODO: should we mark some other reparse points (like DFSR) as directories? */
fattr->cf_mode = S_IFREG | cifs_sb->mnt_file_mode; fattr->cf_mode = S_IFREG | cifs_sb->mnt_file_mode;
fattr->cf_dtype = DT_REG; fattr->cf_dtype = DT_REG;
} }
...@@ -267,9 +290,8 @@ cifs_posix_to_fattr(struct cifs_fattr *fattr, struct smb2_posix_info *info, ...@@ -267,9 +290,8 @@ cifs_posix_to_fattr(struct cifs_fattr *fattr, struct smb2_posix_info *info,
if (reparse_file_needs_reval(fattr)) if (reparse_file_needs_reval(fattr))
fattr->cf_flags |= CIFS_FATTR_NEED_REVAL; fattr->cf_flags |= CIFS_FATTR_NEED_REVAL;
/* TODO map SIDs */ sid_to_id(cifs_sb, &parsed.owner, fattr, SIDOWNER);
fattr->cf_uid = cifs_sb->mnt_uid; sid_to_id(cifs_sb, &parsed.group, fattr, SIDGROUP);
fattr->cf_gid = cifs_sb->mnt_gid;
} }
static void __dir_info_to_fattr(struct cifs_fattr *fattr, const void *info) static void __dir_info_to_fattr(struct cifs_fattr *fattr, const void *info)
...@@ -360,11 +382,11 @@ int get_symlink_reparse_path(char *full_path, struct cifs_sb_info *cifs_sb, ...@@ -360,11 +382,11 @@ int get_symlink_reparse_path(char *full_path, struct cifs_sb_info *cifs_sb,
*/ */
static int static int
initiate_cifs_search(const unsigned int xid, struct file *file) initiate_cifs_search(const unsigned int xid, struct file *file,
char *full_path)
{ {
__u16 search_flags; __u16 search_flags;
int rc = 0; int rc = 0;
char *full_path = NULL;
struct cifsFileInfo *cifsFile; struct cifsFileInfo *cifsFile;
struct cifs_sb_info *cifs_sb = CIFS_FILE_SB(file); struct cifs_sb_info *cifs_sb = CIFS_FILE_SB(file);
struct tcon_link *tlink = NULL; struct tcon_link *tlink = NULL;
...@@ -400,12 +422,6 @@ initiate_cifs_search(const unsigned int xid, struct file *file) ...@@ -400,12 +422,6 @@ initiate_cifs_search(const unsigned int xid, struct file *file)
cifsFile->invalidHandle = true; cifsFile->invalidHandle = true;
cifsFile->srch_inf.endOfSearch = false; cifsFile->srch_inf.endOfSearch = false;
full_path = build_path_from_dentry(file_dentry(file));
if (full_path == NULL) {
rc = -ENOMEM;
goto error_exit;
}
cifs_dbg(FYI, "Full path: %s start at: %lld\n", full_path, file->f_pos); cifs_dbg(FYI, "Full path: %s start at: %lld\n", full_path, file->f_pos);
ffirst_retry: ffirst_retry:
...@@ -444,7 +460,6 @@ initiate_cifs_search(const unsigned int xid, struct file *file) ...@@ -444,7 +460,6 @@ initiate_cifs_search(const unsigned int xid, struct file *file)
goto ffirst_retry; goto ffirst_retry;
} }
error_exit: error_exit:
kfree(full_path);
cifs_put_tlink(tlink); cifs_put_tlink(tlink);
return rc; return rc;
} }
...@@ -688,7 +703,8 @@ static int cifs_save_resume_key(const char *current_entry, ...@@ -688,7 +703,8 @@ static int cifs_save_resume_key(const char *current_entry,
*/ */
static int static int
find_cifs_entry(const unsigned int xid, struct cifs_tcon *tcon, loff_t pos, find_cifs_entry(const unsigned int xid, struct cifs_tcon *tcon, loff_t pos,
struct file *file, char **current_entry, int *num_to_ret) struct file *file, char *full_path,
char **current_entry, int *num_to_ret)
{ {
__u16 search_flags; __u16 search_flags;
int rc = 0; int rc = 0;
...@@ -741,7 +757,7 @@ find_cifs_entry(const unsigned int xid, struct cifs_tcon *tcon, loff_t pos, ...@@ -741,7 +757,7 @@ find_cifs_entry(const unsigned int xid, struct cifs_tcon *tcon, loff_t pos,
ntwrk_buf_start); ntwrk_buf_start);
cfile->srch_inf.ntwrk_buf_start = NULL; cfile->srch_inf.ntwrk_buf_start = NULL;
} }
rc = initiate_cifs_search(xid, file); rc = initiate_cifs_search(xid, file, full_path);
if (rc) { if (rc) {
cifs_dbg(FYI, "error %d reinitiating a search on rewind\n", cifs_dbg(FYI, "error %d reinitiating a search on rewind\n",
rc); rc);
...@@ -925,15 +941,22 @@ int cifs_readdir(struct file *file, struct dir_context *ctx) ...@@ -925,15 +941,22 @@ int cifs_readdir(struct file *file, struct dir_context *ctx)
char *tmp_buf = NULL; char *tmp_buf = NULL;
char *end_of_smb; char *end_of_smb;
unsigned int max_len; unsigned int max_len;
char *full_path = NULL;
xid = get_xid(); xid = get_xid();
full_path = build_path_from_dentry(file_dentry(file));
if (full_path == NULL) {
rc = -ENOMEM;
goto rddir2_exit;
}
/* /*
* Ensure FindFirst doesn't fail before doing filldir() for '.' and * Ensure FindFirst doesn't fail before doing filldir() for '.' and
* '..'. Otherwise we won't be able to notify VFS in case of failure. * '..'. Otherwise we won't be able to notify VFS in case of failure.
*/ */
if (file->private_data == NULL) { if (file->private_data == NULL) {
rc = initiate_cifs_search(xid, file); rc = initiate_cifs_search(xid, file, full_path);
cifs_dbg(FYI, "initiate cifs search rc %d\n", rc); cifs_dbg(FYI, "initiate cifs search rc %d\n", rc);
if (rc) if (rc)
goto rddir2_exit; goto rddir2_exit;
...@@ -960,8 +983,8 @@ int cifs_readdir(struct file *file, struct dir_context *ctx) ...@@ -960,8 +983,8 @@ int cifs_readdir(struct file *file, struct dir_context *ctx)
} */ } */
tcon = tlink_tcon(cifsFile->tlink); tcon = tlink_tcon(cifsFile->tlink);
rc = find_cifs_entry(xid, tcon, ctx->pos, file, &current_entry, rc = find_cifs_entry(xid, tcon, ctx->pos, file, full_path,
&num_to_fill); &current_entry, &num_to_fill);
if (rc) { if (rc) {
cifs_dbg(FYI, "fce error %d\n", rc); cifs_dbg(FYI, "fce error %d\n", rc);
goto rddir2_exit; goto rddir2_exit;
...@@ -1019,6 +1042,7 @@ int cifs_readdir(struct file *file, struct dir_context *ctx) ...@@ -1019,6 +1042,7 @@ int cifs_readdir(struct file *file, struct dir_context *ctx)
kfree(tmp_buf); kfree(tmp_buf);
rddir2_exit: rddir2_exit:
kfree(full_path);
free_xid(xid); free_xid(xid);
return rc; return rc;
} }
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
#define SMB2_HMACSHA256_SIZE (32) #define SMB2_HMACSHA256_SIZE (32)
#define SMB2_CMACAES_SIZE (16) #define SMB2_CMACAES_SIZE (16)
#define SMB3_SIGNKEY_SIZE (16) #define SMB3_SIGNKEY_SIZE (16)
#define SMB3_GCM256_CRYPTKEY_SIZE (32)
/* Maximum buffer size value we can send with 1 credit */ /* Maximum buffer size value we can send with 1 credit */
#define SMB2_MAX_BUFFER_SIZE 65536 #define SMB2_MAX_BUFFER_SIZE 65536
......
...@@ -511,9 +511,9 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon, ...@@ -511,9 +511,9 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
int rc; int rc;
struct smb2_file_all_info *smb2_data; struct smb2_file_all_info *smb2_data;
__u32 create_options = 0; __u32 create_options = 0;
struct cifs_fid fid;
bool no_cached_open = tcon->nohandlecache; bool no_cached_open = tcon->nohandlecache;
struct cifsFileInfo *cfile; struct cifsFileInfo *cfile;
struct cached_fid *cfid = NULL;
*adjust_tz = false; *adjust_tz = false;
*symlink = false; *symlink = false;
...@@ -525,7 +525,7 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon, ...@@ -525,7 +525,7 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
/* If it is a root and its handle is cached then use it */ /* If it is a root and its handle is cached then use it */
if (!strlen(full_path) && !no_cached_open) { if (!strlen(full_path) && !no_cached_open) {
rc = open_shroot(xid, tcon, cifs_sb, &fid); rc = open_shroot(xid, tcon, cifs_sb, &cfid);
if (rc) if (rc)
goto out; goto out;
...@@ -533,12 +533,13 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon, ...@@ -533,12 +533,13 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
move_smb2_info_to_cifs(data, move_smb2_info_to_cifs(data,
&tcon->crfid.file_all_info); &tcon->crfid.file_all_info);
} else { } else {
rc = SMB2_query_info(xid, tcon, fid.persistent_fid, rc = SMB2_query_info(xid, tcon,
fid.volatile_fid, smb2_data); cfid->fid->persistent_fid,
cfid->fid->volatile_fid, smb2_data);
if (!rc) if (!rc)
move_smb2_info_to_cifs(data, smb2_data); move_smb2_info_to_cifs(data, smb2_data);
} }
close_shroot(&tcon->crfid); close_shroot(cfid);
goto out; goto out;
} }
......
...@@ -488,7 +488,7 @@ static const struct status_to_posix_error smb2_error_map_table[] = { ...@@ -488,7 +488,7 @@ static const struct status_to_posix_error smb2_error_map_table[] = {
{STATUS_PIPE_CONNECTED, -EIO, "STATUS_PIPE_CONNECTED"}, {STATUS_PIPE_CONNECTED, -EIO, "STATUS_PIPE_CONNECTED"},
{STATUS_PIPE_LISTENING, -EIO, "STATUS_PIPE_LISTENING"}, {STATUS_PIPE_LISTENING, -EIO, "STATUS_PIPE_LISTENING"},
{STATUS_INVALID_READ_MODE, -EIO, "STATUS_INVALID_READ_MODE"}, {STATUS_INVALID_READ_MODE, -EIO, "STATUS_INVALID_READ_MODE"},
{STATUS_IO_TIMEOUT, -ETIMEDOUT, "STATUS_IO_TIMEOUT"}, {STATUS_IO_TIMEOUT, -EAGAIN, "STATUS_IO_TIMEOUT"},
{STATUS_FILE_FORCED_CLOSED, -EIO, "STATUS_FILE_FORCED_CLOSED"}, {STATUS_FILE_FORCED_CLOSED, -EIO, "STATUS_FILE_FORCED_CLOSED"},
{STATUS_PROFILING_NOT_STARTED, -EIO, "STATUS_PROFILING_NOT_STARTED"}, {STATUS_PROFILING_NOT_STARTED, -EIO, "STATUS_PROFILING_NOT_STARTED"},
{STATUS_PROFILING_NOT_STOPPED, -EIO, "STATUS_PROFILING_NOT_STOPPED"}, {STATUS_PROFILING_NOT_STOPPED, -EIO, "STATUS_PROFILING_NOT_STOPPED"},
...@@ -814,7 +814,7 @@ static const struct status_to_posix_error smb2_error_map_table[] = { ...@@ -814,7 +814,7 @@ static const struct status_to_posix_error smb2_error_map_table[] = {
{STATUS_INVALID_VARIANT, -EIO, "STATUS_INVALID_VARIANT"}, {STATUS_INVALID_VARIANT, -EIO, "STATUS_INVALID_VARIANT"},
{STATUS_DOMAIN_CONTROLLER_NOT_FOUND, -EIO, {STATUS_DOMAIN_CONTROLLER_NOT_FOUND, -EIO,
"STATUS_DOMAIN_CONTROLLER_NOT_FOUND"}, "STATUS_DOMAIN_CONTROLLER_NOT_FOUND"},
{STATUS_ACCOUNT_LOCKED_OUT, -EIO, "STATUS_ACCOUNT_LOCKED_OUT"}, {STATUS_ACCOUNT_LOCKED_OUT, -EACCES, "STATUS_ACCOUNT_LOCKED_OUT"},
{STATUS_HANDLE_NOT_CLOSABLE, -EIO, "STATUS_HANDLE_NOT_CLOSABLE"}, {STATUS_HANDLE_NOT_CLOSABLE, -EIO, "STATUS_HANDLE_NOT_CLOSABLE"},
{STATUS_CONNECTION_REFUSED, -EIO, "STATUS_CONNECTION_REFUSED"}, {STATUS_CONNECTION_REFUSED, -EIO, "STATUS_CONNECTION_REFUSED"},
{STATUS_GRACEFUL_DISCONNECT, -EIO, "STATUS_GRACEFUL_DISCONNECT"}, {STATUS_GRACEFUL_DISCONNECT, -EIO, "STATUS_GRACEFUL_DISCONNECT"},
......
...@@ -72,7 +72,7 @@ smb2_add_credits(struct TCP_Server_Info *server, ...@@ -72,7 +72,7 @@ smb2_add_credits(struct TCP_Server_Info *server,
/* eg found case where write overlapping reconnect messed up credits */ /* eg found case where write overlapping reconnect messed up credits */
if (((optype & CIFS_OP_MASK) == CIFS_NEG_OP) && (*val != 0)) if (((optype & CIFS_OP_MASK) == CIFS_NEG_OP) && (*val != 0))
trace_smb3_reconnect_with_invalid_credits(server->CurrentMid, trace_smb3_reconnect_with_invalid_credits(server->CurrentMid,
server->hostname, *val); server->hostname, *val, add);
if ((instance == 0) || (instance == server->reconnect_instance)) if ((instance == 0) || (instance == server->reconnect_instance))
*val += add; *val += add;
else else
...@@ -121,6 +121,8 @@ smb2_add_credits(struct TCP_Server_Info *server, ...@@ -121,6 +121,8 @@ smb2_add_credits(struct TCP_Server_Info *server,
cifs_dbg(FYI, "disabling oplocks\n"); cifs_dbg(FYI, "disabling oplocks\n");
break; break;
default: default:
trace_smb3_add_credits(server->CurrentMid,
server->hostname, rc, add);
cifs_dbg(FYI, "add %u credits total=%d\n", add, rc); cifs_dbg(FYI, "add %u credits total=%d\n", add, rc);
} }
} }
...@@ -651,7 +653,8 @@ smb2_cached_lease_break(struct work_struct *work) ...@@ -651,7 +653,8 @@ smb2_cached_lease_break(struct work_struct *work)
* Open the directory at the root of a share * Open the directory at the root of a share
*/ */
int open_shroot(unsigned int xid, struct cifs_tcon *tcon, int open_shroot(unsigned int xid, struct cifs_tcon *tcon,
struct cifs_sb_info *cifs_sb, struct cifs_fid *pfid) struct cifs_sb_info *cifs_sb,
struct cached_fid **cfid)
{ {
struct cifs_ses *ses = tcon->ses; struct cifs_ses *ses = tcon->ses;
struct TCP_Server_Info *server = ses->server; struct TCP_Server_Info *server = ses->server;
...@@ -666,11 +669,12 @@ int open_shroot(unsigned int xid, struct cifs_tcon *tcon, ...@@ -666,11 +669,12 @@ int open_shroot(unsigned int xid, struct cifs_tcon *tcon,
int rc, flags = 0; int rc, flags = 0;
__le16 utf16_path = 0; /* Null - since an open of top of share */ __le16 utf16_path = 0; /* Null - since an open of top of share */
u8 oplock = SMB2_OPLOCK_LEVEL_II; u8 oplock = SMB2_OPLOCK_LEVEL_II;
struct cifs_fid *pfid;
mutex_lock(&tcon->crfid.fid_mutex); mutex_lock(&tcon->crfid.fid_mutex);
if (tcon->crfid.is_valid) { if (tcon->crfid.is_valid) {
cifs_dbg(FYI, "found a cached root file handle\n"); cifs_dbg(FYI, "found a cached root file handle\n");
memcpy(pfid, tcon->crfid.fid, sizeof(struct cifs_fid)); *cfid = &tcon->crfid;
kref_get(&tcon->crfid.refcount); kref_get(&tcon->crfid.refcount);
mutex_unlock(&tcon->crfid.fid_mutex); mutex_unlock(&tcon->crfid.fid_mutex);
return 0; return 0;
...@@ -691,6 +695,7 @@ int open_shroot(unsigned int xid, struct cifs_tcon *tcon, ...@@ -691,6 +695,7 @@ int open_shroot(unsigned int xid, struct cifs_tcon *tcon,
if (!server->ops->new_lease_key) if (!server->ops->new_lease_key)
return -EIO; return -EIO;
pfid = tcon->crfid.fid;
server->ops->new_lease_key(pfid); server->ops->new_lease_key(pfid);
memset(rqst, 0, sizeof(rqst)); memset(rqst, 0, sizeof(rqst));
...@@ -820,6 +825,8 @@ int open_shroot(unsigned int xid, struct cifs_tcon *tcon, ...@@ -820,6 +825,8 @@ int open_shroot(unsigned int xid, struct cifs_tcon *tcon,
SMB2_query_info_free(&rqst[1]); SMB2_query_info_free(&rqst[1]);
free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base); free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base); free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
if (rc == 0)
*cfid = &tcon->crfid;
return rc; return rc;
} }
...@@ -833,6 +840,7 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon, ...@@ -833,6 +840,7 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
struct cifs_open_parms oparms; struct cifs_open_parms oparms;
struct cifs_fid fid; struct cifs_fid fid;
bool no_cached_open = tcon->nohandlecache; bool no_cached_open = tcon->nohandlecache;
struct cached_fid *cfid = NULL;
oparms.tcon = tcon; oparms.tcon = tcon;
oparms.desired_access = FILE_READ_ATTRIBUTES; oparms.desired_access = FILE_READ_ATTRIBUTES;
...@@ -841,12 +849,14 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon, ...@@ -841,12 +849,14 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
oparms.fid = &fid; oparms.fid = &fid;
oparms.reconnect = false; oparms.reconnect = false;
if (no_cached_open) if (no_cached_open) {
rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL, rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
NULL, NULL); NULL, NULL);
else } else {
rc = open_shroot(xid, tcon, cifs_sb, &fid); rc = open_shroot(xid, tcon, cifs_sb, &cfid);
if (rc == 0)
memcpy(&fid, cfid->fid, sizeof(struct cifs_fid));
}
if (rc) if (rc)
return; return;
...@@ -863,7 +873,7 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon, ...@@ -863,7 +873,7 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
if (no_cached_open) if (no_cached_open)
SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
else else
close_shroot(&tcon->crfid); close_shroot(cfid);
} }
static void static void
...@@ -2346,6 +2356,17 @@ smb2_is_session_expired(char *buf) ...@@ -2346,6 +2356,17 @@ smb2_is_session_expired(char *buf)
return true; return true;
} }
static bool
smb2_is_status_io_timeout(char *buf)
{
struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
if (shdr->Status == STATUS_IO_TIMEOUT)
return true;
else
return false;
}
static int static int
smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid, smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
struct cifsInodeInfo *cinode) struct cifsInodeInfo *cinode)
...@@ -3072,7 +3093,12 @@ get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb, ...@@ -3072,7 +3093,12 @@ get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb,
oparms.tcon = tcon; oparms.tcon = tcon;
oparms.desired_access = READ_CONTROL; oparms.desired_access = READ_CONTROL;
oparms.disposition = FILE_OPEN; oparms.disposition = FILE_OPEN;
oparms.create_options = cifs_create_options(cifs_sb, 0); /*
* When querying an ACL, even if the file is a symlink we want to open
* the source not the target, and so the protocol requires that the
* client specify this flag when opening a reparse point
*/
oparms.create_options = cifs_create_options(cifs_sb, 0) | OPEN_REPARSE_POINT;
oparms.fid = &fid; oparms.fid = &fid;
oparms.reconnect = false; oparms.reconnect = false;
...@@ -3801,10 +3827,11 @@ fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len, ...@@ -3801,10 +3827,11 @@ fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len,
tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM; tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len); tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
tr_hdr->Flags = cpu_to_le16(0x01); tr_hdr->Flags = cpu_to_le16(0x01);
if (cipher_type == SMB2_ENCRYPTION_AES128_GCM) if ((cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
get_random_bytes(&tr_hdr->Nonce, SMB3_AES128GCM_NONCE); (cipher_type == SMB2_ENCRYPTION_AES256_GCM))
get_random_bytes(&tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
else else
get_random_bytes(&tr_hdr->Nonce, SMB3_AES128CCM_NONCE); get_random_bytes(&tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8); memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
} }
...@@ -3924,7 +3951,7 @@ crypt_message(struct TCP_Server_Info *server, int num_rqst, ...@@ -3924,7 +3951,7 @@ crypt_message(struct TCP_Server_Info *server, int num_rqst,
if (rc) { if (rc) {
cifs_server_dbg(VFS, "%s: Could not get %scryption key\n", __func__, cifs_server_dbg(VFS, "%s: Could not get %scryption key\n", __func__,
enc ? "en" : "de"); enc ? "en" : "de");
return 0; return rc;
} }
rc = smb3_crypto_aead_allocate(server); rc = smb3_crypto_aead_allocate(server);
...@@ -3935,7 +3962,12 @@ crypt_message(struct TCP_Server_Info *server, int num_rqst, ...@@ -3935,7 +3962,12 @@ crypt_message(struct TCP_Server_Info *server, int num_rqst,
tfm = enc ? server->secmech.ccmaesencrypt : tfm = enc ? server->secmech.ccmaesencrypt :
server->secmech.ccmaesdecrypt; server->secmech.ccmaesdecrypt;
rc = crypto_aead_setkey(tfm, key, SMB3_SIGN_KEY_SIZE);
if (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM)
rc = crypto_aead_setkey(tfm, key, SMB3_GCM256_CRYPTKEY_SIZE);
else
rc = crypto_aead_setkey(tfm, key, SMB3_SIGN_KEY_SIZE);
if (rc) { if (rc) {
cifs_server_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc); cifs_server_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
return rc; return rc;
...@@ -3973,11 +4005,12 @@ crypt_message(struct TCP_Server_Info *server, int num_rqst, ...@@ -3973,11 +4005,12 @@ crypt_message(struct TCP_Server_Info *server, int num_rqst,
goto free_sg; goto free_sg;
} }
if (server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
memcpy(iv, (char *)tr_hdr->Nonce, SMB3_AES128GCM_NONCE); (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
memcpy(iv, (char *)tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
else { else {
iv[0] = 3; iv[0] = 3;
memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES128CCM_NONCE); memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
} }
aead_request_set_crypt(req, sg, sg, crypt_len, iv); aead_request_set_crypt(req, sg, sg, crypt_len, iv);
...@@ -4103,7 +4136,8 @@ smb3_is_transform_hdr(void *buf) ...@@ -4103,7 +4136,8 @@ smb3_is_transform_hdr(void *buf)
static int static int
decrypt_raw_data(struct TCP_Server_Info *server, char *buf, decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
unsigned int buf_data_size, struct page **pages, unsigned int buf_data_size, struct page **pages,
unsigned int npages, unsigned int page_data_size) unsigned int npages, unsigned int page_data_size,
bool is_offloaded)
{ {
struct kvec iov[2]; struct kvec iov[2];
struct smb_rqst rqst = {NULL}; struct smb_rqst rqst = {NULL};
...@@ -4129,7 +4163,8 @@ decrypt_raw_data(struct TCP_Server_Info *server, char *buf, ...@@ -4129,7 +4163,8 @@ decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
memmove(buf, iov[1].iov_base, buf_data_size); memmove(buf, iov[1].iov_base, buf_data_size);
server->total_read = buf_data_size + page_data_size; if (!is_offloaded)
server->total_read = buf_data_size + page_data_size;
return rc; return rc;
} }
...@@ -4342,7 +4377,7 @@ static void smb2_decrypt_offload(struct work_struct *work) ...@@ -4342,7 +4377,7 @@ static void smb2_decrypt_offload(struct work_struct *work)
struct mid_q_entry *mid; struct mid_q_entry *mid;
rc = decrypt_raw_data(dw->server, dw->buf, dw->server->vals->read_rsp_size, rc = decrypt_raw_data(dw->server, dw->buf, dw->server->vals->read_rsp_size,
dw->ppages, dw->npages, dw->len); dw->ppages, dw->npages, dw->len, true);
if (rc) { if (rc) {
cifs_dbg(VFS, "error decrypting rc=%d\n", rc); cifs_dbg(VFS, "error decrypting rc=%d\n", rc);
goto free_pages; goto free_pages;
...@@ -4448,7 +4483,7 @@ receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid, ...@@ -4448,7 +4483,7 @@ receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid,
non_offloaded_decrypt: non_offloaded_decrypt:
rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size, rc = decrypt_raw_data(server, buf, server->vals->read_rsp_size,
pages, npages, len); pages, npages, len, false);
if (rc) if (rc)
goto free_pages; goto free_pages;
...@@ -4504,7 +4539,7 @@ receive_encrypted_standard(struct TCP_Server_Info *server, ...@@ -4504,7 +4539,7 @@ receive_encrypted_standard(struct TCP_Server_Info *server,
server->total_read += length; server->total_read += length;
buf_size = pdu_length - sizeof(struct smb2_transform_hdr); buf_size = pdu_length - sizeof(struct smb2_transform_hdr);
length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0); length = decrypt_raw_data(server, buf, buf_size, NULL, 0, 0, false);
if (length) if (length)
return length; return length;
...@@ -4809,6 +4844,7 @@ struct smb_version_operations smb20_operations = { ...@@ -4809,6 +4844,7 @@ struct smb_version_operations smb20_operations = {
.make_node = smb2_make_node, .make_node = smb2_make_node,
.fiemap = smb3_fiemap, .fiemap = smb3_fiemap,
.llseek = smb3_llseek, .llseek = smb3_llseek,
.is_status_io_timeout = smb2_is_status_io_timeout,
}; };
struct smb_version_operations smb21_operations = { struct smb_version_operations smb21_operations = {
...@@ -4909,6 +4945,7 @@ struct smb_version_operations smb21_operations = { ...@@ -4909,6 +4945,7 @@ struct smb_version_operations smb21_operations = {
.make_node = smb2_make_node, .make_node = smb2_make_node,
.fiemap = smb3_fiemap, .fiemap = smb3_fiemap,
.llseek = smb3_llseek, .llseek = smb3_llseek,
.is_status_io_timeout = smb2_is_status_io_timeout,
}; };
struct smb_version_operations smb30_operations = { struct smb_version_operations smb30_operations = {
...@@ -5019,6 +5056,7 @@ struct smb_version_operations smb30_operations = { ...@@ -5019,6 +5056,7 @@ struct smb_version_operations smb30_operations = {
.make_node = smb2_make_node, .make_node = smb2_make_node,
.fiemap = smb3_fiemap, .fiemap = smb3_fiemap,
.llseek = smb3_llseek, .llseek = smb3_llseek,
.is_status_io_timeout = smb2_is_status_io_timeout,
}; };
struct smb_version_operations smb311_operations = { struct smb_version_operations smb311_operations = {
...@@ -5130,6 +5168,7 @@ struct smb_version_operations smb311_operations = { ...@@ -5130,6 +5168,7 @@ struct smb_version_operations smb311_operations = {
.make_node = smb2_make_node, .make_node = smb2_make_node,
.fiemap = smb3_fiemap, .fiemap = smb3_fiemap,
.llseek = smb3_llseek, .llseek = smb3_llseek,
.is_status_io_timeout = smb2_is_status_io_timeout,
}; };
struct smb_version_values smb20_values = { struct smb_version_values smb20_values = {
......
...@@ -449,10 +449,22 @@ static void ...@@ -449,10 +449,22 @@ static void
build_encrypt_ctxt(struct smb2_encryption_neg_context *pneg_ctxt) build_encrypt_ctxt(struct smb2_encryption_neg_context *pneg_ctxt)
{ {
pneg_ctxt->ContextType = SMB2_ENCRYPTION_CAPABILITIES; pneg_ctxt->ContextType = SMB2_ENCRYPTION_CAPABILITIES;
pneg_ctxt->DataLength = cpu_to_le16(6); /* Cipher Count + two ciphers */ if (require_gcm_256) {
pneg_ctxt->CipherCount = cpu_to_le16(2); pneg_ctxt->DataLength = cpu_to_le16(4); /* Cipher Count + 1 cipher */
pneg_ctxt->Ciphers[0] = SMB2_ENCRYPTION_AES128_GCM; pneg_ctxt->CipherCount = cpu_to_le16(1);
pneg_ctxt->Ciphers[1] = SMB2_ENCRYPTION_AES128_CCM; pneg_ctxt->Ciphers[0] = SMB2_ENCRYPTION_AES256_GCM;
} else if (enable_gcm_256) {
pneg_ctxt->DataLength = cpu_to_le16(8); /* Cipher Count + 3 ciphers */
pneg_ctxt->CipherCount = cpu_to_le16(3);
pneg_ctxt->Ciphers[0] = SMB2_ENCRYPTION_AES128_GCM;
pneg_ctxt->Ciphers[1] = SMB2_ENCRYPTION_AES256_GCM;
pneg_ctxt->Ciphers[2] = SMB2_ENCRYPTION_AES128_CCM;
} else {
pneg_ctxt->DataLength = cpu_to_le16(6); /* Cipher Count + 2 ciphers */
pneg_ctxt->CipherCount = cpu_to_le16(2);
pneg_ctxt->Ciphers[0] = SMB2_ENCRYPTION_AES128_GCM;
pneg_ctxt->Ciphers[1] = SMB2_ENCRYPTION_AES128_CCM;
}
} }
static unsigned int static unsigned int
...@@ -598,8 +610,29 @@ static int decode_encrypt_ctx(struct TCP_Server_Info *server, ...@@ -598,8 +610,29 @@ static int decode_encrypt_ctx(struct TCP_Server_Info *server,
return -EINVAL; return -EINVAL;
} }
cifs_dbg(FYI, "SMB311 cipher type:%d\n", le16_to_cpu(ctxt->Ciphers[0])); cifs_dbg(FYI, "SMB311 cipher type:%d\n", le16_to_cpu(ctxt->Ciphers[0]));
if ((ctxt->Ciphers[0] != SMB2_ENCRYPTION_AES128_CCM) && if (require_gcm_256) {
(ctxt->Ciphers[0] != SMB2_ENCRYPTION_AES128_GCM)) { if (ctxt->Ciphers[0] != SMB2_ENCRYPTION_AES256_GCM) {
cifs_dbg(VFS, "Server does not support requested encryption type (AES256 GCM)\n");
return -EOPNOTSUPP;
}
} else if (ctxt->Ciphers[0] == 0) {
/*
* e.g. if server only supported AES256_CCM (very unlikely)
* or server supported no encryption types or had all disabled.
* Since GLOBAL_CAP_ENCRYPTION will be not set, in the case
* in which mount requested encryption ("seal") checks later
* on during tree connection will return proper rc, but if
* seal not requested by client, since server is allowed to
* return 0 to indicate no supported cipher, we can't fail here
*/
server->cipher_type = 0;
server->capabilities &= ~SMB2_GLOBAL_CAP_ENCRYPTION;
pr_warn_once("Server does not support requested encryption types\n");
return 0;
} else if ((ctxt->Ciphers[0] != SMB2_ENCRYPTION_AES128_CCM) &&
(ctxt->Ciphers[0] != SMB2_ENCRYPTION_AES128_GCM) &&
(ctxt->Ciphers[0] != SMB2_ENCRYPTION_AES256_GCM)) {
/* server returned a cipher we didn't ask for */
pr_warn_once("Invalid SMB3.11 cipher returned\n"); pr_warn_once("Invalid SMB3.11 cipher returned\n");
return -EINVAL; return -EINVAL;
} }
...@@ -1948,9 +1981,11 @@ smb2_parse_contexts(struct TCP_Server_Info *server, ...@@ -1948,9 +1981,11 @@ smb2_parse_contexts(struct TCP_Server_Info *server,
unsigned int next; unsigned int next;
unsigned int remaining; unsigned int remaining;
char *name; char *name;
const char smb3_create_tag_posix[] = {0x93, 0xAD, 0x25, 0x50, 0x9C, static const char smb3_create_tag_posix[] = {
0xB4, 0x11, 0xE7, 0xB4, 0x23, 0x83, 0x93, 0xAD, 0x25, 0x50, 0x9C,
0xDE, 0x96, 0x8B, 0xCD, 0x7C}; 0xB4, 0x11, 0xE7, 0xB4, 0x23, 0x83,
0xDE, 0x96, 0x8B, 0xCD, 0x7C
};
*oplock = 0; *oplock = 0;
data_offset = (char *)rsp + le32_to_cpu(rsp->CreateContextsOffset); data_offset = (char *)rsp + le32_to_cpu(rsp->CreateContextsOffset);
......
...@@ -128,8 +128,8 @@ struct smb2_sync_pdu { ...@@ -128,8 +128,8 @@ struct smb2_sync_pdu {
__le16 StructureSize2; /* size of wct area (varies, request specific) */ __le16 StructureSize2; /* size of wct area (varies, request specific) */
} __packed; } __packed;
#define SMB3_AES128CCM_NONCE 11 #define SMB3_AES_CCM_NONCE 11
#define SMB3_AES128GCM_NONCE 12 #define SMB3_AES_GCM_NONCE 12
/* Transform flags (for 3.0 dialect this flag indicates CCM */ /* Transform flags (for 3.0 dialect this flag indicates CCM */
#define TRANSFORM_FLAG_ENCRYPTED 0x0001 #define TRANSFORM_FLAG_ENCRYPTED 0x0001
...@@ -153,10 +153,14 @@ struct smb2_compression_transform_hdr { ...@@ -153,10 +153,14 @@ struct smb2_compression_transform_hdr {
} __packed; } __packed;
/* See MS-SMB2 2.2.42.1 */ /* See MS-SMB2 2.2.42.1 */
#define SMB2_COMPRESSION_FLAG_NONE 0x0000
#define SMB2_COMPRESSION_FLAG_CHAINED 0x0001
struct compression_payload_header { struct compression_payload_header {
__le16 AlgorithmId; __le16 CompressionAlgorithm;
__le16 Reserved; __le16 Flags;
__le32 Length; __le32 Length; /* length of compressed playload including field below if present */
/* __le32 OriginalPayloadSize; */ /* optional */
} __packed; } __packed;
/* See MS-SMB2 2.2.42.2 */ /* See MS-SMB2 2.2.42.2 */
...@@ -167,6 +171,26 @@ struct compression_pattern_payload_v1 { ...@@ -167,6 +171,26 @@ struct compression_pattern_payload_v1 {
__le32 Repetitions; __le32 Repetitions;
} __packed; } __packed;
/* See MS-SMB2 2.2.43 */
struct smb2_rdma_transform {
__le16 RdmaDescriptorOffset;
__le16 RdmaDescriptorLength;
__le32 Channel; /* for values see channel description in smb2 read above */
__le16 TransformCount;
__le16 Reserved1;
__le32 Reserved2;
} __packed;
struct smb2_rdma_encryption_transform {
__le16 TransformType;
__le16 SignatureLength;
__le16 NonceLength;
__u16 Reserved;
__u8 Signature[]; /* variable length */
/* u8 Nonce[] */
/* followed by padding */
} __packed;
/* /*
* SMB2 flag definitions * SMB2 flag definitions
*/ */
...@@ -297,6 +321,9 @@ struct smb2_negotiate_req { ...@@ -297,6 +321,9 @@ struct smb2_negotiate_req {
#define SMB2_ENCRYPTION_CAPABILITIES cpu_to_le16(2) #define SMB2_ENCRYPTION_CAPABILITIES cpu_to_le16(2)
#define SMB2_COMPRESSION_CAPABILITIES cpu_to_le16(3) #define SMB2_COMPRESSION_CAPABILITIES cpu_to_le16(3)
#define SMB2_NETNAME_NEGOTIATE_CONTEXT_ID cpu_to_le16(5) #define SMB2_NETNAME_NEGOTIATE_CONTEXT_ID cpu_to_le16(5)
#define SMB2_TRANSPORT_CAPABILITIES cpu_to_le16(6)
#define SMB2_RDMA_TRANSFORM_CAPABILITIES cpu_to_le16(7)
#define SMB2_SIGNING_CAPABILITIES cpu_to_le16(8)
#define SMB2_POSIX_EXTENSIONS_AVAILABLE cpu_to_le16(0x100) #define SMB2_POSIX_EXTENSIONS_AVAILABLE cpu_to_le16(0x100)
struct smb2_neg_context { struct smb2_neg_context {
...@@ -325,6 +352,9 @@ struct smb2_preauth_neg_context { ...@@ -325,6 +352,9 @@ struct smb2_preauth_neg_context {
/* Encryption Algorithms Ciphers */ /* Encryption Algorithms Ciphers */
#define SMB2_ENCRYPTION_AES128_CCM cpu_to_le16(0x0001) #define SMB2_ENCRYPTION_AES128_CCM cpu_to_le16(0x0001)
#define SMB2_ENCRYPTION_AES128_GCM cpu_to_le16(0x0002) #define SMB2_ENCRYPTION_AES128_GCM cpu_to_le16(0x0002)
/* we currently do not request AES256_CCM since presumably GCM faster */
#define SMB2_ENCRYPTION_AES256_CCM cpu_to_le16(0x0003)
#define SMB2_ENCRYPTION_AES256_GCM cpu_to_le16(0x0004)
/* Min encrypt context data is one cipher so 2 bytes + 2 byte count field */ /* Min encrypt context data is one cipher so 2 bytes + 2 byte count field */
#define MIN_ENCRYPT_CTXT_DATA_LEN 4 #define MIN_ENCRYPT_CTXT_DATA_LEN 4
...@@ -332,8 +362,9 @@ struct smb2_encryption_neg_context { ...@@ -332,8 +362,9 @@ struct smb2_encryption_neg_context {
__le16 ContextType; /* 2 */ __le16 ContextType; /* 2 */
__le16 DataLength; __le16 DataLength;
__le32 Reserved; __le32 Reserved;
__le16 CipherCount; /* AES-128-GCM and AES-128-CCM */ /* CipherCount usally 2, but can be 3 when AES256-GCM enabled */
__le16 Ciphers[2]; __le16 CipherCount; /* AES128-GCM and AES128-CCM by default */
__le16 Ciphers[3];
} __packed; } __packed;
/* See MS-SMB2 2.2.3.1.3 */ /* See MS-SMB2 2.2.3.1.3 */
...@@ -351,10 +382,10 @@ struct smb2_encryption_neg_context { ...@@ -351,10 +382,10 @@ struct smb2_encryption_neg_context {
struct smb2_compression_capabilities_context { struct smb2_compression_capabilities_context {
__le16 ContextType; /* 3 */ __le16 ContextType; /* 3 */
__le16 DataLength; __le16 DataLength;
__u32 Flags; __u32 Reserved;
__le16 CompressionAlgorithmCount; __le16 CompressionAlgorithmCount;
__u16 Padding; __u16 Padding;
__u32 Reserved1; __u32 Flags;
__le16 CompressionAlgorithms[3]; __le16 CompressionAlgorithms[3];
} __packed; } __packed;
...@@ -363,12 +394,44 @@ struct smb2_compression_capabilities_context { ...@@ -363,12 +394,44 @@ struct smb2_compression_capabilities_context {
* Its struct simply contains NetName, an array of Unicode characters * Its struct simply contains NetName, an array of Unicode characters
*/ */
struct smb2_netname_neg_context { struct smb2_netname_neg_context {
__le16 ContextType; /* 0x100 */ __le16 ContextType; /* 5 */
__le16 DataLength; __le16 DataLength;
__le32 Reserved; __le32 Reserved;
__le16 NetName[]; /* hostname of target converted to UCS-2 */ __le16 NetName[]; /* hostname of target converted to UCS-2 */
} __packed; } __packed;
/*
* For rdma transform capabilities context see MS-SMB2 2.2.3.1.6
* and 2.2.4.1.5
*/
/* RDMA Transform IDs */
#define SMB2_RDMA_TRANSFORM_NONE 0x0000
#define SMB2_RDMA_TRANSFORM_ENCRYPTION 0x0001
struct smb2_rdma_transform_capabilities_context {
__le16 ContextType; /* 7 */
__le16 DataLength;
__u32 Reserved;
__le16 TransformCount;
__u16 Reserved1;
__u32 Reserved2;
__le16 RDMATransformIds[1];
} __packed;
/* Signing algorithms */
#define SIGNING_ALG_HMAC_SHA256 0
#define SIGNING_ALG_AES_CMAC 1
#define SIGNING_ALG_AES_GMAC 2
struct smb2_signing_capabilities {
__le16 ContextType; /* 8 */
__le16 DataLength;
__u32 Reserved;
__le16 SigningAlgorithmCount;
__le16 SigningAlgorithms[];
} __packed;
#define POSIX_CTXT_DATA_LEN 16 #define POSIX_CTXT_DATA_LEN 16
struct smb2_posix_neg_context { struct smb2_posix_neg_context {
__le16 ContextType; /* 0x100 */ __le16 ContextType; /* 0x100 */
...@@ -1178,6 +1241,7 @@ struct smb2_flush_rsp { ...@@ -1178,6 +1241,7 @@ struct smb2_flush_rsp {
#define SMB2_CHANNEL_NONE cpu_to_le32(0x00000000) #define SMB2_CHANNEL_NONE cpu_to_le32(0x00000000)
#define SMB2_CHANNEL_RDMA_V1 cpu_to_le32(0x00000001) /* SMB3 or later */ #define SMB2_CHANNEL_RDMA_V1 cpu_to_le32(0x00000001) /* SMB3 or later */
#define SMB2_CHANNEL_RDMA_V1_INVALIDATE cpu_to_le32(0x00000002) /* >= SMB3.02 */ #define SMB2_CHANNEL_RDMA_V1_INVALIDATE cpu_to_le32(0x00000002) /* >= SMB3.02 */
#define SMB2_CHANNEL_RDMA_TRANSFORM cpu_to_le32(0x00000003) /* >= SMB3.02, only used on write */
/* SMB2 read request without RFC1001 length at the beginning */ /* SMB2 read request without RFC1001 length at the beginning */
struct smb2_read_plain_req { struct smb2_read_plain_req {
...@@ -1197,6 +1261,10 @@ struct smb2_read_plain_req { ...@@ -1197,6 +1261,10 @@ struct smb2_read_plain_req {
__u8 Buffer[1]; __u8 Buffer[1];
} __packed; } __packed;
/* Read flags */
#define SMB2_READFLAG_RESPONSE_NONE 0x00000000
#define SMB2_READFLAG_RESPONSE_RDMA_TRANSFORM 0x00000001
struct smb2_read_rsp { struct smb2_read_rsp {
struct smb2_sync_hdr sync_hdr; struct smb2_sync_hdr sync_hdr;
__le16 StructureSize; /* Must be 17 */ __le16 StructureSize; /* Must be 17 */
...@@ -1204,7 +1272,7 @@ struct smb2_read_rsp { ...@@ -1204,7 +1272,7 @@ struct smb2_read_rsp {
__u8 Reserved; __u8 Reserved;
__le32 DataLength; __le32 DataLength;
__le32 DataRemaining; __le32 DataRemaining;
__u32 Reserved2; __u32 Flags;
__u8 Buffer[1]; __u8 Buffer[1];
} __packed; } __packed;
......
...@@ -70,7 +70,8 @@ extern int smb3_handle_read_data(struct TCP_Server_Info *server, ...@@ -70,7 +70,8 @@ extern int smb3_handle_read_data(struct TCP_Server_Info *server,
struct mid_q_entry *mid); struct mid_q_entry *mid);
extern int open_shroot(unsigned int xid, struct cifs_tcon *tcon, extern int open_shroot(unsigned int xid, struct cifs_tcon *tcon,
struct cifs_sb_info *cifs_sb, struct cifs_fid *pfid); struct cifs_sb_info *cifs_sb,
struct cached_fid **cfid);
extern void close_shroot(struct cached_fid *cfid); extern void close_shroot(struct cached_fid *cfid);
extern void close_shroot_lease(struct cached_fid *cfid); extern void close_shroot_lease(struct cached_fid *cfid);
extern void close_shroot_lease_locked(struct cached_fid *cfid); extern void close_shroot_lease_locked(struct cached_fid *cfid);
......
...@@ -849,12 +849,13 @@ smb3_crypto_aead_allocate(struct TCP_Server_Info *server) ...@@ -849,12 +849,13 @@ smb3_crypto_aead_allocate(struct TCP_Server_Info *server)
struct crypto_aead *tfm; struct crypto_aead *tfm;
if (!server->secmech.ccmaesencrypt) { if (!server->secmech.ccmaesencrypt) {
if (server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
(server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
tfm = crypto_alloc_aead("gcm(aes)", 0, 0); tfm = crypto_alloc_aead("gcm(aes)", 0, 0);
else else
tfm = crypto_alloc_aead("ccm(aes)", 0, 0); tfm = crypto_alloc_aead("ccm(aes)", 0, 0);
if (IS_ERR(tfm)) { if (IS_ERR(tfm)) {
cifs_server_dbg(VFS, "%s: Failed to alloc encrypt aead\n", cifs_server_dbg(VFS, "%s: Failed alloc encrypt aead\n",
__func__); __func__);
return PTR_ERR(tfm); return PTR_ERR(tfm);
} }
...@@ -862,7 +863,8 @@ smb3_crypto_aead_allocate(struct TCP_Server_Info *server) ...@@ -862,7 +863,8 @@ smb3_crypto_aead_allocate(struct TCP_Server_Info *server)
} }
if (!server->secmech.ccmaesdecrypt) { if (!server->secmech.ccmaesdecrypt) {
if (server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
(server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
tfm = crypto_alloc_aead("gcm(aes)", 0, 0); tfm = crypto_alloc_aead("gcm(aes)", 0, 0);
else else
tfm = crypto_alloc_aead("ccm(aes)", 0, 0); tfm = crypto_alloc_aead("ccm(aes)", 0, 0);
......
...@@ -878,33 +878,39 @@ DEFINE_SMB3_RECONNECT_EVENT(partial_send_reconnect); ...@@ -878,33 +878,39 @@ DEFINE_SMB3_RECONNECT_EVENT(partial_send_reconnect);
DECLARE_EVENT_CLASS(smb3_credit_class, DECLARE_EVENT_CLASS(smb3_credit_class,
TP_PROTO(__u64 currmid, TP_PROTO(__u64 currmid,
char *hostname, char *hostname,
int credits), int credits,
TP_ARGS(currmid, hostname, credits), int credits_to_add),
TP_ARGS(currmid, hostname, credits, credits_to_add),
TP_STRUCT__entry( TP_STRUCT__entry(
__field(__u64, currmid) __field(__u64, currmid)
__field(char *, hostname) __field(char *, hostname)
__field(int, credits) __field(int, credits)
__field(int, credits_to_add)
), ),
TP_fast_assign( TP_fast_assign(
__entry->currmid = currmid; __entry->currmid = currmid;
__entry->hostname = hostname; __entry->hostname = hostname;
__entry->credits = credits; __entry->credits = credits;
__entry->credits_to_add = credits_to_add;
), ),
TP_printk("server=%s current_mid=0x%llx credits=%d", TP_printk("server=%s current_mid=0x%llx credits=%d credits_to_add=%d",
__entry->hostname, __entry->hostname,
__entry->currmid, __entry->currmid,
__entry->credits) __entry->credits,
__entry->credits_to_add)
) )
#define DEFINE_SMB3_CREDIT_EVENT(name) \ #define DEFINE_SMB3_CREDIT_EVENT(name) \
DEFINE_EVENT(smb3_credit_class, smb3_##name, \ DEFINE_EVENT(smb3_credit_class, smb3_##name, \
TP_PROTO(__u64 currmid, \ TP_PROTO(__u64 currmid, \
char *hostname, \ char *hostname, \
int credits), \ int credits, \
TP_ARGS(currmid, hostname, credits)) int credits_to_add), \
TP_ARGS(currmid, hostname, credits, credits_to_add))
DEFINE_SMB3_CREDIT_EVENT(reconnect_with_invalid_credits); DEFINE_SMB3_CREDIT_EVENT(reconnect_with_invalid_credits);
DEFINE_SMB3_CREDIT_EVENT(credit_timeout); DEFINE_SMB3_CREDIT_EVENT(credit_timeout);
DEFINE_SMB3_CREDIT_EVENT(add_credits);
#endif /* _CIFS_TRACE_H */ #endif /* _CIFS_TRACE_H */
......
...@@ -563,7 +563,7 @@ wait_for_free_credits(struct TCP_Server_Info *server, const int num_credits, ...@@ -563,7 +563,7 @@ wait_for_free_credits(struct TCP_Server_Info *server, const int num_credits,
cifs_num_waiters_dec(server); cifs_num_waiters_dec(server);
if (!rc) { if (!rc) {
trace_smb3_credit_timeout(server->CurrentMid, trace_smb3_credit_timeout(server->CurrentMid,
server->hostname, num_credits); server->hostname, num_credits, 0);
cifs_server_dbg(VFS, "wait timed out after %d ms\n", cifs_server_dbg(VFS, "wait timed out after %d ms\n",
timeout); timeout);
return -ENOTSUPP; return -ENOTSUPP;
...@@ -604,7 +604,8 @@ wait_for_free_credits(struct TCP_Server_Info *server, const int num_credits, ...@@ -604,7 +604,8 @@ wait_for_free_credits(struct TCP_Server_Info *server, const int num_credits,
if (!rc) { if (!rc) {
trace_smb3_credit_timeout( trace_smb3_credit_timeout(
server->CurrentMid, server->CurrentMid,
server->hostname, num_credits); server->hostname, num_credits,
0);
cifs_server_dbg(VFS, "wait timed out after %d ms\n", cifs_server_dbg(VFS, "wait timed out after %d ms\n",
timeout); timeout);
return -ENOTSUPP; return -ENOTSUPP;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment