Skip to content

Commit a78f7cd

Browse files
committed
Merge tag '5.5-rc-smb3-fixes-part2' of git://git.samba.org/sfrench/cifs-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
2 parents 5bf9a06 + 231e2a0 commit a78f7cd

File tree

13 files changed

+265
-72
lines changed

13 files changed

+265
-72
lines changed

fs/cifs/cifsacl.c

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,31 @@ static void parse_dacl(struct cifs_acl *pdacl, char *end_of_acl,
802802
return;
803803
}
804804

805+
/*
806+
* Fill in the special SID based on the mode. See
807+
* http://technet.microsoft.com/en-us/library/hh509017(v=ws.10).aspx
808+
*/
809+
unsigned int setup_special_mode_ACE(struct cifs_ace *pntace, __u64 nmode)
810+
{
811+
int i;
812+
unsigned int ace_size = 28;
813+
814+
pntace->type = ACCESS_DENIED_ACE_TYPE;
815+
pntace->flags = 0x0;
816+
pntace->access_req = 0;
817+
pntace->sid.num_subauth = 3;
818+
pntace->sid.revision = 1;
819+
for (i = 0; i < NUM_AUTHS; i++)
820+
pntace->sid.authority[i] = sid_unix_NFS_mode.authority[i];
821+
822+
pntace->sid.sub_auth[0] = sid_unix_NFS_mode.sub_auth[0];
823+
pntace->sid.sub_auth[1] = sid_unix_NFS_mode.sub_auth[1];
824+
pntace->sid.sub_auth[2] = cpu_to_le32(nmode & 07777);
825+
826+
/* size = 1 + 1 + 2 + 4 + 1 + 1 + 6 + (psid->num_subauth*4) */
827+
pntace->size = cpu_to_le16(ace_size);
828+
return ace_size;
829+
}
805830

806831
static int set_chmod_dacl(struct cifs_acl *pndacl, struct cifs_sid *pownersid,
807832
struct cifs_sid *pgrpsid, __u64 nmode, bool modefromsid)
@@ -815,23 +840,8 @@ static int set_chmod_dacl(struct cifs_acl *pndacl, struct cifs_sid *pownersid,
815840
if (modefromsid) {
816841
struct cifs_ace *pntace =
817842
(struct cifs_ace *)((char *)pnndacl + size);
818-
int i;
819843

820-
pntace->type = ACCESS_ALLOWED;
821-
pntace->flags = 0x0;
822-
pntace->access_req = 0;
823-
pntace->sid.num_subauth = 3;
824-
pntace->sid.revision = 1;
825-
for (i = 0; i < NUM_AUTHS; i++)
826-
pntace->sid.authority[i] =
827-
sid_unix_NFS_mode.authority[i];
828-
pntace->sid.sub_auth[0] = sid_unix_NFS_mode.sub_auth[0];
829-
pntace->sid.sub_auth[1] = sid_unix_NFS_mode.sub_auth[1];
830-
pntace->sid.sub_auth[2] = cpu_to_le32(nmode & 07777);
831-
832-
/* size = 1 + 1 + 2 + 4 + 1 + 1 + 6 + (psid->num_subauth*4) */
833-
pntace->size = cpu_to_le16(28);
834-
size += 28;
844+
size += setup_special_mode_ACE(pntace, nmode);
835845
num_aces++;
836846
}
837847

fs/cifs/cifsacl.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -147,22 +147,22 @@ struct smb3_sd {
147147
} __packed;
148148

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

167167
/* Meaning of AclRevision flags */
168168
#define ACL_REVISION 0x02 /* See section 2.4.4.1 of MS-DTYP */

fs/cifs/cifsglob.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,9 @@ struct smb_version_operations {
368368
/* close a file */
369369
void (*close)(const unsigned int, struct cifs_tcon *,
370370
struct cifs_fid *);
371+
/* close a file, returning file attributes and timestamps */
372+
void (*close_getattr)(const unsigned int xid, struct cifs_tcon *tcon,
373+
struct cifsFileInfo *pfile_info);
371374
/* send a flush request to the server */
372375
int (*flush)(const unsigned int, struct cifs_tcon *, struct cifs_fid *);
373376
/* async read from the server */
@@ -774,6 +777,7 @@ struct TCP_Server_Info {
774777
*/
775778
int nr_targets;
776779
bool noblockcnt; /* use non-blocking connect() */
780+
bool is_channel; /* if a session channel */
777781
};
778782

779783
struct cifs_credits {

fs/cifs/cifsproto.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ extern struct cifs_ntsd *get_cifs_acl_by_fid(struct cifs_sb_info *,
213213
const struct cifs_fid *, u32 *);
214214
extern int set_cifs_acl(struct cifs_ntsd *, __u32, struct inode *,
215215
const char *, int);
216+
extern unsigned int setup_special_mode_ACE(struct cifs_ace *pace, __u64 nmode);
216217

217218
extern void dequeue_mid(struct mid_q_entry *mid, bool malformed);
218219
extern int cifs_read_from_socket(struct TCP_Server_Info *server, char *buf,

fs/cifs/connect.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2712,7 +2712,11 @@ cifs_find_tcp_session(struct smb_vol *vol)
27122712

27132713
spin_lock(&cifs_tcp_ses_lock);
27142714
list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
2715-
if (!match_server(server, vol))
2715+
/*
2716+
* Skip ses channels since they're only handled in lower layers
2717+
* (e.g. cifs_send_recv).
2718+
*/
2719+
if (server->is_channel || !match_server(server, vol))
27162720
continue;
27172721

27182722
++server->srv_count;

fs/cifs/file.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,6 @@ cifs_new_fileinfo(struct cifs_fid *fid, struct file *file,
315315
INIT_LIST_HEAD(&fdlocks->locks);
316316
fdlocks->cfile = cfile;
317317
cfile->llist = fdlocks;
318-
cifs_down_write(&cinode->lock_sem);
319-
list_add(&fdlocks->llist, &cinode->llist);
320-
up_write(&cinode->lock_sem);
321318

322319
cfile->count = 1;
323320
cfile->pid = current->tgid;
@@ -342,6 +339,10 @@ cifs_new_fileinfo(struct cifs_fid *fid, struct file *file,
342339
oplock = 0;
343340
}
344341

342+
cifs_down_write(&cinode->lock_sem);
343+
list_add(&fdlocks->llist, &cinode->llist);
344+
up_write(&cinode->lock_sem);
345+
345346
spin_lock(&tcon->open_file_lock);
346347
if (fid->pending_open->oplock != CIFS_OPLOCK_NO_CHANGE && oplock)
347348
oplock = fid->pending_open->oplock;
@@ -495,7 +496,9 @@ void _cifsFileInfo_put(struct cifsFileInfo *cifs_file,
495496
unsigned int xid;
496497

497498
xid = get_xid();
498-
if (server->ops->close)
499+
if (server->ops->close_getattr)
500+
server->ops->close_getattr(xid, tcon, cifs_file);
501+
else if (server->ops->close)
499502
server->ops->close(xid, tcon, &cifs_file->fid);
500503
_free_xid(xid);
501504
}

fs/cifs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr)
163163

164164
spin_lock(&inode->i_lock);
165165
/* we do not want atime to be less than mtime, it broke some apps */
166-
if (timespec64_compare(&fattr->cf_atime, &fattr->cf_mtime))
166+
if (timespec64_compare(&fattr->cf_atime, &fattr->cf_mtime) < 0)
167167
inode->i_atime = fattr->cf_mtime;
168168
else
169169
inode->i_atime = fattr->cf_atime;

fs/cifs/sess.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ int cifs_try_adding_channels(struct cifs_ses *ses)
7777
int i = 0;
7878
int rc = 0;
7979
int tries = 0;
80+
struct cifs_server_iface *ifaces = NULL;
81+
size_t iface_count;
8082

8183
if (left <= 0) {
8284
cifs_dbg(FYI,
@@ -90,6 +92,26 @@ int cifs_try_adding_channels(struct cifs_ses *ses)
9092
return 0;
9193
}
9294

95+
/*
96+
* Make a copy of the iface list at the time and use that
97+
* instead so as to not hold the iface spinlock for opening
98+
* channels
99+
*/
100+
spin_lock(&ses->iface_lock);
101+
iface_count = ses->iface_count;
102+
if (iface_count <= 0) {
103+
spin_unlock(&ses->iface_lock);
104+
cifs_dbg(FYI, "no iface list available to open channels\n");
105+
return 0;
106+
}
107+
ifaces = kmemdup(ses->iface_list, iface_count*sizeof(*ifaces),
108+
GFP_ATOMIC);
109+
if (!ifaces) {
110+
spin_unlock(&ses->iface_lock);
111+
return 0;
112+
}
113+
spin_unlock(&ses->iface_lock);
114+
93115
/*
94116
* Keep connecting to same, fastest, iface for all channels as
95117
* long as its RSS. Try next fastest one if not RSS or channel
@@ -105,17 +127,17 @@ int cifs_try_adding_channels(struct cifs_ses *ses)
105127
break;
106128
}
107129

108-
iface = &ses->iface_list[i];
130+
iface = &ifaces[i];
109131
if (is_ses_using_iface(ses, iface) && !iface->rss_capable) {
110-
i = (i+1) % ses->iface_count;
132+
i = (i+1) % iface_count;
111133
continue;
112134
}
113135

114136
rc = cifs_ses_add_channel(ses, iface);
115137
if (rc) {
116138
cifs_dbg(FYI, "failed to open extra channel on iface#%d rc=%d\n",
117139
i, rc);
118-
i = (i+1) % ses->iface_count;
140+
i = (i+1) % iface_count;
119141
continue;
120142
}
121143

@@ -124,6 +146,7 @@ int cifs_try_adding_channels(struct cifs_ses *ses)
124146
left--;
125147
}
126148

149+
kfree(ifaces);
127150
return ses->chan_count - old_chan_count;
128151
}
129152

@@ -213,6 +236,9 @@ cifs_ses_add_channel(struct cifs_ses *ses, struct cifs_server_iface *iface)
213236
chan->server = NULL;
214237
goto out;
215238
}
239+
spin_lock(&cifs_tcp_ses_lock);
240+
chan->server->is_channel = true;
241+
spin_unlock(&cifs_tcp_ses_lock);
216242

217243
/*
218244
* We need to allocate the server crypto now as we will need

fs/cifs/smb2inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
313313
rqst[num_rqst].rq_iov = close_iov;
314314
rqst[num_rqst].rq_nvec = 1;
315315
rc = SMB2_close_init(tcon, &rqst[num_rqst], COMPOUND_FID,
316-
COMPOUND_FID);
316+
COMPOUND_FID, false);
317317
smb2_set_related(&rqst[num_rqst]);
318318
if (rc)
319319
goto finished;

fs/cifs/smb2ops.c

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
11781178
memset(&close_iov, 0, sizeof(close_iov));
11791179
rqst[2].rq_iov = close_iov;
11801180
rqst[2].rq_nvec = 1;
1181-
rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID);
1181+
rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
11821182
smb2_set_related(&rqst[2]);
11831183

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

1335+
static void
1336+
smb2_close_getattr(const unsigned int xid, struct cifs_tcon *tcon,
1337+
struct cifsFileInfo *cfile)
1338+
{
1339+
struct smb2_file_network_open_info file_inf;
1340+
struct inode *inode;
1341+
int rc;
1342+
1343+
rc = __SMB2_close(xid, tcon, cfile->fid.persistent_fid,
1344+
cfile->fid.volatile_fid, &file_inf);
1345+
if (rc)
1346+
return;
1347+
1348+
inode = d_inode(cfile->dentry);
1349+
1350+
spin_lock(&inode->i_lock);
1351+
CIFS_I(inode)->time = jiffies;
1352+
1353+
/* Creation time should not need to be updated on close */
1354+
if (file_inf.LastWriteTime)
1355+
inode->i_mtime = cifs_NTtimeToUnix(file_inf.LastWriteTime);
1356+
if (file_inf.ChangeTime)
1357+
inode->i_ctime = cifs_NTtimeToUnix(file_inf.ChangeTime);
1358+
if (file_inf.LastAccessTime)
1359+
inode->i_atime = cifs_NTtimeToUnix(file_inf.LastAccessTime);
1360+
1361+
/*
1362+
* i_blocks is not related to (i_size / i_blksize),
1363+
* but instead 512 byte (2**9) size is required for
1364+
* calculating num blocks.
1365+
*/
1366+
if (le64_to_cpu(file_inf.AllocationSize) > 4096)
1367+
inode->i_blocks =
1368+
(512 - 1 + le64_to_cpu(file_inf.AllocationSize)) >> 9;
1369+
1370+
/* End of file and Attributes should not have to be updated on close */
1371+
spin_unlock(&inode->i_lock);
1372+
}
1373+
13351374
static int
13361375
SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
13371376
u64 persistent_fid, u64 volatile_fid,
@@ -1512,7 +1551,7 @@ smb2_ioctl_query_info(const unsigned int xid,
15121551
rqst[2].rq_iov = close_iov;
15131552
rqst[2].rq_nvec = 1;
15141553

1515-
rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID);
1554+
rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
15161555
if (rc)
15171556
goto iqinf_exit;
15181557
smb2_set_related(&rqst[2]);
@@ -2241,7 +2280,7 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
22412280
rqst[2].rq_iov = close_iov;
22422281
rqst[2].rq_nvec = 1;
22432282

2244-
rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID);
2283+
rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
22452284
if (rc)
22462285
goto qic_exit;
22472286
smb2_set_related(&rqst[2]);
@@ -2654,7 +2693,7 @@ smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
26542693
rqst[2].rq_iov = close_iov;
26552694
rqst[2].rq_nvec = 1;
26562695

2657-
rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID);
2696+
rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID, false);
26582697
if (rc)
26592698
goto querty_exit;
26602699

@@ -4707,6 +4746,7 @@ struct smb_version_operations smb30_operations = {
47074746
.open = smb2_open_file,
47084747
.set_fid = smb2_set_fid,
47094748
.close = smb2_close_file,
4749+
.close_getattr = smb2_close_getattr,
47104750
.flush = smb2_flush_file,
47114751
.async_readv = smb2_async_readv,
47124752
.async_writev = smb2_async_writev,
@@ -4816,6 +4856,7 @@ struct smb_version_operations smb311_operations = {
48164856
.open = smb2_open_file,
48174857
.set_fid = smb2_set_fid,
48184858
.close = smb2_close_file,
4859+
.close_getattr = smb2_close_getattr,
48194860
.flush = smb2_flush_file,
48204861
.async_readv = smb2_async_readv,
48214862
.async_writev = smb2_async_writev,

0 commit comments

Comments
 (0)