diff options
-rw-r--r-- | fs/cifs/Kconfig | 83 | ||||
-rw-r--r-- | fs/cifs/Makefile | 7 | ||||
-rw-r--r-- | fs/cifs/cifs_unicode.c | 2 | ||||
-rw-r--r-- | fs/cifs/cifs_unicode.h | 2 | ||||
-rw-r--r-- | fs/cifs/cifsfs.c | 13 | ||||
-rw-r--r-- | fs/cifs/cifsglob.h | 20 | ||||
-rw-r--r-- | fs/cifs/cifssmb.c | 7 | ||||
-rw-r--r-- | fs/cifs/connect.c | 41 | ||||
-rw-r--r-- | fs/cifs/ioctl.c | 2 | ||||
-rw-r--r-- | fs/cifs/link.c | 4 | ||||
-rw-r--r-- | fs/cifs/misc.c | 11 | ||||
-rw-r--r-- | fs/cifs/smb2maperror.c | 4 | ||||
-rw-r--r-- | fs/cifs/smb2ops.c | 86 | ||||
-rw-r--r-- | fs/cifs/smb2pdu.c | 74 | ||||
-rw-r--r-- | fs/cifs/smb2proto.h | 3 |
15 files changed, 180 insertions, 179 deletions
diff --git a/fs/cifs/Kconfig b/fs/cifs/Kconfig index afeefe79c25e..f7243617316c 100644 --- a/fs/cifs/Kconfig +++ b/fs/cifs/Kconfig @@ -1,5 +1,5 @@ config CIFS - tristate "CIFS support (advanced network filesystem, SMBFS successor)" + tristate "SMB3 and CIFS support (advanced network filesystem)" depends on INET select NLS select CRYPTO @@ -10,28 +10,35 @@ config CIFS select CRYPTO_ECB select CRYPTO_DES help - This is the client VFS module for the Common Internet File System - (CIFS) protocol which is the successor to the Server Message Block - (SMB) protocol, the native file sharing mechanism for most early - PC operating systems. The CIFS protocol is fully supported by - file servers such as Windows 2000 (including Windows 2003, Windows 2008, - NT 4 and Windows XP) as well by Samba (which provides excellent CIFS + This is the client VFS module for the SMB3 family of NAS protocols, + as well as for earlier dialects such as SMB2.1, SMB2 and the + Common Internet File System (CIFS) protocol. CIFS was the successor + to the original dialect, the Server Message Block (SMB) protocol, the + native file sharing mechanism for most early PC operating systems. + + The SMB3 protocol is supported by most modern operating systems and + NAS appliances (e.g. Samba, Windows 8, Windows 2012, MacOS). + The older CIFS protocol was included in Windows NT4, 2000 and XP (and + later) as well by Samba (which provides excellent CIFS and SMB3 server support for Linux and many other operating systems). Limited - support for OS/2 and Windows ME and similar servers is provided as - well. + support for OS/2 and Windows ME and similar very old servers is + provided as well. - The module also provides optional support for the followon - protocols for CIFS including SMB3, which enables - useful performance and security features (see the description - of CONFIG_CIFS_SMB2). - - The cifs module provides an advanced network file system - client for mounting to CIFS compliant servers. It includes + The cifs module provides an advanced network file system client + for mounting to SMB3 (and CIFS) compliant servers. It includes support for DFS (hierarchical name space), secure per-user session establishment via Kerberos or NTLM or NTLMv2, safe distributed caching (oplock), optional packet signing, Unicode and other internationalization improvements. - If you need to mount to Samba or Windows from this machine, say Y. + + In general, the default dialects, SMB3 and later, enable better + performance, security and features, than would be possible with CIFS. + Note that when mounting to Samba, due to the CIFS POSIX extensions, + CIFS mounts can provide slightly better POSIX compatibility + than SMB3 mounts. SMB2/SMB3 mount options are also + slightly simpler (compared to CIFS) due to protocol improvements. + + If you need to mount to Samba, Macs or Windows from this machine, say Y. config CIFS_STATS bool "CIFS statistics" @@ -89,7 +96,7 @@ config CIFS_UPCALL Enables an upcall mechanism for CIFS which accesses userspace helper utilities to provide SPNEGO packaged (RFC 4178) Kerberos tickets which are needed to mount to certain secure servers (for which more - secure Kerberos authentication is required). If unsure, say N. + secure Kerberos authentication is required). If unsure, say Y. config CIFS_XATTR bool "CIFS extended attributes" @@ -105,7 +112,7 @@ config CIFS_XATTR (used by some filesystems to store ACLs) is not supported at this time. - If unsure, say N. + If unsure, say Y. config CIFS_POSIX bool "CIFS POSIX Extensions" @@ -125,7 +132,7 @@ config CIFS_ACL help Allows fetching CIFS/NTFS ACL from the server. The DACL blob is handed over to the application/caller. See the man - page for getcifsacl for more information. + page for getcifsacl for more information. If unsure, say Y. config CIFS_DEBUG bool "Enable CIFS debugging routines" @@ -148,12 +155,13 @@ config CIFS_DEBUG2 config CIFS_DEBUG_DUMP_KEYS bool "Dump encryption keys for offline decryption (Unsafe)" - depends on CIFS_DEBUG && CIFS_SMB2 + depends on CIFS_DEBUG help Enabling this will dump the encryption and decryption keys used to communicate on an encrypted share connection on the console. This allows Wireshark to decrypt and dissect encrypted network captures. Enable this carefully. + If unsure, say N. config CIFS_DFS_UPCALL bool "DFS feature support" @@ -166,7 +174,7 @@ config CIFS_DFS_UPCALL an upcall mechanism for CIFS which contacts userspace helper utilities to provide server name resolution (host names to IP addresses) which is needed for implicit mounts of DFS junction - points. If unsure, say N. + points. If unsure, say Y. config CIFS_NFSD_EXPORT bool "Allow nfsd to export CIFS file system" @@ -174,38 +182,9 @@ config CIFS_NFSD_EXPORT help Allows NFS server to export a CIFS mounted share (nfsd over cifs) -config CIFS_SMB2 - bool "SMB2 and SMB3 network file system support" - depends on CIFS - select KEYS - select FSCACHE - select DNS_RESOLVER - select CRYPTO_AES - select CRYPTO_SHA256 - select CRYPTO_CMAC - select CRYPTO_AEAD2 - select CRYPTO_CCM - - help - This enables support for the Server Message Block version 2 - family of protocols, including SMB3. SMB3 support is - enabled on mount by specifying "vers=3.0" in the mount - options. These protocols are the successors to the popular - CIFS and SMB network file sharing protocols. SMB3 is the - native file sharing mechanism for the more recent - versions of Windows (Windows 8 and Windows 2012 and - later) and Samba server and many others support SMB3 well. - In general SMB3 enables better performance, security - and features, than would be possible with CIFS (Note that - when mounting to Samba, due to the CIFS POSIX extensions, - CIFS mounts can provide slightly better POSIX compatibility - than SMB3 mounts do though). Note that SMB2/SMB3 mount - options are also slightly simpler (compared to CIFS) due - to protocol improvements. - config CIFS_SMB311 bool "SMB3.1.1 network file system support (Experimental)" - depends on CIFS_SMB2 + depends on CIFS help This enables experimental support for the newest, SMB3.1.1, dialect. diff --git a/fs/cifs/Makefile b/fs/cifs/Makefile index eed7eb09f46f..5e853a395b92 100644 --- a/fs/cifs/Makefile +++ b/fs/cifs/Makefile @@ -6,7 +6,9 @@ obj-$(CONFIG_CIFS) += cifs.o cifs-y := cifsfs.o cifssmb.o cifs_debug.o connect.o dir.o file.o inode.o \ link.o misc.o netmisc.o smbencrypt.o transport.o asn1.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 \ + smb2misc.o smb2pdu.o smb2inode.o smb2file.o cifs-$(CONFIG_CIFS_XATTR) += xattr.o cifs-$(CONFIG_CIFS_ACL) += cifsacl.o @@ -16,6 +18,3 @@ cifs-$(CONFIG_CIFS_UPCALL) += cifs_spnego.o cifs-$(CONFIG_CIFS_DFS_UPCALL) += dns_resolve.o cifs_dfs_ref.o cifs-$(CONFIG_CIFS_FSCACHE) += fscache.o cache.o - -cifs-$(CONFIG_CIFS_SMB2) += smb2ops.o smb2maperror.o smb2transport.o \ - smb2misc.o smb2pdu.o smb2inode.o smb2file.o diff --git a/fs/cifs/cifs_unicode.c b/fs/cifs/cifs_unicode.c index e0445e2075b2..b380e0871372 100644 --- a/fs/cifs/cifs_unicode.c +++ b/fs/cifs/cifs_unicode.c @@ -588,7 +588,6 @@ ctoUTF16_out: return j; } -#ifdef CONFIG_CIFS_SMB2 /* * cifs_local_to_utf16_bytes - how long will a string be after conversion? * @from - pointer to input string @@ -647,4 +646,3 @@ cifs_strndup_to_utf16(const char *src, const int maxlen, int *utf16_len, *utf16_len = len; return dst; } -#endif /* CONFIG_CIFS_SMB2 */ diff --git a/fs/cifs/cifs_unicode.h b/fs/cifs/cifs_unicode.h index 8a79a34e66b8..8360b74530a9 100644 --- a/fs/cifs/cifs_unicode.h +++ b/fs/cifs/cifs_unicode.h @@ -116,11 +116,9 @@ char *cifs_strndup_from_utf16(const char *src, const int maxlen, extern int cifsConvertToUTF16(__le16 *target, const char *source, int maxlen, const struct nls_table *cp, int mapChars); extern int cifs_remap(struct cifs_sb_info *cifs_sb); -#ifdef CONFIG_CIFS_SMB2 extern __le16 *cifs_strndup_to_utf16(const char *src, const int maxlen, int *utf16_len, const struct nls_table *cp, int remap); -#endif /* CONFIG_CIFS_SMB2 */ #endif wchar_t cifs_toupper(wchar_t in); diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index 9a1667e0e8d6..556f480c6936 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -51,9 +51,7 @@ #include <linux/key-type.h> #include "cifs_spnego.h" #include "fscache.h" -#ifdef CONFIG_CIFS_SMB2 #include "smb2pdu.h" -#endif int cifsFYI = 0; bool traceSMB; @@ -277,9 +275,8 @@ cifs_alloc_inode(struct super_block *sb) cifs_inode->uniqueid = 0; cifs_inode->createtime = 0; cifs_inode->epoch = 0; -#ifdef CONFIG_CIFS_SMB2 generate_random_uuid(cifs_inode->lease_key); -#endif + /* * Can not set i_flags here - they get immediately overwritten to zero * by the VFS. @@ -1213,14 +1210,12 @@ cifs_destroy_inodecache(void) static int cifs_init_request_bufs(void) { - size_t max_hdr_size = MAX_CIFS_HDR_SIZE; -#ifdef CONFIG_CIFS_SMB2 /* * SMB2 maximum header size is bigger than CIFS one - no problems to * allocate some more bytes for CIFS. */ - max_hdr_size = MAX_SMB2_HDR_SIZE; -#endif + size_t max_hdr_size = MAX_SMB2_HDR_SIZE; + if (CIFSMaxBufSize < 8192) { /* Buffer size can not be smaller than 2 * PATH_MAX since maximum Unicode path name has to fit in any SMB/CIFS path based frames */ @@ -1476,12 +1471,10 @@ MODULE_SOFTDEP("pre: hmac"); MODULE_SOFTDEP("pre: md4"); MODULE_SOFTDEP("pre: md5"); MODULE_SOFTDEP("pre: nls"); -#ifdef CONFIG_CIFS_SMB2 MODULE_SOFTDEP("pre: aes"); MODULE_SOFTDEP("pre: cmac"); MODULE_SOFTDEP("pre: sha256"); MODULE_SOFTDEP("pre: aead2"); MODULE_SOFTDEP("pre: ccm"); -#endif /* CONFIG_CIFS_SMB2 */ module_init(init_cifs) module_exit(exit_cifs) diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index bcc7d9acad64..221693fe49ec 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -29,9 +29,7 @@ #include <crypto/internal/hash.h> #include <linux/scatterlist.h> #include <uapi/linux/cifs/cifs_mount.h> -#ifdef CONFIG_CIFS_SMB2 #include "smb2pdu.h" -#endif #define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDUs */ @@ -367,6 +365,8 @@ struct smb_version_operations { unsigned int (*calc_smb_size)(void *); /* check for STATUS_PENDING and process it in a positive case */ bool (*is_status_pending)(char *, struct TCP_Server_Info *, int); + /* check for STATUS_NETWORK_SESSION_EXPIRED */ + bool (*is_session_expired)(char *); /* send oplock break response */ int (*oplock_response)(struct cifs_tcon *, struct cifs_fid *, struct cifsInodeInfo *); @@ -610,12 +610,10 @@ struct TCP_Server_Info { __u16 sec_mode; bool sign; /* is signing enabled on this connection? */ bool session_estab; /* mark when very first sess is established */ -#ifdef CONFIG_CIFS_SMB2 int echo_credits; /* echo reserved slots */ int oplock_credits; /* oplock break reserved slots */ bool echoes:1; /* enable echoes */ __u8 client_guid[SMB2_CLIENT_GUID_SIZE]; /* Client GUID */ -#endif u16 dialect; /* dialect index that server chose */ bool oplocks:1; /* enable oplocks */ unsigned int maxReq; /* Clients should submit no more */ @@ -659,13 +657,11 @@ struct TCP_Server_Info { atomic_t in_send; /* requests trying to send */ atomic_t num_waiters; /* blocked waiting to get in sendrecv */ #endif -#ifdef CONFIG_CIFS_SMB2 unsigned int max_read; unsigned int max_write; __u8 preauth_hash[512]; struct delayed_work reconnect; /* reconnect workqueue job */ struct mutex reconnect_mutex; /* prevent simultaneous reconnects */ -#endif /* CONFIG_CIFS_SMB2 */ unsigned long echo_interval; }; @@ -847,13 +843,11 @@ struct cifs_ses { bool sign; /* is signing required? */ bool need_reconnect:1; /* connection reset, uid now invalid */ bool domainAuto:1; -#ifdef CONFIG_CIFS_SMB2 __u16 session_flags; __u8 smb3signingkey[SMB3_SIGN_KEY_SIZE]; __u8 smb3encryptionkey[SMB3_SIGN_KEY_SIZE]; __u8 smb3decryptionkey[SMB3_SIGN_KEY_SIZE]; __u8 preauth_hash[512]; -#endif /* CONFIG_CIFS_SMB2 */ }; static inline bool @@ -905,12 +899,10 @@ struct cifs_tcon { atomic_t num_acl_get; atomic_t num_acl_set; } cifs_stats; -#ifdef CONFIG_CIFS_SMB2 struct { atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS]; atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS]; } smb2_stats; -#endif /* CONFIG_CIFS_SMB2 */ } stats; #ifdef CONFIG_CIFS_STATS2 unsigned long long time_writes; @@ -946,7 +938,6 @@ struct cifs_tcon { bool need_reopen_files:1; /* need to reopen tcon file handles */ bool use_resilient:1; /* use resilient instead of durable handles */ bool use_persistent:1; /* use persistent instead of durable handles */ -#ifdef CONFIG_CIFS_SMB2 bool print:1; /* set if connection to printer share */ __le32 capabilities; __u32 share_flags; @@ -959,7 +950,6 @@ struct cifs_tcon { __u32 max_chunks; __u32 max_bytes_chunk; __u32 max_bytes_copy; -#endif /* CONFIG_CIFS_SMB2 */ #ifdef CONFIG_CIFS_FSCACHE u64 resource_id; /* server resource id */ struct fscache_cookie *fscache; /* cookie for share */ @@ -1062,12 +1052,10 @@ struct cifs_open_parms { struct cifs_fid { __u16 netfid; -#ifdef CONFIG_CIFS_SMB2 __u64 persistent_fid; /* persist file id for smb2 */ __u64 volatile_fid; /* volatile file id for smb2 */ __u8 lease_key[SMB2_LEASE_KEY_SIZE]; /* lease key for smb2 */ __u8 create_guid[16]; -#endif struct cifs_pending_open *pending_open; unsigned int epoch; bool purge_cache; @@ -1105,10 +1093,8 @@ struct cifsFileInfo { struct cifs_io_parms { __u16 netfid; -#ifdef CONFIG_CIFS_SMB2 __u64 persistent_fid; /* persist file id for smb2 */ __u64 volatile_fid; /* volatile file id for smb2 */ -#endif __u32 pid; __u64 offset; unsigned int length; @@ -1234,9 +1220,7 @@ struct cifsInodeInfo { u64 server_eof; /* current file size on server -- protected by i_lock */ u64 uniqueid; /* server inode number */ u64 createtime; /* creation time on server */ -#ifdef CONFIG_CIFS_SMB2 __u8 lease_key[SMB2_LEASE_KEY_SIZE]; /* lease key for this inode */ -#endif #ifdef CONFIG_CIFS_FSCACHE struct fscache_cookie *fscache; #endif diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index fbb0d4cbda41..72a53bd19865 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c @@ -1460,6 +1460,13 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid) return length; server->total_read += length; + if (server->ops->is_session_expired && + server->ops->is_session_expired(buf)) { + cifs_reconnect(server); + wake_up(&server->response_q); + return -1; + } + if (server->ops->is_status_pending && server->ops->is_status_pending(buf, server, 0)) { cifs_discard_remaining_data(server); diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 9365c0cf77ad..59647eb72c5f 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -55,9 +55,7 @@ #include "nterr.h" #include "rfc1002pdu.h" #include "fscache.h" -#ifdef CONFIG_CIFS_SMB2 #include "smb2proto.h" -#endif #define CIFS_PORT 445 #define RFC1001_PORT 139 @@ -341,9 +339,7 @@ cifs_reconnect(struct TCP_Server_Info *server) server->tcpStatus = CifsNeedReconnect; spin_unlock(&GlobalMid_Lock); server->maxBuf = 0; -#ifdef CONFIG_CIFS_SMB2 server->max_read = 0; -#endif cifs_dbg(FYI, "Reconnecting tcp session\n"); @@ -812,6 +808,13 @@ cifs_handle_standard(struct TCP_Server_Info *server, struct mid_q_entry *mid) cifs_dump_mem("Bad SMB: ", buf, min_t(unsigned int, server->total_read, 48)); + if (server->ops->is_session_expired && + server->ops->is_session_expired(buf)) { + cifs_reconnect(server); + wake_up(&server->response_q); + return -1; + } + if (server->ops->is_status_pending && server->ops->is_status_pending(buf, server, length)) return -1; @@ -1122,7 +1125,6 @@ cifs_parse_smb_version(char *value, struct smb_vol *vol) vol->ops = &smb1_operations; vol->vals = &smb1_values; break; -#ifdef CONFIG_CIFS_SMB2 case Smb_20: vol->ops = &smb20_operations; vol->vals = &smb20_values; @@ -1145,7 +1147,6 @@ cifs_parse_smb_version(char *value, struct smb_vol *vol) vol->vals = &smb311_values; break; #endif /* SMB311 */ -#endif default: cifs_dbg(VFS, "Unknown vers= option specified: %s\n", value); return 1; @@ -1271,9 +1272,9 @@ cifs_parse_mount_options(const char *mountdata, const char *devname, vol->actimeo = CIFS_DEF_ACTIMEO; - /* FIXME: add autonegotiation -- for now, SMB1 is default */ - vol->ops = &smb1_operations; - vol->vals = &smb1_values; + /* FIXME: add autonegotiation for SMB3 or later rather than just SMB3 */ + vol->ops = &smb30_operations; /* both secure and accepted widely */ + vol->vals = &smb30_values; vol->echo_interval = SMB_ECHO_INTERVAL_DEFAULT; @@ -2170,7 +2171,6 @@ cifs_put_tcp_session(struct TCP_Server_Info *server, int from_reconnect) cancel_delayed_work_sync(&server->echo); -#ifdef CONFIG_CIFS_SMB2 if (from_reconnect) /* * Avoid deadlock here: reconnect work calls @@ -2181,7 +2181,6 @@ cifs_put_tcp_session(struct TCP_Server_Info *server, int from_reconnect) cancel_delayed_work(&server->reconnect); else cancel_delayed_work_sync(&server->reconnect); -#endif spin_lock(&GlobalMid_Lock); server->tcpStatus = CifsExiting; @@ -2247,17 +2246,13 @@ cifs_get_tcp_session(struct smb_vol *volume_info) INIT_LIST_HEAD(&tcp_ses->tcp_ses_list); INIT_LIST_HEAD(&tcp_ses->smb_ses_list); INIT_DELAYED_WORK(&tcp_ses->echo, cifs_echo_request); -#ifdef CONFIG_CIFS_SMB2 INIT_DELAYED_WORK(&tcp_ses->reconnect, smb2_reconnect_server); mutex_init(&tcp_ses->reconnect_mutex); -#endif memcpy(&tcp_ses->srcaddr, &volume_info->srcaddr, sizeof(tcp_ses->srcaddr)); memcpy(&tcp_ses->dstaddr, &volume_info->dstaddr, sizeof(tcp_ses->dstaddr)); -#ifdef CONFIG_CIFS_SMB2 generate_random_uuid(tcp_ses->client_guid); -#endif /* * at this point we are the only ones with the pointer * to the struct since the kernel thread not created yet @@ -2655,10 +2650,8 @@ static int match_tcon(struct cifs_tcon *tcon, struct smb_vol *volume_info) return 0; if (tcon->seal != volume_info->seal) return 0; -#ifdef CONFIG_CIFS_SMB2 if (tcon->snapshot_time != volume_info->snapshot_time) return 0; -#endif /* CONFIG_CIFS_SMB2 */ return 1; } @@ -2733,7 +2726,6 @@ cifs_get_tcon(struct cifs_ses *ses, struct smb_vol *volume_info) } if (volume_info->snapshot_time) { -#ifdef CONFIG_CIFS_SMB2 if (ses->server->vals->protocol_id == 0) { cifs_dbg(VFS, "Use SMB2 or later for snapshot mount option\n"); @@ -2741,11 +2733,6 @@ cifs_get_tcon(struct cifs_ses *ses, struct smb_vol *volume_info) goto out_fail; } else tcon->snapshot_time = volume_info->snapshot_time; -#else - cifs_dbg(VFS, "Snapshot mount option requires SMB2 support\n"); - rc = -EOPNOTSUPP; - goto out_fail; -#endif /* CONFIG_CIFS_SMB2 */ } tcon->ses = ses; @@ -2781,7 +2768,6 @@ cifs_get_tcon(struct cifs_ses *ses, struct smb_vol *volume_info) "SMB3 or later required for persistent handles\n"); rc = -EOPNOTSUPP; goto out_fail; -#ifdef CONFIG_CIFS_SMB2 } else if (ses->server->capabilities & SMB2_GLOBAL_CAP_PERSISTENT_HANDLES) tcon->use_persistent = true; @@ -2790,15 +2776,12 @@ cifs_get_tcon(struct cifs_ses *ses, struct smb_vol *volume_info) "Persistent handles not supported on share\n"); rc = -EOPNOTSUPP; goto out_fail; -#endif /* CONFIG_CIFS_SMB2 */ } -#ifdef CONFIG_CIFS_SMB2 } else if ((tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY) && (ses->server->capabilities & SMB2_GLOBAL_CAP_PERSISTENT_HANDLES) && (volume_info->nopersistent == false)) { cifs_dbg(FYI, "enabling persistent handles\n"); tcon->use_persistent = true; -#endif /* CONFIG_CIFS_SMB2 */ } else if (volume_info->resilient) { if (ses->server->vals->protocol_id == 0) { cifs_dbg(VFS, @@ -2815,7 +2798,6 @@ cifs_get_tcon(struct cifs_ses *ses, struct smb_vol *volume_info) "SMB3 or later required for encryption\n"); rc = -EOPNOTSUPP; goto out_fail; -#ifdef CONFIG_CIFS_SMB2 } else if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_ENCRYPTION) tcon->seal = true; @@ -2823,7 +2805,6 @@ cifs_get_tcon(struct cifs_ses *ses, struct smb_vol *volume_info) cifs_dbg(VFS, "Encryption is not supported on share\n"); rc = -EOPNOTSUPP; goto out_fail; -#endif /* CONFIG_CIFS_SMB2 */ } } @@ -3738,14 +3719,12 @@ try_mount_again: goto mount_fail_check; } -#ifdef CONFIG_CIFS_SMB2 if ((volume_info->persistent == true) && ((ses->server->capabilities & SMB2_GLOBAL_CAP_PERSISTENT_HANDLES) == 0)) { cifs_dbg(VFS, "persistent handles not supported by server\n"); rc = -EOPNOTSUPP; goto mount_fail_check; } -#endif /* CONFIG_CIFS_SMB2*/ /* search for existing tcon to this server share */ tcon = cifs_get_tcon(ses, volume_info); diff --git a/fs/cifs/ioctl.c b/fs/cifs/ioctl.c index 76fb0917dc8c..54f32f9143a9 100644 --- a/fs/cifs/ioctl.c +++ b/fs/cifs/ioctl.c @@ -101,7 +101,6 @@ static long smb_mnt_get_fsinfo(unsigned int xid, struct cifs_tcon *tcon, fsinf->fs_attributes = le32_to_cpu(tcon->fsAttrInfo.Attributes); fsinf->max_path_component = le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength); -#ifdef CONFIG_CIFS_SMB2 fsinf->vol_serial_number = tcon->vol_serial_number; fsinf->vol_create_time = le64_to_cpu(tcon->vol_create_time); fsinf->share_flags = tcon->share_flags; @@ -110,7 +109,6 @@ static long smb_mnt_get_fsinfo(unsigned int xid, struct cifs_tcon *tcon, fsinf->optimal_sector_size = tcon->perf_sector_size; fsinf->max_bytes_chunk = tcon->max_bytes_chunk; fsinf->maximal_access = tcon->maximal_access; -#endif /* SMB2 */ fsinf->cifs_posix_caps = le64_to_cpu(tcon->fsUnixInfo.Capability); if (copy_to_user(arg, fsinf, sizeof(struct smb_mnt_fs_info))) diff --git a/fs/cifs/link.c b/fs/cifs/link.c index c4d996f78e1c..60b5a11ee11b 100644 --- a/fs/cifs/link.c +++ b/fs/cifs/link.c @@ -29,9 +29,7 @@ #include "cifs_debug.h" #include "cifs_fs_sb.h" #include "cifs_unicode.h" -#ifdef CONFIG_CIFS_SMB2 #include "smb2proto.h" -#endif /* * M-F Symlink Functions - Begin @@ -402,7 +400,6 @@ cifs_create_mf_symlink(unsigned int xid, struct cifs_tcon *tcon, /* * SMB 2.1/SMB3 Protocol specific functions */ -#ifdef CONFIG_CIFS_SMB2 int smb3_query_mf_symlink(unsigned int xid, struct cifs_tcon *tcon, struct cifs_sb_info *cifs_sb, const unsigned char *path, @@ -525,7 +522,6 @@ smb3_create_mf_symlink(unsigned int xid, struct cifs_tcon *tcon, kfree(utf16_path); return rc; } -#endif /* CONFIG_CIFS_SMB2 */ /* * M-F Symlink Functions - End diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c index 3b147dc6af63..eea93ac15ef0 100644 --- a/fs/cifs/misc.c +++ b/fs/cifs/misc.c @@ -30,9 +30,7 @@ #include "smberr.h" #include "nterr.h" #include "cifs_unicode.h" -#ifdef CONFIG_CIFS_SMB2 #include "smb2pdu.h" -#endif extern mempool_t *cifs_sm_req_poolp; extern mempool_t *cifs_req_poolp; @@ -149,15 +147,12 @@ struct smb_hdr * cifs_buf_get(void) { struct smb_hdr *ret_buf = NULL; - size_t buf_size = sizeof(struct smb_hdr); - -#ifdef CONFIG_CIFS_SMB2 /* * SMB2 header is bigger than CIFS one - no problems to clean some * more bytes for CIFS. */ - buf_size = sizeof(struct smb2_hdr); -#endif + size_t buf_size = sizeof(struct smb2_hdr); + /* * We could use negotiated size instead of max_msgsize - * but it may be more efficient to always alloc same size @@ -620,9 +615,7 @@ void cifs_add_pending_open_locked(struct cifs_fid *fid, struct tcon_link *tlink, struct cifs_pending_open *open) { -#ifdef CONFIG_CIFS_SMB2 memcpy(open->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE); -#endif open->oplock = CIFS_OPLOCK_NO_CHANGE; open->tlink = tlink; fid->pending_open = open; diff --git a/fs/cifs/smb2maperror.c b/fs/cifs/smb2maperror.c index 3030a9dfb0dd..7ca9808a0daa 100644 --- a/fs/cifs/smb2maperror.c +++ b/fs/cifs/smb2maperror.c @@ -2475,8 +2475,8 @@ map_smb2_to_linux_error(char *buf, bool log_err) /* on error mapping not found - return EIO */ - cifs_dbg(FYI, "Mapping SMB2 status code %d to POSIX err %d\n", - smb2err, rc); + cifs_dbg(FYI, "Mapping SMB2 status code 0x%08x to POSIX err %d\n", + __le32_to_cpu(smb2err), rc); return rc; } diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index ccbb397debbc..cfacf2c97e94 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -1036,6 +1036,18 @@ smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length) return true; } +static bool +smb2_is_session_expired(char *buf) +{ + struct smb2_sync_hdr *shdr = get_sync_hdr(buf); + + if (shdr->Status != STATUS_NETWORK_SESSION_EXPIRED) + return false; + + cifs_dbg(FYI, "Session expired\n"); + return true; +} + static int smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid, struct cifsInodeInfo *cinode) @@ -1370,6 +1382,63 @@ get_smb2_acl_by_path(struct cifs_sb_info *cifs_sb, return pntsd; } +#ifdef CONFIG_CIFS_ACL +static int +set_smb2_acl(struct cifs_ntsd *pnntsd, __u32 acllen, + struct inode *inode, const char *path, int aclflag) +{ + u8 oplock = SMB2_OPLOCK_LEVEL_NONE; + unsigned int xid; + int rc, access_flags = 0; + struct cifs_tcon *tcon; + struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); + struct tcon_link *tlink = cifs_sb_tlink(cifs_sb); + struct cifs_fid fid; + struct cifs_open_parms oparms; + __le16 *utf16_path; + + cifs_dbg(FYI, "set smb3 acl for path %s\n", path); + if (IS_ERR(tlink)) + return PTR_ERR(tlink); + + tcon = tlink_tcon(tlink); + xid = get_xid(); + + if (backup_cred(cifs_sb)) + oparms.create_options = CREATE_OPEN_BACKUP_INTENT; + else + oparms.create_options = 0; + + if (aclflag == CIFS_ACL_OWNER || aclflag == CIFS_ACL_GROUP) + access_flags = WRITE_OWNER; + else + access_flags = WRITE_DAC; + + utf16_path = cifs_convert_path_to_utf16(path, cifs_sb); + if (!utf16_path) + return -ENOMEM; + + oparms.tcon = tcon; + oparms.desired_access = access_flags; + oparms.disposition = FILE_OPEN; + oparms.path = path; + oparms.fid = &fid; + oparms.reconnect = false; + + rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL); + kfree(utf16_path); + if (!rc) { + rc = SMB2_set_acl(xid, tlink_tcon(tlink), fid.persistent_fid, + fid.volatile_fid, pnntsd, acllen, aclflag); + SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); + } + + cifs_put_tlink(tlink); + free_xid(xid); + return rc; +} +#endif /* CIFS_ACL */ + /* Retrieve an ACL from the server */ static struct cifs_ntsd * get_smb2_acl(struct cifs_sb_info *cifs_sb, @@ -2160,6 +2229,13 @@ handle_read_data(struct TCP_Server_Info *server, struct mid_q_entry *mid, return -ENOTSUPP; } + if (server->ops->is_session_expired && + server->ops->is_session_expired(buf)) { + cifs_reconnect(server); + wake_up(&server->response_q); + return -1; + } + if (server->ops->is_status_pending && server->ops->is_status_pending(buf, server, 0)) return -1; @@ -2477,6 +2553,7 @@ struct smb_version_operations smb20_operations = { .close_dir = smb2_close_dir, .calc_smb_size = smb2_calc_size, .is_status_pending = smb2_is_status_pending, + .is_session_expired = smb2_is_session_expired, .oplock_response = smb2_oplock_response, .queryfs = smb2_queryfs, .mand_lock = smb2_mand_lock, @@ -2498,7 +2575,7 @@ struct smb_version_operations smb20_operations = { #ifdef CONFIG_CIFS_ACL .get_acl = get_smb2_acl, .get_acl_by_fid = get_smb2_acl_by_fid, -/* .set_acl = set_smb3_acl, */ + .set_acl = set_smb2_acl, #endif /* CIFS_ACL */ }; @@ -2565,6 +2642,7 @@ struct smb_version_operations smb21_operations = { .close_dir = smb2_close_dir, .calc_smb_size = smb2_calc_size, .is_status_pending = smb2_is_status_pending, + .is_session_expired = smb2_is_session_expired, .oplock_response = smb2_oplock_response, .queryfs = smb2_queryfs, .mand_lock = smb2_mand_lock, @@ -2587,7 +2665,7 @@ struct smb_version_operations smb21_operations = { #ifdef CONFIG_CIFS_ACL .get_acl = get_smb2_acl, .get_acl_by_fid = get_smb2_acl_by_fid, -/* .set_acl = set_smb3_acl, */ + .set_acl = set_smb2_acl, #endif /* CIFS_ACL */ }; @@ -2655,6 +2733,7 @@ struct smb_version_operations smb30_operations = { .close_dir = smb2_close_dir, .calc_smb_size = smb2_calc_size, .is_status_pending = smb2_is_status_pending, + .is_session_expired = smb2_is_session_expired, .oplock_response = smb2_oplock_response, .queryfs = smb2_queryfs, .mand_lock = smb2_mand_lock, @@ -2686,7 +2765,7 @@ struct smb_version_operations smb30_operations = { #ifdef CONFIG_CIFS_ACL .get_acl = get_smb2_acl, .get_acl_by_fid = get_smb2_acl_by_fid, -/* .set_acl = set_smb3_acl, */ + .set_acl = set_smb2_acl, #endif /* CIFS_ACL */ }; @@ -2755,6 +2834,7 @@ struct smb_version_operations smb311_operations = { .close_dir = smb2_close_dir, .calc_smb_size = smb2_calc_size, .is_status_pending = smb2_is_status_pending, + .is_session_expired = smb2_is_session_expired, .oplock_response = smb2_oplock_response, .queryfs = smb2_queryfs, .mand_lock = smb2_mand_lock, diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index 4938e8b6d32f..5fb2fc2d0080 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -1167,15 +1167,12 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree, int rc = 0; int resp_buftype; int unc_path_len; - struct TCP_Server_Info *server; __le16 *unc_path = NULL; int flags = 0; cifs_dbg(FYI, "TCON\n"); - if ((ses->server) && tree) - server = ses->server; - else + if (!(ses->server) || !tree) return -EIO; unc_path = kmalloc(MAX_SHARENAME_LENGTH * 2, GFP_KERNEL); @@ -1294,15 +1291,12 @@ SMB2_tdis(const unsigned int xid, struct cifs_tcon *tcon) { struct smb2_tree_disconnect_req *req; /* response is trivial */ int rc = 0; - struct TCP_Server_Info *server; struct cifs_ses *ses = tcon->ses; int flags = 0; cifs_dbg(FYI, "Tree Disconnect\n"); - if (ses && (ses->server)) - server = ses->server; - else + if (!ses || !(ses->server)) return -EIO; if ((tcon->need_reconnect) || (tcon->ses->need_reconnect)) @@ -1794,7 +1788,6 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, struct smb2_ioctl_req *req; struct smb2_ioctl_rsp *rsp; struct smb2_sync_hdr *shdr; - struct TCP_Server_Info *server; struct cifs_ses *ses; struct kvec iov[2]; struct kvec rsp_iov; @@ -1817,9 +1810,7 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, else return -EIO; - if (ses && (ses->server)) - server = ses->server; - else + if (!ses || !(ses->server)) return -EIO; rc = small_smb2_init(SMB2_IOCTL, tcon, (void **) &req); @@ -1977,7 +1968,6 @@ SMB2_close(const unsigned int xid, struct cifs_tcon *tcon, { struct smb2_close_req *req; struct smb2_close_rsp *rsp; - struct TCP_Server_Info *server; struct cifs_ses *ses = tcon->ses; struct kvec iov[1]; struct kvec rsp_iov; @@ -1987,9 +1977,7 @@ SMB2_close(const unsigned int xid, struct cifs_tcon *tcon, cifs_dbg(FYI, "Close\n"); - if (ses && (ses->server)) - server = ses->server; - else + if (!ses || !(ses->server)) return -EIO; rc = small_smb2_init(SMB2_CLOSE, tcon, (void **) &req); @@ -2091,15 +2079,12 @@ query_info(const unsigned int xid, struct cifs_tcon *tcon, struct kvec rsp_iov; int rc = 0; int resp_buftype; - struct TCP_Server_Info *server; struct cifs_ses *ses = tcon->ses; int flags = 0; cifs_dbg(FYI, "Query Info\n"); - if (ses && (ses->server)) - server = ses->server; - else + if (!ses || !(ses->server)) return -EIO; rc = small_smb2_init(SMB2_QUERY_INFO, tcon, (void **) &req); @@ -2311,7 +2296,6 @@ SMB2_flush(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, u64 volatile_fid) { struct smb2_flush_req *req; - struct TCP_Server_Info *server; struct cifs_ses *ses = tcon->ses; struct kvec iov[1]; struct kvec rsp_iov; @@ -2321,9 +2305,7 @@ SMB2_flush(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, cifs_dbg(FYI, "Flush\n"); - if (ses && (ses->server)) - server = ses->server; - else + if (!ses || !(ses->server)) return -EIO; rc = small_smb2_init(SMB2_FLUSH, tcon, (void **) &req); @@ -3000,8 +2982,9 @@ qdir_exit: static int send_set_info(const unsigned int xid, struct cifs_tcon *tcon, - u64 persistent_fid, u64 volatile_fid, u32 pid, int info_class, - unsigned int num, void **data, unsigned int *size) + u64 persistent_fid, u64 volatile_fid, u32 pid, u8 info_class, + u8 info_type, u32 additional_info, unsigned int num, + void **data, unsigned int *size) { struct smb2_set_info_req *req; struct smb2_set_info_rsp *rsp = NULL; @@ -3010,13 +2993,10 @@ send_set_info(const unsigned int xid, struct cifs_tcon *tcon, int rc = 0; int resp_buftype; unsigned int i; - struct TCP_Server_Info *server; struct cifs_ses *ses = tcon->ses; int flags = 0; - if (ses && (ses->server)) - server = ses->server; - else + if (!ses || !(ses->server)) return -EIO; if (!num) @@ -3037,10 +3017,11 @@ send_set_info(const unsigned int xid, struct cifs_tcon *tcon, req->hdr.sync_hdr.ProcessId = cpu_to_le32(pid); - req->InfoType = SMB2_O_INFO_FILE; + req->InfoType = info_type; req->FileInfoClass = info_class; req->PersistentFileId = persistent_fid; req->VolatileFileId = volatile_fid; + req->AdditionalInformation = cpu_to_le32(additional_info); /* 4 for RFC1001 length and 1 for Buffer */ req->BufferOffset = @@ -3100,8 +3081,8 @@ SMB2_rename(const unsigned int xid, struct cifs_tcon *tcon, size[1] = len + 2 /* null */; rc = send_set_info(xid, tcon, persistent_fid, volatile_fid, - current->tgid, FILE_RENAME_INFORMATION, 2, data, - size); + current->tgid, FILE_RENAME_INFORMATION, SMB2_O_INFO_FILE, + 0, 2, data, size); kfree(data); return rc; } @@ -3118,8 +3099,8 @@ SMB2_rmdir(const unsigned int xid, struct cifs_tcon *tcon, size = 1; /* sizeof __u8 */ return send_set_info(xid, tcon, persistent_fid, volatile_fid, - current->tgid, FILE_DISPOSITION_INFORMATION, 1, &data, - &size); + current->tgid, FILE_DISPOSITION_INFORMATION, SMB2_O_INFO_FILE, + 0, 1, &data, &size); } int @@ -3148,7 +3129,8 @@ SMB2_set_hardlink(const unsigned int xid, struct cifs_tcon *tcon, size[1] = len + 2 /* null */; rc = send_set_info(xid, tcon, persistent_fid, volatile_fid, - current->tgid, FILE_LINK_INFORMATION, 2, data, size); + current->tgid, FILE_LINK_INFORMATION, SMB2_O_INFO_FILE, + 0, 2, data, size); kfree(data); return rc; } @@ -3168,10 +3150,12 @@ SMB2_set_eof(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, if (is_falloc) return send_set_info(xid, tcon, persistent_fid, volatile_fid, - pid, FILE_ALLOCATION_INFORMATION, 1, &data, &size); + pid, FILE_ALLOCATION_INFORMATION, SMB2_O_INFO_FILE, + 0, 1, &data, &size); else return send_set_info(xid, tcon, persistent_fid, volatile_fid, - pid, FILE_END_OF_FILE_INFORMATION, 1, &data, &size); + pid, FILE_END_OF_FILE_INFORMATION, SMB2_O_INFO_FILE, + 0, 1, &data, &size); } int @@ -3181,8 +3165,18 @@ SMB2_set_info(const unsigned int xid, struct cifs_tcon *tcon, unsigned int size; size = sizeof(FILE_BASIC_INFO); return send_set_info(xid, tcon, persistent_fid, volatile_fid, - current->tgid, FILE_BASIC_INFORMATION, 1, - (void **)&buf, &size); + current->tgid, FILE_BASIC_INFORMATION, SMB2_O_INFO_FILE, + 0, 1, (void **)&buf, &size); +} + +int +SMB2_set_acl(const unsigned int xid, struct cifs_tcon *tcon, + u64 persistent_fid, u64 volatile_fid, + struct cifs_ntsd *pnntsd, int pacllen, int aclflag) +{ + return send_set_info(xid, tcon, persistent_fid, volatile_fid, + current->tgid, 0, SMB2_O_INFO_SECURITY, aclflag, + 1, (void **)&pnntsd, &pacllen); } int diff --git a/fs/cifs/smb2proto.h b/fs/cifs/smb2proto.h index 3595cd755147..1cadaf9f3c58 100644 --- a/fs/cifs/smb2proto.h +++ b/fs/cifs/smb2proto.h @@ -166,6 +166,9 @@ extern int SMB2_set_eof(const unsigned int xid, struct cifs_tcon *tcon, extern int SMB2_set_info(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, u64 volatile_fid, FILE_BASIC_INFO *buf); +extern int SMB2_set_acl(const unsigned int xid, struct cifs_tcon *tcon, + u64 persistent_fid, u64 volatile_fid, + struct cifs_ntsd *pnntsd, int pacllen, int aclflag); extern int SMB2_set_compression(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, u64 volatile_fid); extern int SMB2_oplock_break(const unsigned int xid, struct cifs_tcon *tcon, |