Skip to content

Commit fdef665

Browse files
committed
smb3: fix mode passed in on create for modetosid mount option
When using the special SID to store the mode bits in an ACE (See http://technet.microsoft.com/en-us/library/hh509017(v=ws.10).aspx) which is enabled with mount parm "modefromsid" we were not passing in the mode via SMB3 create (although chmod was enabled). SMB3 create allows a security descriptor context to be passed in (which is more atomic and thus preferable to setting the mode bits after create via a setinfo). This patch enables setting the mode bits on create when using modefromsid mount option. In addition it fixes an endian error in the definition of the Control field flags in the SMB3 security descriptor. It also makes the ACE type of the special SID better match the documentation (and behavior of servers which use this to store mode bits in SMB3 ACLs). Signed-off-by: Steve French <[email protected]> Acked-by: Ronnie Sahlberg <[email protected]> Reviewed-by: Pavel Shilovsky <[email protected]>
1 parent 9a7d5a9 commit fdef665

File tree

5 files changed

+122
-34
lines changed

5 files changed

+122
-34
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/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/smb2pdu.c

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2191,6 +2191,72 @@ add_twarp_context(struct kvec *iov, unsigned int *num_iovec, __u64 timewarp)
21912191
return 0;
21922192
}
21932193

2194+
/* See MS-SMB2 2.2.13.2.2 and MS-DTYP 2.4.6 */
2195+
static struct crt_sd_ctxt *
2196+
create_sd_buf(umode_t mode, unsigned int *len)
2197+
{
2198+
struct crt_sd_ctxt *buf;
2199+
struct cifs_ace *pace;
2200+
unsigned int sdlen, acelen;
2201+
2202+
*len = roundup(sizeof(struct crt_sd_ctxt) + sizeof(struct cifs_ace), 8);
2203+
buf = kzalloc(*len, GFP_KERNEL);
2204+
if (buf == NULL)
2205+
return buf;
2206+
2207+
sdlen = sizeof(struct smb3_sd) + sizeof(struct smb3_acl) +
2208+
sizeof(struct cifs_ace);
2209+
2210+
buf->ccontext.DataOffset = cpu_to_le16(offsetof
2211+
(struct crt_sd_ctxt, sd));
2212+
buf->ccontext.DataLength = cpu_to_le32(sdlen);
2213+
buf->ccontext.NameOffset = cpu_to_le16(offsetof
2214+
(struct crt_sd_ctxt, Name));
2215+
buf->ccontext.NameLength = cpu_to_le16(4);
2216+
/* SMB2_CREATE_SD_BUFFER_TOKEN is "SecD" */
2217+
buf->Name[0] = 'S';
2218+
buf->Name[1] = 'e';
2219+
buf->Name[2] = 'c';
2220+
buf->Name[3] = 'D';
2221+
buf->sd.Revision = 1; /* Must be one see MS-DTYP 2.4.6 */
2222+
/*
2223+
* ACL is "self relative" ie ACL is stored in contiguous block of memory
2224+
* and "DP" ie the DACL is present
2225+
*/
2226+
buf->sd.Control = cpu_to_le16(ACL_CONTROL_SR | ACL_CONTROL_DP);
2227+
2228+
/* offset owner, group and Sbz1 and SACL are all zero */
2229+
buf->sd.OffsetDacl = cpu_to_le32(sizeof(struct smb3_sd));
2230+
buf->acl.AclRevision = ACL_REVISION; /* See 2.4.4.1 of MS-DTYP */
2231+
2232+
/* create one ACE to hold the mode embedded in reserved special SID */
2233+
pace = (struct cifs_ace *)(sizeof(struct crt_sd_ctxt) + (char *)buf);
2234+
acelen = setup_special_mode_ACE(pace, (__u64)mode);
2235+
buf->acl.AclSize = cpu_to_le16(sizeof(struct cifs_acl) + acelen);
2236+
buf->acl.AceCount = cpu_to_le16(1);
2237+
return buf;
2238+
}
2239+
2240+
static int
2241+
add_sd_context(struct kvec *iov, unsigned int *num_iovec, umode_t mode)
2242+
{
2243+
struct smb2_create_req *req = iov[0].iov_base;
2244+
unsigned int num = *num_iovec;
2245+
unsigned int len = 0;
2246+
2247+
iov[num].iov_base = create_sd_buf(mode, &len);
2248+
if (iov[num].iov_base == NULL)
2249+
return -ENOMEM;
2250+
iov[num].iov_len = len;
2251+
if (!req->CreateContextsOffset)
2252+
req->CreateContextsOffset = cpu_to_le32(
2253+
sizeof(struct smb2_create_req) +
2254+
iov[num - 1].iov_len);
2255+
le32_add_cpu(&req->CreateContextsLength, len);
2256+
*num_iovec = num + 1;
2257+
return 0;
2258+
}
2259+
21942260
static struct crt_query_id_ctxt *
21952261
create_query_id_buf(void)
21962262
{
@@ -2563,7 +2629,7 @@ SMB2_open_init(struct cifs_tcon *tcon, struct smb_rqst *rqst, __u8 *oplock,
25632629
return rc;
25642630
}
25652631

2566-
if ((oparms->disposition == FILE_CREATE) &&
2632+
if ((oparms->disposition != FILE_OPEN) &&
25672633
(oparms->mode != ACL_NO_MODE)) {
25682634
if (n_iov > 2) {
25692635
struct create_context *ccontext =
@@ -2572,7 +2638,8 @@ SMB2_open_init(struct cifs_tcon *tcon, struct smb_rqst *rqst, __u8 *oplock,
25722638
cpu_to_le32(iov[n_iov-1].iov_len);
25732639
}
25742640

2575-
/* rc = add_sd_context(iov, &n_iov, oparms->mode); */
2641+
cifs_dbg(FYI, "add sd with mode 0x%x\n", oparms->mode);
2642+
rc = add_sd_context(iov, &n_iov, oparms->mode);
25762643
if (rc)
25772644
return rc;
25782645
}

fs/cifs/smb2pdu.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#define _SMB2PDU_H
2626

2727
#include <net/sock.h>
28+
#include <cifsacl.h>
2829

2930
/*
3031
* Note that, due to trying to use names similar to the protocol specifications,
@@ -855,6 +856,15 @@ struct crt_query_id_ctxt {
855856
__u8 Name[8];
856857
} __packed;
857858

859+
struct crt_sd_ctxt {
860+
struct create_context ccontext;
861+
__u8 Name[8];
862+
struct smb3_sd sd;
863+
struct smb3_acl acl;
864+
/* Followed by at least 4 ACEs */
865+
} __packed;
866+
867+
858868
#define COPY_CHUNK_RES_KEY_SIZE 24
859869
struct resume_key_req {
860870
char ResumeKey[COPY_CHUNK_RES_KEY_SIZE];

0 commit comments

Comments
 (0)