Commit fb157ed2 authored by Steve French's avatar Steve French

cifs: when insecure legacy is disabled shrink amount of SMB1 code

Currently much of the smb1 code is built even when
CONFIG_CIFS_ALLOW_INSECURE_LEGACY is disabled.

Move cifssmb.c to only be compiled when insecure legacy is disabled,
and move various SMB1/CIFS helper functions to that ifdef.  Some
functions that were not SMB1/CIFS specific needed to be moved out of
cifssmb.c

This shrinks cifs.ko by more than 10% which is good - but also will
help with the eventual movement of the legacy code to a distinct
module.  Follow on patches can shrink the number of ifdefs by
code restructuring where smb1 code is wedged in functions that
should be calling dialect specific helper functions instead,
and also by moving some functions from file.c/dir.c/inode.c into
smb1 specific c files.
Reviewed-by: default avatarRonnie Sahlberg <lsahlber@redhat.com>
Reviewed-by: default avatarPaulo Alcantara (SUSE) <pc@cjr.nz>
Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
parent 97b82c07
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
ccflags-y += -I$(src) # needed for trace events ccflags-y += -I$(src) # needed for trace events
obj-$(CONFIG_CIFS) += cifs.o obj-$(CONFIG_CIFS) += cifs.o
cifs-y := trace.o cifsfs.o cifssmb.o cifs_debug.o connect.o dir.o file.o \ cifs-y := trace.o cifsfs.o cifs_debug.o connect.o dir.o file.o \
inode.o link.o misc.o netmisc.o smbencrypt.o transport.o \ inode.o link.o misc.o netmisc.o smbencrypt.o transport.o \
cifs_unicode.o nterr.o cifsencrypt.o \ cifs_unicode.o nterr.o cifsencrypt.o \
readdir.o ioctl.o sess.o export.o unc.o winucase.o \ readdir.o ioctl.o sess.o export.o unc.o winucase.o \
...@@ -31,4 +31,4 @@ cifs-$(CONFIG_CIFS_SMB_DIRECT) += smbdirect.o ...@@ -31,4 +31,4 @@ cifs-$(CONFIG_CIFS_SMB_DIRECT) += smbdirect.o
cifs-$(CONFIG_CIFS_ROOT) += cifsroot.o cifs-$(CONFIG_CIFS_ROOT) += cifsroot.o
cifs-$(CONFIG_CIFS_ALLOW_INSECURE_LEGACY) += smb1ops.o cifs-$(CONFIG_CIFS_ALLOW_INSECURE_LEGACY) += smb1ops.o cifssmb.o
...@@ -1379,6 +1379,7 @@ static int build_sec_desc(struct cifs_ntsd *pntsd, struct cifs_ntsd *pnntsd, ...@@ -1379,6 +1379,7 @@ static int build_sec_desc(struct cifs_ntsd *pntsd, struct cifs_ntsd *pnntsd,
return rc; return rc;
} }
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
struct cifs_ntsd *get_cifs_acl_by_fid(struct cifs_sb_info *cifs_sb, struct cifs_ntsd *get_cifs_acl_by_fid(struct cifs_sb_info *cifs_sb,
const struct cifs_fid *cifsfid, u32 *pacllen, const struct cifs_fid *cifsfid, u32 *pacllen,
u32 __maybe_unused unused) u32 __maybe_unused unused)
...@@ -1512,6 +1513,7 @@ int set_cifs_acl(struct cifs_ntsd *pnntsd, __u32 acllen, ...@@ -1512,6 +1513,7 @@ int set_cifs_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
cifs_put_tlink(tlink); cifs_put_tlink(tlink);
return rc; return rc;
} }
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
/* Translate the CIFS ACL (similar to NTFS ACL) for a file into mode bits */ /* Translate the CIFS ACL (similar to NTFS ACL) for a file into mode bits */
int int
......
...@@ -521,6 +521,7 @@ extern int generate_smb30signingkey(struct cifs_ses *ses, ...@@ -521,6 +521,7 @@ extern int generate_smb30signingkey(struct cifs_ses *ses,
extern int generate_smb311signingkey(struct cifs_ses *ses, extern int generate_smb311signingkey(struct cifs_ses *ses,
struct TCP_Server_Info *server); struct TCP_Server_Info *server);
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
extern int CIFSSMBCopy(unsigned int xid, extern int CIFSSMBCopy(unsigned int xid,
struct cifs_tcon *source_tcon, struct cifs_tcon *source_tcon,
const char *fromName, const char *fromName,
...@@ -551,6 +552,7 @@ extern int CIFSSMBSetPosixACL(const unsigned int xid, struct cifs_tcon *tcon, ...@@ -551,6 +552,7 @@ extern int CIFSSMBSetPosixACL(const unsigned int xid, struct cifs_tcon *tcon,
const struct nls_table *nls_codepage, int remap_special_chars); const struct nls_table *nls_codepage, int remap_special_chars);
extern int CIFSGetExtAttr(const unsigned int xid, struct cifs_tcon *tcon, extern int CIFSGetExtAttr(const unsigned int xid, struct cifs_tcon *tcon,
const int netfid, __u64 *pExtAttrBits, __u64 *pMask); const int netfid, __u64 *pExtAttrBits, __u64 *pMask);
#endif /* CIFS_ALLOW_INSECURE_LEGACY */
extern void cifs_autodisable_serverino(struct cifs_sb_info *cifs_sb); extern void cifs_autodisable_serverino(struct cifs_sb_info *cifs_sb);
extern bool couldbe_mf_symlink(const struct cifs_fattr *fattr); extern bool couldbe_mf_symlink(const struct cifs_fattr *fattr);
extern int check_mf_symlink(unsigned int xid, struct cifs_tcon *tcon, extern int check_mf_symlink(unsigned int xid, struct cifs_tcon *tcon,
......
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include "cifsproto.h" #include "cifsproto.h"
#include "cifs_unicode.h" #include "cifs_unicode.h"
#include "cifs_debug.h" #include "cifs_debug.h"
#include "smb2proto.h"
#include "fscache.h" #include "fscache.h"
#include "smbdirect.h" #include "smbdirect.h"
#ifdef CONFIG_CIFS_DFS_UPCALL #ifdef CONFIG_CIFS_DFS_UPCALL
...@@ -62,52 +61,6 @@ static struct { ...@@ -62,52 +61,6 @@ static struct {
#define CIFS_NUM_PROT 1 #define CIFS_NUM_PROT 1
#endif /* CIFS_POSIX */ #endif /* CIFS_POSIX */
/*
* Mark as invalid, all open files on tree connections since they
* were closed when session to server was lost.
*/
void
cifs_mark_open_files_invalid(struct cifs_tcon *tcon)
{
struct cifsFileInfo *open_file = NULL;
struct list_head *tmp;
struct list_head *tmp1;
/* only send once per connect */
spin_lock(&tcon->ses->ses_lock);
if ((tcon->ses->ses_status != SES_GOOD) || (tcon->status != TID_NEED_RECON)) {
spin_unlock(&tcon->ses->ses_lock);
return;
}
tcon->status = TID_IN_FILES_INVALIDATE;
spin_unlock(&tcon->ses->ses_lock);
/* list all files open on tree connection and mark them invalid */
spin_lock(&tcon->open_file_lock);
list_for_each_safe(tmp, tmp1, &tcon->openFileList) {
open_file = list_entry(tmp, struct cifsFileInfo, tlist);
open_file->invalidHandle = true;
open_file->oplock_break_cancelled = true;
}
spin_unlock(&tcon->open_file_lock);
mutex_lock(&tcon->crfid.fid_mutex);
tcon->crfid.is_valid = false;
/* cached handle is not valid, so SMB2_CLOSE won't be sent below */
close_cached_dir_lease_locked(&tcon->crfid);
memset(tcon->crfid.fid, 0, sizeof(struct cifs_fid));
mutex_unlock(&tcon->crfid.fid_mutex);
spin_lock(&tcon->tc_lock);
if (tcon->status == TID_IN_FILES_INVALIDATE)
tcon->status = TID_NEED_TCON;
spin_unlock(&tcon->tc_lock);
/*
* BB Add call to invalidate_inodes(sb) for all superblocks mounted
* to this tcon.
*/
}
/* reconnect the socket, tcon, and smb session if needed */ /* reconnect the socket, tcon, and smb session if needed */
static int static int
...@@ -457,52 +410,6 @@ decode_ext_sec_blob(struct cifs_ses *ses, NEGOTIATE_RSP *pSMBr) ...@@ -457,52 +410,6 @@ decode_ext_sec_blob(struct cifs_ses *ses, NEGOTIATE_RSP *pSMBr)
return 0; return 0;
} }
int
cifs_enable_signing(struct TCP_Server_Info *server, bool mnt_sign_required)
{
bool srv_sign_required = server->sec_mode & server->vals->signing_required;
bool srv_sign_enabled = server->sec_mode & server->vals->signing_enabled;
bool mnt_sign_enabled;
/*
* Is signing required by mnt options? If not then check
* global_secflags to see if it is there.
*/
if (!mnt_sign_required)
mnt_sign_required = ((global_secflags & CIFSSEC_MUST_SIGN) ==
CIFSSEC_MUST_SIGN);
/*
* If signing is required then it's automatically enabled too,
* otherwise, check to see if the secflags allow it.
*/
mnt_sign_enabled = mnt_sign_required ? mnt_sign_required :
(global_secflags & CIFSSEC_MAY_SIGN);
/* If server requires signing, does client allow it? */
if (srv_sign_required) {
if (!mnt_sign_enabled) {
cifs_dbg(VFS, "Server requires signing, but it's disabled in SecurityFlags!\n");
return -ENOTSUPP;
}
server->sign = true;
}
/* If client requires signing, does server allow it? */
if (mnt_sign_required) {
if (!srv_sign_enabled) {
cifs_dbg(VFS, "Server does not support signing!\n");
return -ENOTSUPP;
}
server->sign = true;
}
if (cifs_rdma_enabled(server) && server->sign)
cifs_dbg(VFS, "Signing is enabled, and RDMA read/write will be disabled\n");
return 0;
}
static bool static bool
should_set_ext_sec_flag(enum securityEnum sectype) should_set_ext_sec_flag(enum securityEnum sectype)
{ {
...@@ -1379,184 +1286,6 @@ CIFS_open(const unsigned int xid, struct cifs_open_parms *oparms, int *oplock, ...@@ -1379,184 +1286,6 @@ CIFS_open(const unsigned int xid, struct cifs_open_parms *oparms, int *oplock,
return rc; return rc;
} }
/*
* Discard any remaining data in the current SMB. To do this, we borrow the
* current bigbuf.
*/
int
cifs_discard_remaining_data(struct TCP_Server_Info *server)
{
unsigned int rfclen = server->pdu_size;
int remaining = rfclen + server->vals->header_preamble_size -
server->total_read;
while (remaining > 0) {
int length;
length = cifs_discard_from_socket(server,
min_t(size_t, remaining,
CIFSMaxBufSize + MAX_HEADER_SIZE(server)));
if (length < 0)
return length;
server->total_read += length;
remaining -= length;
}
return 0;
}
static int
__cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid,
bool malformed)
{
int length;
length = cifs_discard_remaining_data(server);
dequeue_mid(mid, malformed);
mid->resp_buf = server->smallbuf;
server->smallbuf = NULL;
return length;
}
static int
cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid)
{
struct cifs_readdata *rdata = mid->callback_data;
return __cifs_readv_discard(server, mid, rdata->result);
}
int
cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid)
{
int length, len;
unsigned int data_offset, data_len;
struct cifs_readdata *rdata = mid->callback_data;
char *buf = server->smallbuf;
unsigned int buflen = server->pdu_size +
server->vals->header_preamble_size;
bool use_rdma_mr = false;
cifs_dbg(FYI, "%s: mid=%llu offset=%llu bytes=%u\n",
__func__, mid->mid, rdata->offset, rdata->bytes);
/*
* read the rest of READ_RSP header (sans Data array), or whatever we
* can if there's not enough data. At this point, we've read down to
* the Mid.
*/
len = min_t(unsigned int, buflen, server->vals->read_rsp_size) -
HEADER_SIZE(server) + 1;
length = cifs_read_from_socket(server,
buf + HEADER_SIZE(server) - 1, len);
if (length < 0)
return length;
server->total_read += length;
if (server->ops->is_session_expired &&
server->ops->is_session_expired(buf)) {
cifs_reconnect(server, true);
return -1;
}
if (server->ops->is_status_pending &&
server->ops->is_status_pending(buf, server)) {
cifs_discard_remaining_data(server);
return -1;
}
/* set up first two iov for signature check and to get credits */
rdata->iov[0].iov_base = buf;
rdata->iov[0].iov_len = server->vals->header_preamble_size;
rdata->iov[1].iov_base = buf + server->vals->header_preamble_size;
rdata->iov[1].iov_len =
server->total_read - server->vals->header_preamble_size;
cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
rdata->iov[0].iov_base, rdata->iov[0].iov_len);
cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n",
rdata->iov[1].iov_base, rdata->iov[1].iov_len);
/* Was the SMB read successful? */
rdata->result = server->ops->map_error(buf, false);
if (rdata->result != 0) {
cifs_dbg(FYI, "%s: server returned error %d\n",
__func__, rdata->result);
/* normal error on read response */
return __cifs_readv_discard(server, mid, false);
}
/* Is there enough to get to the rest of the READ_RSP header? */
if (server->total_read < server->vals->read_rsp_size) {
cifs_dbg(FYI, "%s: server returned short header. got=%u expected=%zu\n",
__func__, server->total_read,
server->vals->read_rsp_size);
rdata->result = -EIO;
return cifs_readv_discard(server, mid);
}
data_offset = server->ops->read_data_offset(buf) +
server->vals->header_preamble_size;
if (data_offset < server->total_read) {
/*
* win2k8 sometimes sends an offset of 0 when the read
* is beyond the EOF. Treat it as if the data starts just after
* the header.
*/
cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
__func__, data_offset);
data_offset = server->total_read;
} else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
/* data_offset is beyond the end of smallbuf */
cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
__func__, data_offset);
rdata->result = -EIO;
return cifs_readv_discard(server, mid);
}
cifs_dbg(FYI, "%s: total_read=%u data_offset=%u\n",
__func__, server->total_read, data_offset);
len = data_offset - server->total_read;
if (len > 0) {
/* read any junk before data into the rest of smallbuf */
length = cifs_read_from_socket(server,
buf + server->total_read, len);
if (length < 0)
return length;
server->total_read += length;
}
/* how much data is in the response? */
#ifdef CONFIG_CIFS_SMB_DIRECT
use_rdma_mr = rdata->mr;
#endif
data_len = server->ops->read_data_length(buf, use_rdma_mr);
if (!use_rdma_mr && (data_offset + data_len > buflen)) {
/* data_len is corrupt -- discard frame */
rdata->result = -EIO;
return cifs_readv_discard(server, mid);
}
length = rdata->read_into_pages(server, rdata, data_len);
if (length < 0)
return length;
server->total_read += length;
cifs_dbg(FYI, "total_read=%u buflen=%u remaining=%u\n",
server->total_read, buflen, data_len);
/* discard anything left over */
if (server->total_read < buflen)
return cifs_readv_discard(server, mid);
dequeue_mid(mid, false);
mid->resp_buf = server->smallbuf;
server->smallbuf = NULL;
return length;
}
static void static void
cifs_readv_callback(struct mid_q_entry *mid) cifs_readv_callback(struct mid_q_entry *mid)
{ {
...@@ -1909,183 +1638,6 @@ CIFSSMBWrite(const unsigned int xid, struct cifs_io_parms *io_parms, ...@@ -1909,183 +1638,6 @@ CIFSSMBWrite(const unsigned int xid, struct cifs_io_parms *io_parms,
return rc; return rc;
} }
void
cifs_writedata_release(struct kref *refcount)
{
struct cifs_writedata *wdata = container_of(refcount,
struct cifs_writedata, refcount);
#ifdef CONFIG_CIFS_SMB_DIRECT
if (wdata->mr) {
smbd_deregister_mr(wdata->mr);
wdata->mr = NULL;
}
#endif
if (wdata->cfile)
cifsFileInfo_put(wdata->cfile);
kvfree(wdata->pages);
kfree(wdata);
}
/*
* Write failed with a retryable error. Resend the write request. It's also
* possible that the page was redirtied so re-clean the page.
*/
static void
cifs_writev_requeue(struct cifs_writedata *wdata)
{
int i, rc = 0;
struct inode *inode = d_inode(wdata->cfile->dentry);
struct TCP_Server_Info *server;
unsigned int rest_len;
server = tlink_tcon(wdata->cfile->tlink)->ses->server;
i = 0;
rest_len = wdata->bytes;
do {
struct cifs_writedata *wdata2;
unsigned int j, nr_pages, wsize, tailsz, cur_len;
wsize = server->ops->wp_retry_size(inode);
if (wsize < rest_len) {
nr_pages = wsize / PAGE_SIZE;
if (!nr_pages) {
rc = -ENOTSUPP;
break;
}
cur_len = nr_pages * PAGE_SIZE;
tailsz = PAGE_SIZE;
} else {
nr_pages = DIV_ROUND_UP(rest_len, PAGE_SIZE);
cur_len = rest_len;
tailsz = rest_len - (nr_pages - 1) * PAGE_SIZE;
}
wdata2 = cifs_writedata_alloc(nr_pages, cifs_writev_complete);
if (!wdata2) {
rc = -ENOMEM;
break;
}
for (j = 0; j < nr_pages; j++) {
wdata2->pages[j] = wdata->pages[i + j];
lock_page(wdata2->pages[j]);
clear_page_dirty_for_io(wdata2->pages[j]);
}
wdata2->sync_mode = wdata->sync_mode;
wdata2->nr_pages = nr_pages;
wdata2->offset = page_offset(wdata2->pages[0]);
wdata2->pagesz = PAGE_SIZE;
wdata2->tailsz = tailsz;
wdata2->bytes = cur_len;
rc = cifs_get_writable_file(CIFS_I(inode), FIND_WR_ANY,
&wdata2->cfile);
if (!wdata2->cfile) {
cifs_dbg(VFS, "No writable handle to retry writepages rc=%d\n",
rc);
if (!is_retryable_error(rc))
rc = -EBADF;
} else {
wdata2->pid = wdata2->cfile->pid;
rc = server->ops->async_writev(wdata2,
cifs_writedata_release);
}
for (j = 0; j < nr_pages; j++) {
unlock_page(wdata2->pages[j]);
if (rc != 0 && !is_retryable_error(rc)) {
SetPageError(wdata2->pages[j]);
end_page_writeback(wdata2->pages[j]);
put_page(wdata2->pages[j]);
}
}
kref_put(&wdata2->refcount, cifs_writedata_release);
if (rc) {
if (is_retryable_error(rc))
continue;
i += nr_pages;
break;
}
rest_len -= cur_len;
i += nr_pages;
} while (i < wdata->nr_pages);
/* cleanup remaining pages from the original wdata */
for (; i < wdata->nr_pages; i++) {
SetPageError(wdata->pages[i]);
end_page_writeback(wdata->pages[i]);
put_page(wdata->pages[i]);
}
if (rc != 0 && !is_retryable_error(rc))
mapping_set_error(inode->i_mapping, rc);
kref_put(&wdata->refcount, cifs_writedata_release);
}
void
cifs_writev_complete(struct work_struct *work)
{
struct cifs_writedata *wdata = container_of(work,
struct cifs_writedata, work);
struct inode *inode = d_inode(wdata->cfile->dentry);
int i = 0;
if (wdata->result == 0) {
spin_lock(&inode->i_lock);
cifs_update_eof(CIFS_I(inode), wdata->offset, wdata->bytes);
spin_unlock(&inode->i_lock);
cifs_stats_bytes_written(tlink_tcon(wdata->cfile->tlink),
wdata->bytes);
} else if (wdata->sync_mode == WB_SYNC_ALL && wdata->result == -EAGAIN)
return cifs_writev_requeue(wdata);
for (i = 0; i < wdata->nr_pages; i++) {
struct page *page = wdata->pages[i];
if (wdata->result == -EAGAIN)
__set_page_dirty_nobuffers(page);
else if (wdata->result < 0)
SetPageError(page);
end_page_writeback(page);
cifs_readpage_to_fscache(inode, page);
put_page(page);
}
if (wdata->result != -EAGAIN)
mapping_set_error(inode->i_mapping, wdata->result);
kref_put(&wdata->refcount, cifs_writedata_release);
}
struct cifs_writedata *
cifs_writedata_alloc(unsigned int nr_pages, work_func_t complete)
{
struct page **pages =
kcalloc(nr_pages, sizeof(struct page *), GFP_NOFS);
if (pages)
return cifs_writedata_direct_alloc(pages, complete);
return NULL;
}
struct cifs_writedata *
cifs_writedata_direct_alloc(struct page **pages, work_func_t complete)
{
struct cifs_writedata *wdata;
wdata = kzalloc(sizeof(*wdata), GFP_NOFS);
if (wdata != NULL) {
wdata->pages = pages;
kref_init(&wdata->refcount);
INIT_LIST_HEAD(&wdata->list);
init_completion(&wdata->done);
INIT_WORK(&wdata->work, complete);
}
return wdata;
}
/* /*
* Check the mid_state and signature on received buffer (if any), and queue the * Check the mid_state and signature on received buffer (if any), and queue the
* workqueue completion task. * workqueue completion task.
...@@ -3660,7 +3212,6 @@ CIFSSMBSetPosixACL(const unsigned int xid, struct cifs_tcon *tcon, ...@@ -3660,7 +3212,6 @@ CIFSSMBSetPosixACL(const unsigned int xid, struct cifs_tcon *tcon,
return rc; return rc;
} }
/* BB fix tabs in this function FIXME BB */
int int
CIFSGetExtAttr(const unsigned int xid, struct cifs_tcon *tcon, CIFSGetExtAttr(const unsigned int xid, struct cifs_tcon *tcon,
const int netfid, __u64 *pExtAttrBits, __u64 *pMask) const int netfid, __u64 *pExtAttrBits, __u64 *pMask)
...@@ -3723,7 +3274,7 @@ CIFSGetExtAttr(const unsigned int xid, struct cifs_tcon *tcon, ...@@ -3723,7 +3274,7 @@ CIFSGetExtAttr(const unsigned int xid, struct cifs_tcon *tcon,
__u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
__u16 count = le16_to_cpu(pSMBr->t2.DataCount); __u16 count = le16_to_cpu(pSMBr->t2.DataCount);
struct file_chattr_info *pfinfo; struct file_chattr_info *pfinfo;
/* BB Do we need a cast or hash here ? */
if (count != 16) { if (count != 16) {
cifs_dbg(FYI, "Invalid size ret in GetExtAttr\n"); cifs_dbg(FYI, "Invalid size ret in GetExtAttr\n");
rc = -EIO; rc = -EIO;
......
...@@ -898,6 +898,53 @@ handle_mid(struct mid_q_entry *mid, struct TCP_Server_Info *server, ...@@ -898,6 +898,53 @@ handle_mid(struct mid_q_entry *mid, struct TCP_Server_Info *server,
dequeue_mid(mid, malformed); dequeue_mid(mid, malformed);
} }
int
cifs_enable_signing(struct TCP_Server_Info *server, bool mnt_sign_required)
{
bool srv_sign_required = server->sec_mode & server->vals->signing_required;
bool srv_sign_enabled = server->sec_mode & server->vals->signing_enabled;
bool mnt_sign_enabled;
/*
* Is signing required by mnt options? If not then check
* global_secflags to see if it is there.
*/
if (!mnt_sign_required)
mnt_sign_required = ((global_secflags & CIFSSEC_MUST_SIGN) ==
CIFSSEC_MUST_SIGN);
/*
* If signing is required then it's automatically enabled too,
* otherwise, check to see if the secflags allow it.
*/
mnt_sign_enabled = mnt_sign_required ? mnt_sign_required :
(global_secflags & CIFSSEC_MAY_SIGN);
/* If server requires signing, does client allow it? */
if (srv_sign_required) {
if (!mnt_sign_enabled) {
cifs_dbg(VFS, "Server requires signing, but it's disabled in SecurityFlags!\n");
return -EOPNOTSUPP;
}
server->sign = true;
}
/* If client requires signing, does server allow it? */
if (mnt_sign_required) {
if (!srv_sign_enabled) {
cifs_dbg(VFS, "Server does not support signing!\n");
return -EOPNOTSUPP;
}
server->sign = true;
}
if (cifs_rdma_enabled(server) && server->sign)
cifs_dbg(VFS, "Signing is enabled, and RDMA read/write will be disabled\n");
return 0;
}
static void clean_demultiplex_info(struct TCP_Server_Info *server) static void clean_demultiplex_info(struct TCP_Server_Info *server)
{ {
int length; int length;
...@@ -2976,6 +3023,7 @@ ip_connect(struct TCP_Server_Info *server) ...@@ -2976,6 +3023,7 @@ ip_connect(struct TCP_Server_Info *server)
return generic_ip_connect(server); return generic_ip_connect(server);
} }
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
void reset_cifs_unix_caps(unsigned int xid, struct cifs_tcon *tcon, void reset_cifs_unix_caps(unsigned int xid, struct cifs_tcon *tcon,
struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx) struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx)
{ {
...@@ -3081,6 +3129,7 @@ void reset_cifs_unix_caps(unsigned int xid, struct cifs_tcon *tcon, ...@@ -3081,6 +3129,7 @@ void reset_cifs_unix_caps(unsigned int xid, struct cifs_tcon *tcon,
} }
} }
} }
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
int cifs_setup_cifs_sb(struct cifs_sb_info *cifs_sb) int cifs_setup_cifs_sb(struct cifs_sb_info *cifs_sb)
{ {
...@@ -3197,6 +3246,7 @@ static int mount_get_conns(struct mount_ctx *mnt_ctx) ...@@ -3197,6 +3246,7 @@ static int mount_get_conns(struct mount_ctx *mnt_ctx)
if (tcon->posix_extensions) if (tcon->posix_extensions)
cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_POSIX_PATHS; cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_POSIX_PATHS;
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
/* tell server which Unix caps we support */ /* tell server which Unix caps we support */
if (cap_unix(tcon->ses)) { if (cap_unix(tcon->ses)) {
/* /*
...@@ -3214,6 +3264,7 @@ static int mount_get_conns(struct mount_ctx *mnt_ctx) ...@@ -3214,6 +3264,7 @@ static int mount_get_conns(struct mount_ctx *mnt_ctx)
} }
spin_unlock(&tcon->ses->server->srv_lock); spin_unlock(&tcon->ses->server->srv_lock);
} else } else
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
tcon->unix_ext = 0; /* server does not support them */ tcon->unix_ext = 0; /* server does not support them */
/* do not care if a following call succeed - informational */ /* do not care if a following call succeed - informational */
...@@ -4189,8 +4240,10 @@ cifs_construct_tcon(struct cifs_sb_info *cifs_sb, kuid_t fsuid) ...@@ -4189,8 +4240,10 @@ cifs_construct_tcon(struct cifs_sb_info *cifs_sb, kuid_t fsuid)
goto out; goto out;
} }
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
if (cap_unix(ses)) if (cap_unix(ses))
reset_cifs_unix_caps(0, tcon, NULL, ctx); reset_cifs_unix_caps(0, tcon, NULL, ctx);
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
out: out:
kfree(ctx->username); kfree(ctx->username);
......
...@@ -193,6 +193,7 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid, ...@@ -193,6 +193,7 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
return PTR_ERR(full_path); return PTR_ERR(full_path);
} }
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
if (tcon->unix_ext && cap_unix(tcon->ses) && !tcon->broken_posix_open && if (tcon->unix_ext && cap_unix(tcon->ses) && !tcon->broken_posix_open &&
(CIFS_UNIX_POSIX_PATH_OPS_CAP & (CIFS_UNIX_POSIX_PATH_OPS_CAP &
le64_to_cpu(tcon->fsUnixInfo.Capability))) { le64_to_cpu(tcon->fsUnixInfo.Capability))) {
...@@ -261,6 +262,7 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid, ...@@ -261,6 +262,7 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
* rare for path not covered on files) * rare for path not covered on files)
*/ */
} }
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
desired_access = 0; desired_access = 0;
if (OPEN_FMODE(oflags) & FMODE_READ) if (OPEN_FMODE(oflags) & FMODE_READ)
...@@ -316,6 +318,7 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid, ...@@ -316,6 +318,7 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
goto out; goto out;
} }
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
/* /*
* If Open reported that we actually created a file then we now have to * If Open reported that we actually created a file then we now have to
* set the mode if possible. * set the mode if possible.
...@@ -357,6 +360,9 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid, ...@@ -357,6 +360,9 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
rc = cifs_get_inode_info_unix(&newinode, full_path, inode->i_sb, rc = cifs_get_inode_info_unix(&newinode, full_path, inode->i_sb,
xid); xid);
else { else {
#else
{
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
/* TODO: Add support for calling POSIX query info here, but passing in fid */ /* TODO: Add support for calling POSIX query info here, but passing in fid */
rc = cifs_get_inode_info(&newinode, full_path, buf, inode->i_sb, rc = cifs_get_inode_info(&newinode, full_path, buf, inode->i_sb,
xid, fid); xid, fid);
...@@ -377,7 +383,9 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid, ...@@ -377,7 +383,9 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
} }
} }
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
cifs_create_set_dentry: cifs_create_set_dentry:
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
if (rc != 0) { if (rc != 0) {
cifs_dbg(FYI, "Create worked, get_inode_info failed rc = %d\n", cifs_dbg(FYI, "Create worked, get_inode_info failed rc = %d\n",
rc); rc);
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "cifspdu.h" #include "cifspdu.h"
#include "cifsglob.h" #include "cifsglob.h"
#include "cifsproto.h" #include "cifsproto.h"
#include "smb2proto.h"
#include "cifs_unicode.h" #include "cifs_unicode.h"
#include "cifs_debug.h" #include "cifs_debug.h"
#include "cifs_fs_sb.h" #include "cifs_fs_sb.h"
...@@ -34,6 +35,53 @@ ...@@ -34,6 +35,53 @@
#include "fs_context.h" #include "fs_context.h"
#include "cifs_ioctl.h" #include "cifs_ioctl.h"
/*
* Mark as invalid, all open files on tree connections since they
* were closed when session to server was lost.
*/
void
cifs_mark_open_files_invalid(struct cifs_tcon *tcon)
{
struct cifsFileInfo *open_file = NULL;
struct list_head *tmp;
struct list_head *tmp1;
/* only send once per connect */
spin_lock(&tcon->ses->ses_lock);
if ((tcon->ses->ses_status != SES_GOOD) || (tcon->status != TID_NEED_RECON)) {
spin_unlock(&tcon->ses->ses_lock);
return;
}
tcon->status = TID_IN_FILES_INVALIDATE;
spin_unlock(&tcon->ses->ses_lock);
/* list all files open on tree connection and mark them invalid */
spin_lock(&tcon->open_file_lock);
list_for_each_safe(tmp, tmp1, &tcon->openFileList) {
open_file = list_entry(tmp, struct cifsFileInfo, tlist);
open_file->invalidHandle = true;
open_file->oplock_break_cancelled = true;
}
spin_unlock(&tcon->open_file_lock);
mutex_lock(&tcon->crfid.fid_mutex);
tcon->crfid.is_valid = false;
/* cached handle is not valid, so SMB2_CLOSE won't be sent below */
close_cached_dir_lease_locked(&tcon->crfid);
memset(tcon->crfid.fid, 0, sizeof(struct cifs_fid));
mutex_unlock(&tcon->crfid.fid_mutex);
spin_lock(&tcon->tc_lock);
if (tcon->status == TID_IN_FILES_INVALIDATE)
tcon->status = TID_NEED_TCON;
spin_unlock(&tcon->tc_lock);
/*
* BB Add call to invalidate_inodes(sb) for all superblocks mounted
* to this tcon.
*/
}
static inline int cifs_convert_flags(unsigned int flags) static inline int cifs_convert_flags(unsigned int flags)
{ {
if ((flags & O_ACCMODE) == O_RDONLY) if ((flags & O_ACCMODE) == O_RDONLY)
...@@ -52,6 +100,7 @@ static inline int cifs_convert_flags(unsigned int flags) ...@@ -52,6 +100,7 @@ static inline int cifs_convert_flags(unsigned int flags)
FILE_READ_DATA); FILE_READ_DATA);
} }
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
static u32 cifs_posix_convert_flags(unsigned int flags) static u32 cifs_posix_convert_flags(unsigned int flags)
{ {
u32 posix_flags = 0; u32 posix_flags = 0;
...@@ -85,6 +134,7 @@ static u32 cifs_posix_convert_flags(unsigned int flags) ...@@ -85,6 +134,7 @@ static u32 cifs_posix_convert_flags(unsigned int flags)
return posix_flags; return posix_flags;
} }
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
static inline int cifs_get_disposition(unsigned int flags) static inline int cifs_get_disposition(unsigned int flags)
{ {
...@@ -100,6 +150,7 @@ static inline int cifs_get_disposition(unsigned int flags) ...@@ -100,6 +150,7 @@ static inline int cifs_get_disposition(unsigned int flags)
return FILE_OPEN; return FILE_OPEN;
} }
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
int cifs_posix_open(const char *full_path, struct inode **pinode, int cifs_posix_open(const char *full_path, struct inode **pinode,
struct super_block *sb, int mode, unsigned int f_flags, struct super_block *sb, int mode, unsigned int f_flags,
__u32 *poplock, __u16 *pnetfid, unsigned int xid) __u32 *poplock, __u16 *pnetfid, unsigned int xid)
...@@ -161,6 +212,7 @@ int cifs_posix_open(const char *full_path, struct inode **pinode, ...@@ -161,6 +212,7 @@ int cifs_posix_open(const char *full_path, struct inode **pinode,
kfree(presp_data); kfree(presp_data);
return rc; return rc;
} }
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
static int static int
cifs_nt_open(const char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb, cifs_nt_open(const char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb,
...@@ -579,6 +631,7 @@ int cifs_open(struct inode *inode, struct file *file) ...@@ -579,6 +631,7 @@ int cifs_open(struct inode *inode, struct file *file)
else else
oplock = 0; oplock = 0;
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
if (!tcon->broken_posix_open && tcon->unix_ext && if (!tcon->broken_posix_open && tcon->unix_ext &&
cap_unix(tcon->ses) && (CIFS_UNIX_POSIX_PATH_OPS_CAP & cap_unix(tcon->ses) && (CIFS_UNIX_POSIX_PATH_OPS_CAP &
le64_to_cpu(tcon->fsUnixInfo.Capability))) { le64_to_cpu(tcon->fsUnixInfo.Capability))) {
...@@ -603,6 +656,7 @@ int cifs_open(struct inode *inode, struct file *file) ...@@ -603,6 +656,7 @@ int cifs_open(struct inode *inode, struct file *file)
* or DFS errors. * or DFS errors.
*/ */
} }
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
if (server->ops->get_lease_key) if (server->ops->get_lease_key)
server->ops->get_lease_key(inode, &fid); server->ops->get_lease_key(inode, &fid);
...@@ -630,6 +684,7 @@ int cifs_open(struct inode *inode, struct file *file) ...@@ -630,6 +684,7 @@ int cifs_open(struct inode *inode, struct file *file)
goto out; goto out;
} }
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
if ((oplock & CIFS_CREATE_ACTION) && !posix_open_ok && tcon->unix_ext) { if ((oplock & CIFS_CREATE_ACTION) && !posix_open_ok && tcon->unix_ext) {
/* /*
* Time to set mode which we can not set earlier due to * Time to set mode which we can not set earlier due to
...@@ -647,6 +702,7 @@ int cifs_open(struct inode *inode, struct file *file) ...@@ -647,6 +702,7 @@ int cifs_open(struct inode *inode, struct file *file)
CIFSSMBUnixSetFileInfo(xid, tcon, &args, fid.netfid, CIFSSMBUnixSetFileInfo(xid, tcon, &args, fid.netfid,
cfile->pid); cfile->pid);
} }
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
use_cache: use_cache:
fscache_use_cookie(cifs_inode_cookie(file_inode(file)), fscache_use_cookie(cifs_inode_cookie(file_inode(file)),
...@@ -664,7 +720,9 @@ int cifs_open(struct inode *inode, struct file *file) ...@@ -664,7 +720,9 @@ int cifs_open(struct inode *inode, struct file *file)
return rc; return rc;
} }
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
static int cifs_push_posix_locks(struct cifsFileInfo *cfile); static int cifs_push_posix_locks(struct cifsFileInfo *cfile);
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
/* /*
* Try to reacquire byte range locks that were released when session * Try to reacquire byte range locks that were released when session
...@@ -673,10 +731,12 @@ static int cifs_push_posix_locks(struct cifsFileInfo *cfile); ...@@ -673,10 +731,12 @@ static int cifs_push_posix_locks(struct cifsFileInfo *cfile);
static int static int
cifs_relock_file(struct cifsFileInfo *cfile) cifs_relock_file(struct cifsFileInfo *cfile)
{ {
struct cifs_sb_info *cifs_sb = CIFS_SB(cfile->dentry->d_sb);
struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry)); struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
int rc = 0; int rc = 0;
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
struct cifs_sb_info *cifs_sb = CIFS_SB(cfile->dentry->d_sb);
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
down_read_nested(&cinode->lock_sem, SINGLE_DEPTH_NESTING); down_read_nested(&cinode->lock_sem, SINGLE_DEPTH_NESTING);
if (cinode->can_cache_brlcks) { if (cinode->can_cache_brlcks) {
...@@ -685,11 +745,13 @@ cifs_relock_file(struct cifsFileInfo *cfile) ...@@ -685,11 +745,13 @@ cifs_relock_file(struct cifsFileInfo *cfile)
return rc; return rc;
} }
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
if (cap_unix(tcon->ses) && if (cap_unix(tcon->ses) &&
(CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) && (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) &&
((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0)) ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0))
rc = cifs_push_posix_locks(cfile); rc = cifs_push_posix_locks(cfile);
else else
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
rc = tcon->ses->server->ops->push_mand_locks(cfile); rc = tcon->ses->server->ops->push_mand_locks(cfile);
up_read(&cinode->lock_sem); up_read(&cinode->lock_sem);
...@@ -750,6 +812,7 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush) ...@@ -750,6 +812,7 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush)
else else
oplock = 0; oplock = 0;
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
if (tcon->unix_ext && cap_unix(tcon->ses) && if (tcon->unix_ext && cap_unix(tcon->ses) &&
(CIFS_UNIX_POSIX_PATH_OPS_CAP & (CIFS_UNIX_POSIX_PATH_OPS_CAP &
le64_to_cpu(tcon->fsUnixInfo.Capability))) { le64_to_cpu(tcon->fsUnixInfo.Capability))) {
...@@ -773,6 +836,7 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush) ...@@ -773,6 +836,7 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush)
* in the reconnect path it is important to retry hard * in the reconnect path it is important to retry hard
*/ */
} }
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
desired_access = cifs_convert_flags(cfile->f_flags); desired_access = cifs_convert_flags(cfile->f_flags);
...@@ -817,7 +881,9 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush) ...@@ -817,7 +881,9 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush)
goto reopen_error_exit; goto reopen_error_exit;
} }
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
reopen_success: reopen_success:
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
cfile->invalidHandle = false; cfile->invalidHandle = false;
mutex_unlock(&cfile->fh_mutex); mutex_unlock(&cfile->fh_mutex);
cinode = CIFS_I(inode); cinode = CIFS_I(inode);
...@@ -1192,6 +1258,7 @@ cifs_lock_add_if(struct cifsFileInfo *cfile, struct cifsLockInfo *lock, ...@@ -1192,6 +1258,7 @@ cifs_lock_add_if(struct cifsFileInfo *cfile, struct cifsLockInfo *lock,
return rc; return rc;
} }
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
/* /*
* Check if there is another lock that prevents us to set the lock (posix * Check if there is another lock that prevents us to set the lock (posix
* style). If such a lock exists, update the flock structure with its * style). If such a lock exists, update the flock structure with its
...@@ -1330,6 +1397,7 @@ hash_lockowner(fl_owner_t owner) ...@@ -1330,6 +1397,7 @@ hash_lockowner(fl_owner_t owner)
{ {
return cifs_lock_secret ^ hash32_ptr((const void *)owner); return cifs_lock_secret ^ hash32_ptr((const void *)owner);
} }
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
struct lock_to_push { struct lock_to_push {
struct list_head llist; struct list_head llist;
...@@ -1340,6 +1408,7 @@ struct lock_to_push { ...@@ -1340,6 +1408,7 @@ struct lock_to_push {
__u8 type; __u8 type;
}; };
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
static int static int
cifs_push_posix_locks(struct cifsFileInfo *cfile) cifs_push_posix_locks(struct cifsFileInfo *cfile)
{ {
...@@ -1427,14 +1496,17 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile) ...@@ -1427,14 +1496,17 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile)
} }
goto out; goto out;
} }
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
static int static int
cifs_push_locks(struct cifsFileInfo *cfile) cifs_push_locks(struct cifsFileInfo *cfile)
{ {
struct cifs_sb_info *cifs_sb = CIFS_SB(cfile->dentry->d_sb);
struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry)); struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
int rc = 0; int rc = 0;
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
struct cifs_sb_info *cifs_sb = CIFS_SB(cfile->dentry->d_sb);
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
/* we are going to update can_cache_brlcks here - need a write access */ /* we are going to update can_cache_brlcks here - need a write access */
cifs_down_write(&cinode->lock_sem); cifs_down_write(&cinode->lock_sem);
...@@ -1443,11 +1515,13 @@ cifs_push_locks(struct cifsFileInfo *cfile) ...@@ -1443,11 +1515,13 @@ cifs_push_locks(struct cifsFileInfo *cfile)
return rc; return rc;
} }
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
if (cap_unix(tcon->ses) && if (cap_unix(tcon->ses) &&
(CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) && (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) &&
((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0)) ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0))
rc = cifs_push_posix_locks(cfile); rc = cifs_push_posix_locks(cfile);
else else
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
rc = tcon->ses->server->ops->push_mand_locks(cfile); rc = tcon->ses->server->ops->push_mand_locks(cfile);
cinode->can_cache_brlcks = false; cinode->can_cache_brlcks = false;
...@@ -1511,6 +1585,7 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type, ...@@ -1511,6 +1585,7 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type,
struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data; struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data;
struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
struct TCP_Server_Info *server = tcon->ses->server; struct TCP_Server_Info *server = tcon->ses->server;
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
__u16 netfid = cfile->fid.netfid; __u16 netfid = cfile->fid.netfid;
if (posix_lck) { if (posix_lck) {
...@@ -1530,6 +1605,7 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type, ...@@ -1530,6 +1605,7 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type,
posix_lock_type, wait_flag); posix_lock_type, wait_flag);
return rc; return rc;
} }
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
rc = cifs_lock_test(cfile, flock->fl_start, length, type, flock); rc = cifs_lock_test(cfile, flock->fl_start, length, type, flock);
if (!rc) if (!rc)
...@@ -1590,6 +1666,7 @@ cifs_free_llist(struct list_head *llist) ...@@ -1590,6 +1666,7 @@ cifs_free_llist(struct list_head *llist)
} }
} }
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
int int
cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock,
unsigned int xid) unsigned int xid)
...@@ -1702,6 +1779,7 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, ...@@ -1702,6 +1779,7 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock,
kfree(buf); kfree(buf);
return rc; return rc;
} }
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
static int static int
cifs_setlk(struct file *file, struct file_lock *flock, __u32 type, cifs_setlk(struct file *file, struct file_lock *flock, __u32 type,
...@@ -1715,6 +1793,7 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type, ...@@ -1715,6 +1793,7 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type,
struct TCP_Server_Info *server = tcon->ses->server; struct TCP_Server_Info *server = tcon->ses->server;
struct inode *inode = d_inode(cfile->dentry); struct inode *inode = d_inode(cfile->dentry);
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
if (posix_lck) { if (posix_lck) {
int posix_lock_type; int posix_lock_type;
...@@ -1736,7 +1815,7 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type, ...@@ -1736,7 +1815,7 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type,
NULL, posix_lock_type, wait_flag); NULL, posix_lock_type, wait_flag);
goto out; goto out;
} }
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
if (lock) { if (lock) {
struct cifsLockInfo *lock; struct cifsLockInfo *lock;
...@@ -2200,6 +2279,185 @@ cifs_get_readable_path(struct cifs_tcon *tcon, const char *name, ...@@ -2200,6 +2279,185 @@ cifs_get_readable_path(struct cifs_tcon *tcon, const char *name,
return -ENOENT; return -ENOENT;
} }
void
cifs_writedata_release(struct kref *refcount)
{
struct cifs_writedata *wdata = container_of(refcount,
struct cifs_writedata, refcount);
#ifdef CONFIG_CIFS_SMB_DIRECT
if (wdata->mr) {
smbd_deregister_mr(wdata->mr);
wdata->mr = NULL;
}
#endif
if (wdata->cfile)
cifsFileInfo_put(wdata->cfile);
kvfree(wdata->pages);
kfree(wdata);
}
/*
* Write failed with a retryable error. Resend the write request. It's also
* possible that the page was redirtied so re-clean the page.
*/
static void
cifs_writev_requeue(struct cifs_writedata *wdata)
{
int i, rc = 0;
struct inode *inode = d_inode(wdata->cfile->dentry);
struct TCP_Server_Info *server;
unsigned int rest_len;
server = tlink_tcon(wdata->cfile->tlink)->ses->server;
i = 0;
rest_len = wdata->bytes;
do {
struct cifs_writedata *wdata2;
unsigned int j, nr_pages, wsize, tailsz, cur_len;
wsize = server->ops->wp_retry_size(inode);
if (wsize < rest_len) {
nr_pages = wsize / PAGE_SIZE;
if (!nr_pages) {
rc = -EOPNOTSUPP;
break;
}
cur_len = nr_pages * PAGE_SIZE;
tailsz = PAGE_SIZE;
} else {
nr_pages = DIV_ROUND_UP(rest_len, PAGE_SIZE);
cur_len = rest_len;
tailsz = rest_len - (nr_pages - 1) * PAGE_SIZE;
}
wdata2 = cifs_writedata_alloc(nr_pages, cifs_writev_complete);
if (!wdata2) {
rc = -ENOMEM;
break;
}
for (j = 0; j < nr_pages; j++) {
wdata2->pages[j] = wdata->pages[i + j];
lock_page(wdata2->pages[j]);
clear_page_dirty_for_io(wdata2->pages[j]);
}
wdata2->sync_mode = wdata->sync_mode;
wdata2->nr_pages = nr_pages;
wdata2->offset = page_offset(wdata2->pages[0]);
wdata2->pagesz = PAGE_SIZE;
wdata2->tailsz = tailsz;
wdata2->bytes = cur_len;
rc = cifs_get_writable_file(CIFS_I(inode), FIND_WR_ANY,
&wdata2->cfile);
if (!wdata2->cfile) {
cifs_dbg(VFS, "No writable handle to retry writepages rc=%d\n",
rc);
if (!is_retryable_error(rc))
rc = -EBADF;
} else {
wdata2->pid = wdata2->cfile->pid;
rc = server->ops->async_writev(wdata2,
cifs_writedata_release);
}
for (j = 0; j < nr_pages; j++) {
unlock_page(wdata2->pages[j]);
if (rc != 0 && !is_retryable_error(rc)) {
SetPageError(wdata2->pages[j]);
end_page_writeback(wdata2->pages[j]);
put_page(wdata2->pages[j]);
}
}
kref_put(&wdata2->refcount, cifs_writedata_release);
if (rc) {
if (is_retryable_error(rc))
continue;
i += nr_pages;
break;
}
rest_len -= cur_len;
i += nr_pages;
} while (i < wdata->nr_pages);
/* cleanup remaining pages from the original wdata */
for (; i < wdata->nr_pages; i++) {
SetPageError(wdata->pages[i]);
end_page_writeback(wdata->pages[i]);
put_page(wdata->pages[i]);
}
if (rc != 0 && !is_retryable_error(rc))
mapping_set_error(inode->i_mapping, rc);
kref_put(&wdata->refcount, cifs_writedata_release);
}
void
cifs_writev_complete(struct work_struct *work)
{
struct cifs_writedata *wdata = container_of(work,
struct cifs_writedata, work);
struct inode *inode = d_inode(wdata->cfile->dentry);
int i = 0;
if (wdata->result == 0) {
spin_lock(&inode->i_lock);
cifs_update_eof(CIFS_I(inode), wdata->offset, wdata->bytes);
spin_unlock(&inode->i_lock);
cifs_stats_bytes_written(tlink_tcon(wdata->cfile->tlink),
wdata->bytes);
} else if (wdata->sync_mode == WB_SYNC_ALL && wdata->result == -EAGAIN)
return cifs_writev_requeue(wdata);
for (i = 0; i < wdata->nr_pages; i++) {
struct page *page = wdata->pages[i];
if (wdata->result == -EAGAIN)
__set_page_dirty_nobuffers(page);
else if (wdata->result < 0)
SetPageError(page);
end_page_writeback(page);
cifs_readpage_to_fscache(inode, page);
put_page(page);
}
if (wdata->result != -EAGAIN)
mapping_set_error(inode->i_mapping, wdata->result);
kref_put(&wdata->refcount, cifs_writedata_release);
}
struct cifs_writedata *
cifs_writedata_alloc(unsigned int nr_pages, work_func_t complete)
{
struct page **pages =
kcalloc(nr_pages, sizeof(struct page *), GFP_NOFS);
if (pages)
return cifs_writedata_direct_alloc(pages, complete);
return NULL;
}
struct cifs_writedata *
cifs_writedata_direct_alloc(struct page **pages, work_func_t complete)
{
struct cifs_writedata *wdata;
wdata = kzalloc(sizeof(*wdata), GFP_NOFS);
if (wdata != NULL) {
wdata->pages = pages;
kref_init(&wdata->refcount);
INIT_LIST_HEAD(&wdata->list);
init_completion(&wdata->done);
INIT_WORK(&wdata->work, complete);
}
return wdata;
}
static int cifs_partialpagewrite(struct page *page, unsigned from, unsigned to) static int cifs_partialpagewrite(struct page *page, unsigned from, unsigned to)
{ {
struct address_space *mapping = page->mapping; struct address_space *mapping = page->mapping;
......
...@@ -339,6 +339,7 @@ cifs_create_dfs_fattr(struct cifs_fattr *fattr, struct super_block *sb) ...@@ -339,6 +339,7 @@ cifs_create_dfs_fattr(struct cifs_fattr *fattr, struct super_block *sb)
fattr->cf_flags = CIFS_FATTR_DFS_REFERRAL; fattr->cf_flags = CIFS_FATTR_DFS_REFERRAL;
} }
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
static int static int
cifs_get_file_info_unix(struct file *filp) cifs_get_file_info_unix(struct file *filp)
{ {
...@@ -432,6 +433,14 @@ int cifs_get_inode_info_unix(struct inode **pinode, ...@@ -432,6 +433,14 @@ int cifs_get_inode_info_unix(struct inode **pinode,
cgiiu_exit: cgiiu_exit:
return rc; return rc;
} }
#else
int cifs_get_inode_info_unix(struct inode **pinode,
const unsigned char *full_path,
struct super_block *sb, unsigned int xid)
{
return -EOPNOTSUPP;
}
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
static int static int
cifs_sfu_type(struct cifs_fattr *fattr, const char *path, cifs_sfu_type(struct cifs_fattr *fattr, const char *path,
...@@ -795,6 +804,7 @@ static __u64 simple_hashstr(const char *str) ...@@ -795,6 +804,7 @@ static __u64 simple_hashstr(const char *str)
return hash; return hash;
} }
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
/** /**
* cifs_backup_query_path_info - SMB1 fallback code to get ino * cifs_backup_query_path_info - SMB1 fallback code to get ino
* *
...@@ -847,6 +857,7 @@ cifs_backup_query_path_info(int xid, ...@@ -847,6 +857,7 @@ cifs_backup_query_path_info(int xid,
*data = (FILE_ALL_INFO *)info.srch_entries_start; *data = (FILE_ALL_INFO *)info.srch_entries_start;
return 0; return 0;
} }
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
static void static void
cifs_set_fattr_ino(int xid, cifs_set_fattr_ino(int xid,
...@@ -991,6 +1002,7 @@ cifs_get_inode_info(struct inode **inode, ...@@ -991,6 +1002,7 @@ cifs_get_inode_info(struct inode **inode,
rc = 0; rc = 0;
break; break;
case -EACCES: case -EACCES:
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
/* /*
* perm errors, try again with backup flags if possible * perm errors, try again with backup flags if possible
* *
...@@ -1022,6 +1034,9 @@ cifs_get_inode_info(struct inode **inode, ...@@ -1022,6 +1034,9 @@ cifs_get_inode_info(struct inode **inode,
/* nothing we can do, bail out */ /* nothing we can do, bail out */
goto out; goto out;
} }
#else
goto out;
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
break; break;
default: default:
cifs_dbg(FYI, "%s: unhandled err rc %d\n", __func__, rc); cifs_dbg(FYI, "%s: unhandled err rc %d\n", __func__, rc);
...@@ -1037,8 +1052,9 @@ cifs_get_inode_info(struct inode **inode, ...@@ -1037,8 +1052,9 @@ cifs_get_inode_info(struct inode **inode,
/* /*
* 4. Tweak fattr based on mount options * 4. Tweak fattr based on mount options
*/ */
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
handle_mnt_opt: handle_mnt_opt:
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
/* query for SFU type info if supported and needed */ /* query for SFU type info if supported and needed */
if (fattr.cf_cifsattrs & ATTR_SYSTEM && if (fattr.cf_cifsattrs & ATTR_SYSTEM &&
cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) { cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) {
...@@ -1435,6 +1451,7 @@ cifs_set_file_info(struct inode *inode, struct iattr *attrs, unsigned int xid, ...@@ -1435,6 +1451,7 @@ cifs_set_file_info(struct inode *inode, struct iattr *attrs, unsigned int xid,
return server->ops->set_file_info(inode, full_path, &info_buf, xid); return server->ops->set_file_info(inode, full_path, &info_buf, xid);
} }
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
/* /*
* Open the given file (if it isn't already), set the DELETE_ON_CLOSE bit * Open the given file (if it isn't already), set the DELETE_ON_CLOSE bit
* and rename it to a random name that hopefully won't conflict with * and rename it to a random name that hopefully won't conflict with
...@@ -1565,6 +1582,7 @@ cifs_rename_pending_delete(const char *full_path, struct dentry *dentry, ...@@ -1565,6 +1582,7 @@ cifs_rename_pending_delete(const char *full_path, struct dentry *dentry,
goto out_close; goto out_close;
} }
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
/* copied from fs/nfs/dir.c with small changes */ /* copied from fs/nfs/dir.c with small changes */
static void static void
...@@ -1627,6 +1645,7 @@ int cifs_unlink(struct inode *dir, struct dentry *dentry) ...@@ -1627,6 +1645,7 @@ int cifs_unlink(struct inode *dir, struct dentry *dentry)
} }
cifs_close_deferred_file_under_dentry(tcon, full_path); cifs_close_deferred_file_under_dentry(tcon, full_path);
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
if (cap_unix(tcon->ses) && (CIFS_UNIX_POSIX_PATH_OPS_CAP & if (cap_unix(tcon->ses) && (CIFS_UNIX_POSIX_PATH_OPS_CAP &
le64_to_cpu(tcon->fsUnixInfo.Capability))) { le64_to_cpu(tcon->fsUnixInfo.Capability))) {
rc = CIFSPOSIXDelFile(xid, tcon, full_path, rc = CIFSPOSIXDelFile(xid, tcon, full_path,
...@@ -1636,6 +1655,7 @@ int cifs_unlink(struct inode *dir, struct dentry *dentry) ...@@ -1636,6 +1655,7 @@ int cifs_unlink(struct inode *dir, struct dentry *dentry)
if ((rc == 0) || (rc == -ENOENT)) if ((rc == 0) || (rc == -ENOENT))
goto psx_del_no_retry; goto psx_del_no_retry;
} }
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
retry_std_delete: retry_std_delete:
if (!server->ops->unlink) { if (!server->ops->unlink) {
...@@ -1714,9 +1734,11 @@ cifs_mkdir_qinfo(struct inode *parent, struct dentry *dentry, umode_t mode, ...@@ -1714,9 +1734,11 @@ cifs_mkdir_qinfo(struct inode *parent, struct dentry *dentry, umode_t mode,
if (tcon->posix_extensions) if (tcon->posix_extensions)
rc = smb311_posix_get_inode_info(&inode, full_path, parent->i_sb, xid); rc = smb311_posix_get_inode_info(&inode, full_path, parent->i_sb, xid);
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
else if (tcon->unix_ext) else if (tcon->unix_ext)
rc = cifs_get_inode_info_unix(&inode, full_path, parent->i_sb, rc = cifs_get_inode_info_unix(&inode, full_path, parent->i_sb,
xid); xid);
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
else else
rc = cifs_get_inode_info(&inode, full_path, NULL, parent->i_sb, rc = cifs_get_inode_info(&inode, full_path, NULL, parent->i_sb,
xid, NULL); xid, NULL);
...@@ -1746,6 +1768,7 @@ cifs_mkdir_qinfo(struct inode *parent, struct dentry *dentry, umode_t mode, ...@@ -1746,6 +1768,7 @@ cifs_mkdir_qinfo(struct inode *parent, struct dentry *dentry, umode_t mode,
if (parent->i_mode & S_ISGID) if (parent->i_mode & S_ISGID)
mode |= S_ISGID; mode |= S_ISGID;
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
if (tcon->unix_ext) { if (tcon->unix_ext) {
struct cifs_unix_set_info_args args = { struct cifs_unix_set_info_args args = {
.mode = mode, .mode = mode,
...@@ -1768,6 +1791,9 @@ cifs_mkdir_qinfo(struct inode *parent, struct dentry *dentry, umode_t mode, ...@@ -1768,6 +1791,9 @@ cifs_mkdir_qinfo(struct inode *parent, struct dentry *dentry, umode_t mode,
cifs_sb->local_nls, cifs_sb->local_nls,
cifs_remap(cifs_sb)); cifs_remap(cifs_sb));
} else { } else {
#else
{
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
struct TCP_Server_Info *server = tcon->ses->server; struct TCP_Server_Info *server = tcon->ses->server;
if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) && if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) &&
(mode & S_IWUGO) == 0 && server->ops->mkdir_setinfo) (mode & S_IWUGO) == 0 && server->ops->mkdir_setinfo)
...@@ -1788,6 +1814,7 @@ cifs_mkdir_qinfo(struct inode *parent, struct dentry *dentry, umode_t mode, ...@@ -1788,6 +1814,7 @@ cifs_mkdir_qinfo(struct inode *parent, struct dentry *dentry, umode_t mode,
return 0; return 0;
} }
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
static int static int
cifs_posix_mkdir(struct inode *inode, struct dentry *dentry, umode_t mode, cifs_posix_mkdir(struct inode *inode, struct dentry *dentry, umode_t mode,
const char *full_path, struct cifs_sb_info *cifs_sb, const char *full_path, struct cifs_sb_info *cifs_sb,
...@@ -1850,6 +1877,7 @@ cifs_posix_mkdir(struct inode *inode, struct dentry *dentry, umode_t mode, ...@@ -1850,6 +1877,7 @@ cifs_posix_mkdir(struct inode *inode, struct dentry *dentry, umode_t mode,
xid); xid);
goto posix_mkdir_out; goto posix_mkdir_out;
} }
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
int cifs_mkdir(struct user_namespace *mnt_userns, struct inode *inode, int cifs_mkdir(struct user_namespace *mnt_userns, struct inode *inode,
struct dentry *direntry, umode_t mode) struct dentry *direntry, umode_t mode)
...@@ -1892,6 +1920,7 @@ int cifs_mkdir(struct user_namespace *mnt_userns, struct inode *inode, ...@@ -1892,6 +1920,7 @@ int cifs_mkdir(struct user_namespace *mnt_userns, struct inode *inode,
goto mkdir_out; goto mkdir_out;
} }
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
if (cap_unix(tcon->ses) && (CIFS_UNIX_POSIX_PATH_OPS_CAP & if (cap_unix(tcon->ses) && (CIFS_UNIX_POSIX_PATH_OPS_CAP &
le64_to_cpu(tcon->fsUnixInfo.Capability))) { le64_to_cpu(tcon->fsUnixInfo.Capability))) {
rc = cifs_posix_mkdir(inode, direntry, mode, full_path, cifs_sb, rc = cifs_posix_mkdir(inode, direntry, mode, full_path, cifs_sb,
...@@ -1899,6 +1928,7 @@ int cifs_mkdir(struct user_namespace *mnt_userns, struct inode *inode, ...@@ -1899,6 +1928,7 @@ int cifs_mkdir(struct user_namespace *mnt_userns, struct inode *inode,
if (rc != -EOPNOTSUPP) if (rc != -EOPNOTSUPP)
goto mkdir_out; goto mkdir_out;
} }
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
if (!server->ops->mkdir) { if (!server->ops->mkdir) {
rc = -ENOSYS; rc = -ENOSYS;
...@@ -2015,9 +2045,12 @@ cifs_do_rename(const unsigned int xid, struct dentry *from_dentry, ...@@ -2015,9 +2045,12 @@ cifs_do_rename(const unsigned int xid, struct dentry *from_dentry,
struct tcon_link *tlink; struct tcon_link *tlink;
struct cifs_tcon *tcon; struct cifs_tcon *tcon;
struct TCP_Server_Info *server; struct TCP_Server_Info *server;
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
struct cifs_fid fid; struct cifs_fid fid;
struct cifs_open_parms oparms; struct cifs_open_parms oparms;
int oplock, rc; int oplock;
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
int rc;
tlink = cifs_sb_tlink(cifs_sb); tlink = cifs_sb_tlink(cifs_sb);
if (IS_ERR(tlink)) if (IS_ERR(tlink))
...@@ -2043,6 +2076,7 @@ cifs_do_rename(const unsigned int xid, struct dentry *from_dentry, ...@@ -2043,6 +2076,7 @@ cifs_do_rename(const unsigned int xid, struct dentry *from_dentry,
if (server->vals->protocol_id != 0) if (server->vals->protocol_id != 0)
goto do_rename_exit; goto do_rename_exit;
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
/* open-file renames don't work across directories */ /* open-file renames don't work across directories */
if (to_dentry->d_parent != from_dentry->d_parent) if (to_dentry->d_parent != from_dentry->d_parent)
goto do_rename_exit; goto do_rename_exit;
...@@ -2064,6 +2098,7 @@ cifs_do_rename(const unsigned int xid, struct dentry *from_dentry, ...@@ -2064,6 +2098,7 @@ cifs_do_rename(const unsigned int xid, struct dentry *from_dentry,
cifs_sb->local_nls, cifs_remap(cifs_sb)); cifs_sb->local_nls, cifs_remap(cifs_sb));
CIFSSMBClose(xid, tcon, fid.netfid); CIFSSMBClose(xid, tcon, fid.netfid);
} }
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
do_rename_exit: do_rename_exit:
if (rc == 0) if (rc == 0)
d_move(from_dentry, to_dentry); d_move(from_dentry, to_dentry);
...@@ -2081,11 +2116,13 @@ cifs_rename2(struct user_namespace *mnt_userns, struct inode *source_dir, ...@@ -2081,11 +2116,13 @@ cifs_rename2(struct user_namespace *mnt_userns, struct inode *source_dir,
struct cifs_sb_info *cifs_sb; struct cifs_sb_info *cifs_sb;
struct tcon_link *tlink; struct tcon_link *tlink;
struct cifs_tcon *tcon; struct cifs_tcon *tcon;
FILE_UNIX_BASIC_INFO *info_buf_source = NULL;
FILE_UNIX_BASIC_INFO *info_buf_target;
unsigned int xid; unsigned int xid;
int rc, tmprc; int rc, tmprc;
int retry_count = 0; int retry_count = 0;
FILE_UNIX_BASIC_INFO *info_buf_source = NULL;
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
FILE_UNIX_BASIC_INFO *info_buf_target;
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
if (flags & ~RENAME_NOREPLACE) if (flags & ~RENAME_NOREPLACE)
return -EINVAL; return -EINVAL;
...@@ -2139,6 +2176,7 @@ cifs_rename2(struct user_namespace *mnt_userns, struct inode *source_dir, ...@@ -2139,6 +2176,7 @@ cifs_rename2(struct user_namespace *mnt_userns, struct inode *source_dir,
if (flags & RENAME_NOREPLACE) if (flags & RENAME_NOREPLACE)
goto cifs_rename_exit; goto cifs_rename_exit;
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
if (rc == -EEXIST && tcon->unix_ext) { if (rc == -EEXIST && tcon->unix_ext) {
/* /*
* Are src and dst hardlinks of same inode? We can only tell * Are src and dst hardlinks of same inode? We can only tell
...@@ -2178,6 +2216,8 @@ cifs_rename2(struct user_namespace *mnt_userns, struct inode *source_dir, ...@@ -2178,6 +2216,8 @@ cifs_rename2(struct user_namespace *mnt_userns, struct inode *source_dir,
*/ */
unlink_target: unlink_target:
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
/* Try unlinking the target dentry if it's not negative */ /* Try unlinking the target dentry if it's not negative */
if (d_really_is_positive(target_dentry) && (rc == -EACCES || rc == -EEXIST)) { if (d_really_is_positive(target_dentry) && (rc == -EACCES || rc == -EEXIST)) {
if (d_is_dir(target_dentry)) if (d_is_dir(target_dentry))
...@@ -2337,14 +2377,18 @@ int cifs_revalidate_file_attr(struct file *filp) ...@@ -2337,14 +2377,18 @@ int cifs_revalidate_file_attr(struct file *filp)
{ {
int rc = 0; int rc = 0;
struct dentry *dentry = file_dentry(filp); struct dentry *dentry = file_dentry(filp);
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
struct cifsFileInfo *cfile = (struct cifsFileInfo *) filp->private_data; struct cifsFileInfo *cfile = (struct cifsFileInfo *) filp->private_data;
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
if (!cifs_dentry_needs_reval(dentry)) if (!cifs_dentry_needs_reval(dentry))
return rc; return rc;
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
if (tlink_tcon(cfile->tlink)->unix_ext) if (tlink_tcon(cfile->tlink)->unix_ext)
rc = cifs_get_file_info_unix(filp); rc = cifs_get_file_info_unix(filp);
else else
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
rc = cifs_get_file_info(filp); rc = cifs_get_file_info(filp);
return rc; return rc;
...@@ -2653,6 +2697,7 @@ cifs_set_file_size(struct inode *inode, struct iattr *attrs, ...@@ -2653,6 +2697,7 @@ cifs_set_file_size(struct inode *inode, struct iattr *attrs,
return rc; return rc;
} }
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
static int static int
cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs) cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs)
{ {
...@@ -2800,6 +2845,7 @@ cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs) ...@@ -2800,6 +2845,7 @@ cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs)
free_xid(xid); free_xid(xid);
return rc; return rc;
} }
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
static int static int
cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs) cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs)
...@@ -2995,16 +3041,20 @@ cifs_setattr(struct user_namespace *mnt_userns, struct dentry *direntry, ...@@ -2995,16 +3041,20 @@ cifs_setattr(struct user_namespace *mnt_userns, struct dentry *direntry,
struct iattr *attrs) struct iattr *attrs)
{ {
struct cifs_sb_info *cifs_sb = CIFS_SB(direntry->d_sb); struct cifs_sb_info *cifs_sb = CIFS_SB(direntry->d_sb);
struct cifs_tcon *pTcon = cifs_sb_master_tcon(cifs_sb);
int rc, retries = 0; int rc, retries = 0;
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
struct cifs_tcon *pTcon = cifs_sb_master_tcon(cifs_sb);
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
if (unlikely(cifs_forced_shutdown(cifs_sb))) if (unlikely(cifs_forced_shutdown(cifs_sb)))
return -EIO; return -EIO;
do { do {
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
if (pTcon->unix_ext) if (pTcon->unix_ext)
rc = cifs_setattr_unix(direntry, attrs); rc = cifs_setattr_unix(direntry, attrs);
else else
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
rc = cifs_setattr_nounix(direntry, attrs); rc = cifs_setattr_nounix(direntry, attrs);
retries++; retries++;
} while (is_retryable_error(rc) && retries < 2); } while (is_retryable_error(rc) && retries < 2);
......
...@@ -333,6 +333,7 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) ...@@ -333,6 +333,7 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
tcon = tlink_tcon(pSMBFile->tlink); tcon = tlink_tcon(pSMBFile->tlink);
caps = le64_to_cpu(tcon->fsUnixInfo.Capability); caps = le64_to_cpu(tcon->fsUnixInfo.Capability);
#ifdef CONFIG_CIFS_POSIX #ifdef CONFIG_CIFS_POSIX
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
if (CIFS_UNIX_EXTATTR_CAP & caps) { if (CIFS_UNIX_EXTATTR_CAP & caps) {
__u64 ExtAttrMask = 0; __u64 ExtAttrMask = 0;
rc = CIFSGetExtAttr(xid, tcon, rc = CIFSGetExtAttr(xid, tcon,
...@@ -345,6 +346,7 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) ...@@ -345,6 +346,7 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
if (rc != EOPNOTSUPP) if (rc != EOPNOTSUPP)
break; break;
} }
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
#endif /* CONFIG_CIFS_POSIX */ #endif /* CONFIG_CIFS_POSIX */
rc = 0; rc = 0;
if (CIFS_I(inode)->cifsAttrs & ATTR_COMPRESSED) { if (CIFS_I(inode)->cifsAttrs & ATTR_COMPRESSED) {
......
...@@ -286,6 +286,7 @@ check_mf_symlink(unsigned int xid, struct cifs_tcon *tcon, ...@@ -286,6 +286,7 @@ check_mf_symlink(unsigned int xid, struct cifs_tcon *tcon,
return rc; return rc;
} }
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
/* /*
* SMB 1.0 Protocol specific functions * SMB 1.0 Protocol specific functions
*/ */
...@@ -368,6 +369,7 @@ cifs_create_mf_symlink(unsigned int xid, struct cifs_tcon *tcon, ...@@ -368,6 +369,7 @@ cifs_create_mf_symlink(unsigned int xid, struct cifs_tcon *tcon,
CIFSSMBClose(xid, tcon, fid.netfid); CIFSSMBClose(xid, tcon, fid.netfid);
return rc; return rc;
} }
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
/* /*
* SMB 2.1/SMB3 Protocol specific functions * SMB 2.1/SMB3 Protocol specific functions
...@@ -532,11 +534,15 @@ cifs_hardlink(struct dentry *old_file, struct inode *inode, ...@@ -532,11 +534,15 @@ cifs_hardlink(struct dentry *old_file, struct inode *inode,
goto cifs_hl_exit; goto cifs_hl_exit;
} }
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
if (tcon->unix_ext) if (tcon->unix_ext)
rc = CIFSUnixCreateHardLink(xid, tcon, from_name, to_name, rc = CIFSUnixCreateHardLink(xid, tcon, from_name, to_name,
cifs_sb->local_nls, cifs_sb->local_nls,
cifs_remap(cifs_sb)); cifs_remap(cifs_sb));
else { else {
#else
{
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
server = tcon->ses->server; server = tcon->ses->server;
if (!server->ops->create_hardlink) { if (!server->ops->create_hardlink) {
rc = -ENOSYS; rc = -ENOSYS;
...@@ -704,10 +710,12 @@ cifs_symlink(struct user_namespace *mnt_userns, struct inode *inode, ...@@ -704,10 +710,12 @@ cifs_symlink(struct user_namespace *mnt_userns, struct inode *inode,
/* BB what if DFS and this volume is on different share? BB */ /* BB what if DFS and this volume is on different share? BB */
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS) if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS)
rc = create_mf_symlink(xid, pTcon, cifs_sb, full_path, symname); rc = create_mf_symlink(xid, pTcon, cifs_sb, full_path, symname);
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
else if (pTcon->unix_ext) else if (pTcon->unix_ext)
rc = CIFSUnixCreateSymLink(xid, pTcon, full_path, symname, rc = CIFSUnixCreateSymLink(xid, pTcon, full_path, symname,
cifs_sb->local_nls, cifs_sb->local_nls,
cifs_remap(cifs_sb)); cifs_remap(cifs_sb));
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
/* else /* else
rc = CIFSCreateReparseSymLink(xid, pTcon, fromName, toName, rc = CIFSCreateReparseSymLink(xid, pTcon, fromName, toName,
cifs_sb_target->local_nls); */ cifs_sb_target->local_nls); */
......
...@@ -499,6 +499,7 @@ cifs_ses_add_channel(struct cifs_sb_info *cifs_sb, struct cifs_ses *ses, ...@@ -499,6 +499,7 @@ cifs_ses_add_channel(struct cifs_sb_info *cifs_sb, struct cifs_ses *ses,
return rc; return rc;
} }
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
static __u32 cifs_ssetup_hdr(struct cifs_ses *ses, static __u32 cifs_ssetup_hdr(struct cifs_ses *ses,
struct TCP_Server_Info *server, struct TCP_Server_Info *server,
SESSION_SETUP_ANDX *pSMB) SESSION_SETUP_ANDX *pSMB)
...@@ -591,7 +592,6 @@ static void unicode_domain_string(char **pbcc_area, struct cifs_ses *ses, ...@@ -591,7 +592,6 @@ static void unicode_domain_string(char **pbcc_area, struct cifs_ses *ses,
*pbcc_area = bcc_ptr; *pbcc_area = bcc_ptr;
} }
static void unicode_ssetup_strings(char **pbcc_area, struct cifs_ses *ses, static void unicode_ssetup_strings(char **pbcc_area, struct cifs_ses *ses,
const struct nls_table *nls_cp) const struct nls_table *nls_cp)
{ {
...@@ -753,6 +753,7 @@ static void decode_ascii_ssetup(char **pbcc_area, __u16 bleft, ...@@ -753,6 +753,7 @@ static void decode_ascii_ssetup(char **pbcc_area, __u16 bleft,
for it later, but it is not very important */ for it later, but it is not very important */
cifs_dbg(FYI, "ascii: bytes left %d\n", bleft); cifs_dbg(FYI, "ascii: bytes left %d\n", bleft);
} }
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len, int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len,
struct cifs_ses *ses) struct cifs_ses *ses)
...@@ -1170,6 +1171,7 @@ struct sess_data { ...@@ -1170,6 +1171,7 @@ struct sess_data {
struct kvec iov[3]; struct kvec iov[3];
}; };
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
static int static int
sess_alloc_buffer(struct sess_data *sess_data, int wct) sess_alloc_buffer(struct sess_data *sess_data, int wct)
{ {
...@@ -1846,3 +1848,4 @@ int CIFS_SessSetup(const unsigned int xid, struct cifs_ses *ses, ...@@ -1846,3 +1848,4 @@ int CIFS_SessSetup(const unsigned int xid, struct cifs_ses *ses,
kfree(sess_data); kfree(sess_data);
return rc; return rc;
} }
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <asm/processor.h> #include <asm/processor.h>
#include <linux/mempool.h> #include <linux/mempool.h>
#include <linux/sched/signal.h> #include <linux/sched/signal.h>
#include <linux/task_io_accounting_ops.h>
#include "cifspdu.h" #include "cifspdu.h"
#include "cifsglob.h" #include "cifsglob.h"
#include "cifsproto.h" #include "cifsproto.h"
...@@ -1638,3 +1639,181 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon, ...@@ -1638,3 +1639,181 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon,
return -ERESTARTSYS; return -ERESTARTSYS;
return rc; return rc;
} }
/*
* Discard any remaining data in the current SMB. To do this, we borrow the
* current bigbuf.
*/
int
cifs_discard_remaining_data(struct TCP_Server_Info *server)
{
unsigned int rfclen = server->pdu_size;
int remaining = rfclen + server->vals->header_preamble_size -
server->total_read;
while (remaining > 0) {
int length;
length = cifs_discard_from_socket(server,
min_t(size_t, remaining,
CIFSMaxBufSize + MAX_HEADER_SIZE(server)));
if (length < 0)
return length;
server->total_read += length;
remaining -= length;
}
return 0;
}
static int
__cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid,
bool malformed)
{
int length;
length = cifs_discard_remaining_data(server);
dequeue_mid(mid, malformed);
mid->resp_buf = server->smallbuf;
server->smallbuf = NULL;
return length;
}
static int
cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid)
{
struct cifs_readdata *rdata = mid->callback_data;
return __cifs_readv_discard(server, mid, rdata->result);
}
int
cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid)
{
int length, len;
unsigned int data_offset, data_len;
struct cifs_readdata *rdata = mid->callback_data;
char *buf = server->smallbuf;
unsigned int buflen = server->pdu_size +
server->vals->header_preamble_size;
bool use_rdma_mr = false;
cifs_dbg(FYI, "%s: mid=%llu offset=%llu bytes=%u\n",
__func__, mid->mid, rdata->offset, rdata->bytes);
/*
* read the rest of READ_RSP header (sans Data array), or whatever we
* can if there's not enough data. At this point, we've read down to
* the Mid.
*/
len = min_t(unsigned int, buflen, server->vals->read_rsp_size) -
HEADER_SIZE(server) + 1;
length = cifs_read_from_socket(server,
buf + HEADER_SIZE(server) - 1, len);
if (length < 0)
return length;
server->total_read += length;
if (server->ops->is_session_expired &&
server->ops->is_session_expired(buf)) {
cifs_reconnect(server, true);
return -1;
}
if (server->ops->is_status_pending &&
server->ops->is_status_pending(buf, server)) {
cifs_discard_remaining_data(server);
return -1;
}
/* set up first two iov for signature check and to get credits */
rdata->iov[0].iov_base = buf;
rdata->iov[0].iov_len = server->vals->header_preamble_size;
rdata->iov[1].iov_base = buf + server->vals->header_preamble_size;
rdata->iov[1].iov_len =
server->total_read - server->vals->header_preamble_size;
cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
rdata->iov[0].iov_base, rdata->iov[0].iov_len);
cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n",
rdata->iov[1].iov_base, rdata->iov[1].iov_len);
/* Was the SMB read successful? */
rdata->result = server->ops->map_error(buf, false);
if (rdata->result != 0) {
cifs_dbg(FYI, "%s: server returned error %d\n",
__func__, rdata->result);
/* normal error on read response */
return __cifs_readv_discard(server, mid, false);
}
/* Is there enough to get to the rest of the READ_RSP header? */
if (server->total_read < server->vals->read_rsp_size) {
cifs_dbg(FYI, "%s: server returned short header. got=%u expected=%zu\n",
__func__, server->total_read,
server->vals->read_rsp_size);
rdata->result = -EIO;
return cifs_readv_discard(server, mid);
}
data_offset = server->ops->read_data_offset(buf) +
server->vals->header_preamble_size;
if (data_offset < server->total_read) {
/*
* win2k8 sometimes sends an offset of 0 when the read
* is beyond the EOF. Treat it as if the data starts just after
* the header.
*/
cifs_dbg(FYI, "%s: data offset (%u) inside read response header\n",
__func__, data_offset);
data_offset = server->total_read;
} else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
/* data_offset is beyond the end of smallbuf */
cifs_dbg(FYI, "%s: data offset (%u) beyond end of smallbuf\n",
__func__, data_offset);
rdata->result = -EIO;
return cifs_readv_discard(server, mid);
}
cifs_dbg(FYI, "%s: total_read=%u data_offset=%u\n",
__func__, server->total_read, data_offset);
len = data_offset - server->total_read;
if (len > 0) {
/* read any junk before data into the rest of smallbuf */
length = cifs_read_from_socket(server,
buf + server->total_read, len);
if (length < 0)
return length;
server->total_read += length;
}
/* how much data is in the response? */
#ifdef CONFIG_CIFS_SMB_DIRECT
use_rdma_mr = rdata->mr;
#endif
data_len = server->ops->read_data_length(buf, use_rdma_mr);
if (!use_rdma_mr && (data_offset + data_len > buflen)) {
/* data_len is corrupt -- discard frame */
rdata->result = -EIO;
return cifs_readv_discard(server, mid);
}
length = rdata->read_into_pages(server, rdata, data_len);
if (length < 0)
return length;
server->total_read += length;
cifs_dbg(FYI, "total_read=%u buflen=%u remaining=%u\n",
server->total_read, buflen, data_len);
/* discard anything left over */
if (server->total_read < buflen)
return cifs_readv_discard(server, mid);
dequeue_mid(mid, false);
mid->resp_buf = server->smallbuf;
server->smallbuf = NULL;
return length;
}
...@@ -201,6 +201,7 @@ static int cifs_xattr_set(const struct xattr_handler *handler, ...@@ -201,6 +201,7 @@ static int cifs_xattr_set(const struct xattr_handler *handler,
break; break;
} }
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
case XATTR_ACL_ACCESS: case XATTR_ACL_ACCESS:
#ifdef CONFIG_CIFS_POSIX #ifdef CONFIG_CIFS_POSIX
if (!value) if (!value)
...@@ -224,6 +225,7 @@ static int cifs_xattr_set(const struct xattr_handler *handler, ...@@ -224,6 +225,7 @@ static int cifs_xattr_set(const struct xattr_handler *handler,
cifs_remap(cifs_sb)); cifs_remap(cifs_sb));
#endif /* CONFIG_CIFS_POSIX */ #endif /* CONFIG_CIFS_POSIX */
break; break;
#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
} }
out: out:
...@@ -364,7 +366,7 @@ static int cifs_xattr_get(const struct xattr_handler *handler, ...@@ -364,7 +366,7 @@ static int cifs_xattr_get(const struct xattr_handler *handler,
} }
break; break;
} }
#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
case XATTR_ACL_ACCESS: case XATTR_ACL_ACCESS:
#ifdef CONFIG_CIFS_POSIX #ifdef CONFIG_CIFS_POSIX
if (sb->s_flags & SB_POSIXACL) if (sb->s_flags & SB_POSIXACL)
...@@ -384,6 +386,7 @@ static int cifs_xattr_get(const struct xattr_handler *handler, ...@@ -384,6 +386,7 @@ static int cifs_xattr_get(const struct xattr_handler *handler,
cifs_remap(cifs_sb)); cifs_remap(cifs_sb));
#endif /* CONFIG_CIFS_POSIX */ #endif /* CONFIG_CIFS_POSIX */
break; break;
#endif /* ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
} }
/* We could add an additional check for streams ie /* We could add an additional check for streams ie
......
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