Skip to content

Commit

Permalink
Merge tag '5.5-rc-smb3-fixes-part2' of git://git.samba.org/sfrench/ci…
Browse files Browse the repository at this point in the history
…fs-2.6

Pull cifs fixes from Steve French:
 "Nine cifs/smb3 fixes:

   - one fix for stable (oops during oplock break)

   - two timestamp fixes including important one for updating mtime at
     close to avoid stale metadata caching issue on dirty files (also
     improves perf by using SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB over the
     wire)

   - two fixes for "modefromsid" mount option for file create (now
     allows mode bits to be set more atomically and accurately on create
     by adding "sd_context" on create when modefromsid specified on
     mount)

   - two fixes for multichannel found in testing this week against
     different servers

   - two small cleanup patches"

* tag '5.5-rc-smb3-fixes-part2' of git://git.samba.org/sfrench/cifs-2.6:
  smb3: improve check for when we send the security descriptor context on create
  smb3: fix mode passed in on create for modetosid mount option
  cifs: fix possible uninitialized access and race on iface_list
  cifs: Fix lookup of SMB connections on multichannel
  smb3: query attributes on file close
  smb3: remove unused flag passed into close functions
  cifs: remove redundant assignment to pointer pneg_ctxt
  fs: cifs: Fix atime update check vs mtime
  CIFS: Fix NULL-pointer dereference in smb2_push_mandatory_locks
  • Loading branch information
torvalds committed Dec 8, 2019
2 parents 5bf9a06 + 231e2a0 commit a78f7cd
Show file tree
Hide file tree
Showing 13 changed files with 265 additions and 72 deletions.
42 changes: 26 additions & 16 deletions fs/cifs/cifsacl.c
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,31 @@ static void parse_dacl(struct cifs_acl *pdacl, char *end_of_acl,
return;
}

/*
* Fill in the special SID based on the mode. See
* http://technet.microsoft.com/en-us/library/hh509017(v=ws.10).aspx
*/
unsigned int setup_special_mode_ACE(struct cifs_ace *pntace, __u64 nmode)
{
int i;
unsigned int ace_size = 28;

pntace->type = ACCESS_DENIED_ACE_TYPE;
pntace->flags = 0x0;
pntace->access_req = 0;
pntace->sid.num_subauth = 3;
pntace->sid.revision = 1;
for (i = 0; i < NUM_AUTHS; i++)
pntace->sid.authority[i] = sid_unix_NFS_mode.authority[i];

pntace->sid.sub_auth[0] = sid_unix_NFS_mode.sub_auth[0];
pntace->sid.sub_auth[1] = sid_unix_NFS_mode.sub_auth[1];
pntace->sid.sub_auth[2] = cpu_to_le32(nmode & 07777);

/* size = 1 + 1 + 2 + 4 + 1 + 1 + 6 + (psid->num_subauth*4) */
pntace->size = cpu_to_le16(ace_size);
return ace_size;
}

static int set_chmod_dacl(struct cifs_acl *pndacl, struct cifs_sid *pownersid,
struct cifs_sid *pgrpsid, __u64 nmode, bool modefromsid)
Expand All @@ -815,23 +840,8 @@ static int set_chmod_dacl(struct cifs_acl *pndacl, struct cifs_sid *pownersid,
if (modefromsid) {
struct cifs_ace *pntace =
(struct cifs_ace *)((char *)pnndacl + size);
int i;

pntace->type = ACCESS_ALLOWED;
pntace->flags = 0x0;
pntace->access_req = 0;
pntace->sid.num_subauth = 3;
pntace->sid.revision = 1;
for (i = 0; i < NUM_AUTHS; i++)
pntace->sid.authority[i] =
sid_unix_NFS_mode.authority[i];
pntace->sid.sub_auth[0] = sid_unix_NFS_mode.sub_auth[0];
pntace->sid.sub_auth[1] = sid_unix_NFS_mode.sub_auth[1];
pntace->sid.sub_auth[2] = cpu_to_le32(nmode & 07777);

/* size = 1 + 1 + 2 + 4 + 1 + 1 + 6 + (psid->num_subauth*4) */
pntace->size = cpu_to_le16(28);
size += 28;
size += setup_special_mode_ACE(pntace, nmode);
num_aces++;
}

Expand Down
32 changes: 16 additions & 16 deletions fs/cifs/cifsacl.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,22 +147,22 @@ struct smb3_sd {
} __packed;

/* Meaning of 'Control' field flags */
#define ACL_CONTROL_SR 0x0001 /* Self relative */
#define ACL_CONTROL_RM 0x0002 /* Resource manager control bits */
#define ACL_CONTROL_PS 0x0004 /* SACL protected from inherits */
#define ACL_CONTROL_PD 0x0008 /* DACL protected from inherits */
#define ACL_CONTROL_SI 0x0010 /* SACL Auto-Inherited */
#define ACL_CONTROL_DI 0x0020 /* DACL Auto-Inherited */
#define ACL_CONTROL_SC 0x0040 /* SACL computed through inheritance */
#define ACL_CONTROL_DC 0x0080 /* DACL computed through inheritence */
#define ACL_CONTROL_SS 0x0100 /* Create server ACL */
#define ACL_CONTROL_DT 0x0200 /* DACL provided by trusteed source */
#define ACL_CONTROL_SD 0x0400 /* SACL defaulted */
#define ACL_CONTROL_SP 0x0800 /* SACL is present on object */
#define ACL_CONTROL_DD 0x1000 /* DACL defaulted */
#define ACL_CONTROL_DP 0x2000 /* DACL is present on object */
#define ACL_CONTROL_GD 0x4000 /* Group was defaulted */
#define ACL_CONTROL_OD 0x8000 /* User was defaulted */
#define ACL_CONTROL_SR 0x8000 /* Self relative */
#define ACL_CONTROL_RM 0x4000 /* Resource manager control bits */
#define ACL_CONTROL_PS 0x2000 /* SACL protected from inherits */
#define ACL_CONTROL_PD 0x1000 /* DACL protected from inherits */
#define ACL_CONTROL_SI 0x0800 /* SACL Auto-Inherited */
#define ACL_CONTROL_DI 0x0400 /* DACL Auto-Inherited */
#define ACL_CONTROL_SC 0x0200 /* SACL computed through inheritance */
#define ACL_CONTROL_DC 0x0100 /* DACL computed through inheritence */
#define ACL_CONTROL_SS 0x0080 /* Create server ACL */
#define ACL_CONTROL_DT 0x0040 /* DACL provided by trusted source */
#define ACL_CONTROL_SD 0x0020 /* SACL defaulted */
#define ACL_CONTROL_SP 0x0010 /* SACL is present on object */
#define ACL_CONTROL_DD 0x0008 /* DACL defaulted */
#define ACL_CONTROL_DP 0x0004 /* DACL is present on object */
#define ACL_CONTROL_GD 0x0002 /* Group was defaulted */
#define ACL_CONTROL_OD 0x0001 /* User was defaulted */

/* Meaning of AclRevision flags */
#define ACL_REVISION 0x02 /* See section 2.4.4.1 of MS-DTYP */
Expand Down
4 changes: 4 additions & 0 deletions fs/cifs/cifsglob.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@ struct smb_version_operations {
/* close a file */
void (*close)(const unsigned int, struct cifs_tcon *,
struct cifs_fid *);
/* close a file, returning file attributes and timestamps */
void (*close_getattr)(const unsigned int xid, struct cifs_tcon *tcon,
struct cifsFileInfo *pfile_info);
/* send a flush request to the server */
int (*flush)(const unsigned int, struct cifs_tcon *, struct cifs_fid *);
/* async read from the server */
Expand Down Expand Up @@ -774,6 +777,7 @@ struct TCP_Server_Info {
*/
int nr_targets;
bool noblockcnt; /* use non-blocking connect() */
bool is_channel; /* if a session channel */
};

struct cifs_credits {
Expand Down
1 change: 1 addition & 0 deletions fs/cifs/cifsproto.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ extern struct cifs_ntsd *get_cifs_acl_by_fid(struct cifs_sb_info *,
const struct cifs_fid *, u32 *);
extern int set_cifs_acl(struct cifs_ntsd *, __u32, struct inode *,
const char *, int);
extern unsigned int setup_special_mode_ACE(struct cifs_ace *pace, __u64 nmode);

extern void dequeue_mid(struct mid_q_entry *mid, bool malformed);
extern int cifs_read_from_socket(struct TCP_Server_Info *server, char *buf,
Expand Down
6 changes: 5 additions & 1 deletion fs/cifs/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -2712,7 +2712,11 @@ cifs_find_tcp_session(struct smb_vol *vol)

spin_lock(&cifs_tcp_ses_lock);
list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
if (!match_server(server, vol))
/*
* Skip ses channels since they're only handled in lower layers
* (e.g. cifs_send_recv).
*/
if (server->is_channel || !match_server(server, vol))
continue;

++server->srv_count;
Expand Down
11 changes: 7 additions & 4 deletions fs/cifs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,6 @@ cifs_new_fileinfo(struct cifs_fid *fid, struct file *file,
INIT_LIST_HEAD(&fdlocks->locks);
fdlocks->cfile = cfile;
cfile->llist = fdlocks;
cifs_down_write(&cinode->lock_sem);
list_add(&fdlocks->llist, &cinode->llist);
up_write(&cinode->lock_sem);

cfile->count = 1;
cfile->pid = current->tgid;
Expand All @@ -342,6 +339,10 @@ cifs_new_fileinfo(struct cifs_fid *fid, struct file *file,
oplock = 0;
}

cifs_down_write(&cinode->lock_sem);
list_add(&fdlocks->llist, &cinode->llist);
up_write(&cinode->lock_sem);

spin_lock(&tcon->open_file_lock);
if (fid->pending_open->oplock != CIFS_OPLOCK_NO_CHANGE && oplock)
oplock = fid->pending_open->oplock;
Expand Down Expand Up @@ -495,7 +496,9 @@ void _cifsFileInfo_put(struct cifsFileInfo *cifs_file,
unsigned int xid;

xid = get_xid();
if (server->ops->close)
if (server->ops->close_getattr)
server->ops->close_getattr(xid, tcon, cifs_file);
else if (server->ops->close)
server->ops->close(xid, tcon, &cifs_file->fid);
_free_xid(xid);
}
Expand Down
2 changes: 1 addition & 1 deletion fs/cifs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr)

spin_lock(&inode->i_lock);
/* we do not want atime to be less than mtime, it broke some apps */
if (timespec64_compare(&fattr->cf_atime, &fattr->cf_mtime))
if (timespec64_compare(&fattr->cf_atime, &fattr->cf_mtime) < 0)
inode->i_atime = fattr->cf_mtime;
else
inode->i_atime = fattr->cf_atime;
Expand Down
32 changes: 29 additions & 3 deletions fs/cifs/sess.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ int cifs_try_adding_channels(struct cifs_ses *ses)
int i = 0;
int rc = 0;
int tries = 0;
struct cifs_server_iface *ifaces = NULL;
size_t iface_count;

if (left <= 0) {
cifs_dbg(FYI,
Expand All @@ -90,6 +92,26 @@ int cifs_try_adding_channels(struct cifs_ses *ses)
return 0;
}

/*
* Make a copy of the iface list at the time and use that
* instead so as to not hold the iface spinlock for opening
* channels
*/
spin_lock(&ses->iface_lock);
iface_count = ses->iface_count;
if (iface_count <= 0) {
spin_unlock(&ses->iface_lock);
cifs_dbg(FYI, "no iface list available to open channels\n");
return 0;
}
ifaces = kmemdup(ses->iface_list, iface_count*sizeof(*ifaces),
GFP_ATOMIC);
if (!ifaces) {
spin_unlock(&ses->iface_lock);
return 0;
}
spin_unlock(&ses->iface_lock);

/*
* Keep connecting to same, fastest, iface for all channels as
* long as its RSS. Try next fastest one if not RSS or channel
Expand All @@ -105,17 +127,17 @@ int cifs_try_adding_channels(struct cifs_ses *ses)
break;
}

iface = &ses->iface_list[i];
iface = &ifaces[i];
if (is_ses_using_iface(ses, iface) && !iface->rss_capable) {
i = (i+1) % ses->iface_count;
i = (i+1) % iface_count;
continue;
}

rc = cifs_ses_add_channel(ses, iface);
if (rc) {
cifs_dbg(FYI, "failed to open extra channel on iface#%d rc=%d\n",
i, rc);
i = (i+1) % ses->iface_count;
i = (i+1) % iface_count;
continue;
}

Expand All @@ -124,6 +146,7 @@ int cifs_try_adding_channels(struct cifs_ses *ses)
left--;
}

kfree(ifaces);
return ses->chan_count - old_chan_count;
}

Expand Down Expand Up @@ -213,6 +236,9 @@ cifs_ses_add_channel(struct cifs_ses *ses, struct cifs_server_iface *iface)
chan->server = NULL;
goto out;
}
spin_lock(&cifs_tcp_ses_lock);
chan->server->is_channel = true;
spin_unlock(&cifs_tcp_ses_lock);

/*
* We need to allocate the server crypto now as we will need
Expand Down
2 changes: 1 addition & 1 deletion fs/cifs/smb2inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
rqst[num_rqst].rq_iov = close_iov;
rqst[num_rqst].rq_nvec = 1;
rc = SMB2_close_init(tcon, &rqst[num_rqst], COMPOUND_FID,
COMPOUND_FID);
COMPOUND_FID, false);
smb2_set_related(&rqst[num_rqst]);
if (rc)
goto finished;
Expand Down
49 changes: 45 additions & 4 deletions fs/cifs/smb2ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
memset(&close_iov, 0, sizeof(close_iov));
rqst[2].rq_iov = close_iov;
rqst[2].rq_nvec = 1;
rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID);
rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
smb2_set_related(&rqst[2]);

rc = compound_send_recv(xid, ses, flags, 3, rqst,
Expand Down Expand Up @@ -1332,6 +1332,45 @@ smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
}

static void
smb2_close_getattr(const unsigned int xid, struct cifs_tcon *tcon,
struct cifsFileInfo *cfile)
{
struct smb2_file_network_open_info file_inf;
struct inode *inode;
int rc;

rc = __SMB2_close(xid, tcon, cfile->fid.persistent_fid,
cfile->fid.volatile_fid, &file_inf);
if (rc)
return;

inode = d_inode(cfile->dentry);

spin_lock(&inode->i_lock);
CIFS_I(inode)->time = jiffies;

/* Creation time should not need to be updated on close */
if (file_inf.LastWriteTime)
inode->i_mtime = cifs_NTtimeToUnix(file_inf.LastWriteTime);
if (file_inf.ChangeTime)
inode->i_ctime = cifs_NTtimeToUnix(file_inf.ChangeTime);
if (file_inf.LastAccessTime)
inode->i_atime = cifs_NTtimeToUnix(file_inf.LastAccessTime);

/*
* i_blocks is not related to (i_size / i_blksize),
* but instead 512 byte (2**9) size is required for
* calculating num blocks.
*/
if (le64_to_cpu(file_inf.AllocationSize) > 4096)
inode->i_blocks =
(512 - 1 + le64_to_cpu(file_inf.AllocationSize)) >> 9;

/* End of file and Attributes should not have to be updated on close */
spin_unlock(&inode->i_lock);
}

static int
SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
u64 persistent_fid, u64 volatile_fid,
Expand Down Expand Up @@ -1512,7 +1551,7 @@ smb2_ioctl_query_info(const unsigned int xid,
rqst[2].rq_iov = close_iov;
rqst[2].rq_nvec = 1;

rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID);
rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
if (rc)
goto iqinf_exit;
smb2_set_related(&rqst[2]);
Expand Down Expand Up @@ -2241,7 +2280,7 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
rqst[2].rq_iov = close_iov;
rqst[2].rq_nvec = 1;

rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID);
rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
if (rc)
goto qic_exit;
smb2_set_related(&rqst[2]);
Expand Down Expand Up @@ -2654,7 +2693,7 @@ smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
rqst[2].rq_iov = close_iov;
rqst[2].rq_nvec = 1;

rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID);
rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
if (rc)
goto querty_exit;

Expand Down Expand Up @@ -4707,6 +4746,7 @@ struct smb_version_operations smb30_operations = {
.open = smb2_open_file,
.set_fid = smb2_set_fid,
.close = smb2_close_file,
.close_getattr = smb2_close_getattr,
.flush = smb2_flush_file,
.async_readv = smb2_async_readv,
.async_writev = smb2_async_writev,
Expand Down Expand Up @@ -4816,6 +4856,7 @@ struct smb_version_operations smb311_operations = {
.open = smb2_open_file,
.set_fid = smb2_set_fid,
.close = smb2_close_file,
.close_getattr = smb2_close_getattr,
.flush = smb2_flush_file,
.async_readv = smb2_async_readv,
.async_writev = smb2_async_writev,
Expand Down
Loading

0 comments on commit a78f7cd

Please sign in to comment.