Commit 908b852d authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'smb3-security-fixes-for-4.13' of git://git.samba.org/sfrench/cifs-2.6

Pull cifs fixes and sane default from Steve French:
 "Upgrade default dialect to more secure SMB3 from older cifs dialect"

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