Skip to content

Commit d4e9041

Browse files
committed
Merge tag '5.10-rc6-smb3-fixes-part2' of git://git.samba.org/sfrench/cifs-2.6
Pull cifs fixes from Steve French: "Three smb3 fixes (two for stable) fixing - a null pointer issue in a DFS error path - a problem with excessive padding when mounted with "idsfromsid" causing owner fields to get corrupted - a more recent problem with compounded reparse point query found in testing to the Linux kernel server" * tag '5.10-rc6-smb3-fixes-part2' of git://git.samba.org/sfrench/cifs-2.6: cifs: refactor create_sd_buf() and and avoid corrupting the buffer cifs: add NULL check for ses->tcon_ipc smb3: set COMPOUND_FID to FileID field of subsequent compound request
2 parents 312b0bc + ea64370 commit d4e9041

4 files changed

Lines changed: 42 additions & 38 deletions

File tree

fs/cifs/connect.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4546,7 +4546,8 @@ static void set_root_ses(struct cifs_sb_info *cifs_sb, struct cifs_ses *ses,
45464546
if (ses) {
45474547
spin_lock(&cifs_tcp_ses_lock);
45484548
ses->ses_count++;
4549-
ses->tcon_ipc->remap = cifs_remap(cifs_sb);
4549+
if (ses->tcon_ipc)
4550+
ses->tcon_ipc->remap = cifs_remap(cifs_sb);
45504551
spin_unlock(&cifs_tcp_ses_lock);
45514552
}
45524553
*root_ses = ses;

fs/cifs/smb2ops.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3114,8 +3114,8 @@ smb2_query_reparse_tag(const unsigned int xid, struct cifs_tcon *tcon,
31143114
rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
31153115

31163116
rc = SMB2_ioctl_init(tcon, server,
3117-
&rqst[1], fid.persistent_fid,
3118-
fid.volatile_fid, FSCTL_GET_REPARSE_POINT,
3117+
&rqst[1], COMPOUND_FID,
3118+
COMPOUND_FID, FSCTL_GET_REPARSE_POINT,
31193119
true /* is_fctl */, NULL, 0,
31203120
CIFSMaxBufSize -
31213121
MAX_SMB2_CREATE_RESPONSE_SIZE -

fs/cifs/smb2pdu.c

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2272,17 +2272,15 @@ static struct crt_sd_ctxt *
22722272
create_sd_buf(umode_t mode, bool set_owner, unsigned int *len)
22732273
{
22742274
struct crt_sd_ctxt *buf;
2275-
struct cifs_ace *pace;
2276-
unsigned int sdlen, acelen;
2275+
__u8 *ptr, *aclptr;
2276+
unsigned int acelen, acl_size, ace_count;
22772277
unsigned int owner_offset = 0;
22782278
unsigned int group_offset = 0;
2279+
struct smb3_acl acl;
22792280

2280-
*len = roundup(sizeof(struct crt_sd_ctxt) + (sizeof(struct cifs_ace) * 2), 8);
2281+
*len = roundup(sizeof(struct crt_sd_ctxt) + (sizeof(struct cifs_ace) * 4), 8);
22812282

22822283
if (set_owner) {
2283-
/* offset fields are from beginning of security descriptor not of create context */
2284-
owner_offset = sizeof(struct smb3_acl) + (sizeof(struct cifs_ace) * 2);
2285-
22862284
/* sizeof(struct owner_group_sids) is already multiple of 8 so no need to round */
22872285
*len += sizeof(struct owner_group_sids);
22882286
}
@@ -2291,26 +2289,22 @@ create_sd_buf(umode_t mode, bool set_owner, unsigned int *len)
22912289
if (buf == NULL)
22922290
return buf;
22932291

2292+
ptr = (__u8 *)&buf[1];
22942293
if (set_owner) {
2294+
/* offset fields are from beginning of security descriptor not of create context */
2295+
owner_offset = ptr - (__u8 *)&buf->sd;
22952296
buf->sd.OffsetOwner = cpu_to_le32(owner_offset);
2296-
group_offset = owner_offset + sizeof(struct owner_sid);
2297+
group_offset = owner_offset + offsetof(struct owner_group_sids, group);
22972298
buf->sd.OffsetGroup = cpu_to_le32(group_offset);
2299+
2300+
setup_owner_group_sids(ptr);
2301+
ptr += sizeof(struct owner_group_sids);
22982302
} else {
22992303
buf->sd.OffsetOwner = 0;
23002304
buf->sd.OffsetGroup = 0;
23012305
}
23022306

2303-
sdlen = sizeof(struct smb3_sd) + sizeof(struct smb3_acl) +
2304-
2 * sizeof(struct cifs_ace);
2305-
if (set_owner) {
2306-
sdlen += sizeof(struct owner_group_sids);
2307-
setup_owner_group_sids(owner_offset + sizeof(struct create_context) + 8 /* name */
2308-
+ (char *)buf);
2309-
}
2310-
2311-
buf->ccontext.DataOffset = cpu_to_le16(offsetof
2312-
(struct crt_sd_ctxt, sd));
2313-
buf->ccontext.DataLength = cpu_to_le32(sdlen);
2307+
buf->ccontext.DataOffset = cpu_to_le16(offsetof(struct crt_sd_ctxt, sd));
23142308
buf->ccontext.NameOffset = cpu_to_le16(offsetof(struct crt_sd_ctxt, Name));
23152309
buf->ccontext.NameLength = cpu_to_le16(4);
23162310
/* SMB2_CREATE_SD_BUFFER_TOKEN is "SecD" */
@@ -2319,35 +2313,46 @@ create_sd_buf(umode_t mode, bool set_owner, unsigned int *len)
23192313
buf->Name[2] = 'c';
23202314
buf->Name[3] = 'D';
23212315
buf->sd.Revision = 1; /* Must be one see MS-DTYP 2.4.6 */
2316+
23222317
/*
23232318
* ACL is "self relative" ie ACL is stored in contiguous block of memory
23242319
* and "DP" ie the DACL is present
23252320
*/
23262321
buf->sd.Control = cpu_to_le16(ACL_CONTROL_SR | ACL_CONTROL_DP);
23272322

23282323
/* offset owner, group and Sbz1 and SACL are all zero */
2329-
buf->sd.OffsetDacl = cpu_to_le32(sizeof(struct smb3_sd));
2330-
buf->acl.AclRevision = ACL_REVISION; /* See 2.4.4.1 of MS-DTYP */
2324+
buf->sd.OffsetDacl = cpu_to_le32(ptr - (__u8 *)&buf->sd);
2325+
/* Ship the ACL for now. we will copy it into buf later. */
2326+
aclptr = ptr;
2327+
ptr += sizeof(struct cifs_acl);
23312328

23322329
/* create one ACE to hold the mode embedded in reserved special SID */
2333-
pace = (struct cifs_ace *)(sizeof(struct crt_sd_ctxt) + (char *)buf);
2334-
acelen = setup_special_mode_ACE(pace, (__u64)mode);
2330+
acelen = setup_special_mode_ACE((struct cifs_ace *)ptr, (__u64)mode);
2331+
ptr += acelen;
2332+
acl_size = acelen + sizeof(struct smb3_acl);
2333+
ace_count = 1;
23352334

23362335
if (set_owner) {
23372336
/* we do not need to reallocate buffer to add the two more ACEs. plenty of space */
2338-
pace = (struct cifs_ace *)(acelen + (sizeof(struct crt_sd_ctxt) + (char *)buf));
2339-
acelen += setup_special_user_owner_ACE(pace);
2340-
/* it does not appear necessary to add an ACE for the NFS group SID */
2341-
buf->acl.AceCount = cpu_to_le16(3);
2342-
} else
2343-
buf->acl.AceCount = cpu_to_le16(2);
2337+
acelen = setup_special_user_owner_ACE((struct cifs_ace *)ptr);
2338+
ptr += acelen;
2339+
acl_size += acelen;
2340+
ace_count += 1;
2341+
}
23442342

23452343
/* and one more ACE to allow access for authenticated users */
2346-
pace = (struct cifs_ace *)(acelen + (sizeof(struct crt_sd_ctxt) +
2347-
(char *)buf));
2348-
acelen += setup_authusers_ACE(pace);
2349-
2350-
buf->acl.AclSize = cpu_to_le16(sizeof(struct cifs_acl) + acelen);
2344+
acelen = setup_authusers_ACE((struct cifs_ace *)ptr);
2345+
ptr += acelen;
2346+
acl_size += acelen;
2347+
ace_count += 1;
2348+
2349+
acl.AclRevision = ACL_REVISION; /* See 2.4.4.1 of MS-DTYP */
2350+
acl.AclSize = cpu_to_le16(acl_size);
2351+
acl.AceCount = cpu_to_le16(ace_count);
2352+
memcpy(aclptr, &acl, sizeof(struct cifs_acl));
2353+
2354+
buf->ccontext.DataLength = cpu_to_le32(ptr - (__u8 *)&buf->sd);
2355+
*len = ptr - (__u8 *)buf;
23512356

23522357
return buf;
23532358
}

fs/cifs/smb2pdu.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -963,8 +963,6 @@ struct crt_sd_ctxt {
963963
struct create_context ccontext;
964964
__u8 Name[8];
965965
struct smb3_sd sd;
966-
struct smb3_acl acl;
967-
/* Followed by at least 4 ACEs */
968966
} __packed;
969967

970968

0 commit comments

Comments
 (0)