Skip to content

Commit 643fbce

Browse files
committed
smb3: fix default permissions on new files when mounting with modefromsid
When mounting with "modefromsid" mount parm most servers will require that some default permissions are given to users in the ACL on newly created files, files created with the new 'sd context' - when passing in an sd context on create, permissions are not inherited from the parent directory, so in addition to the ACE with the special SID which contains the mode, we also must pass in an ACE allowing users to access the file (GENERIC_ALL for authenticated users seemed like a reasonable default, although later we could allow a mount option or config switch to make it GENERIC_ALL for EVERYONE special sid). CC: Stable <[email protected]> Signed-off-by: Steve French <[email protected]> Reviewed-By: Ronnie Sahlberg <[email protected]> Reviewed-by: Pavel Shilovsky <[email protected]>
1 parent 438471b commit 643fbce

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

fs/cifs/cifsacl.c

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

805+
unsigned int setup_authusers_ACE(struct cifs_ace *pntace)
806+
{
807+
int i;
808+
unsigned int ace_size = 20;
809+
810+
pntace->type = ACCESS_ALLOWED_ACE_TYPE;
811+
pntace->flags = 0x0;
812+
pntace->access_req = cpu_to_le32(GENERIC_ALL);
813+
pntace->sid.num_subauth = 1;
814+
pntace->sid.revision = 1;
815+
for (i = 0; i < NUM_AUTHS; i++)
816+
pntace->sid.authority[i] = sid_authusers.authority[i];
817+
818+
pntace->sid.sub_auth[0] = sid_authusers.sub_auth[0];
819+
820+
/* size = 1 + 1 + 2 + 4 + 1 + 1 + 6 + (psid->num_subauth*4) */
821+
pntace->size = cpu_to_le16(ace_size);
822+
return ace_size;
823+
}
824+
805825
/*
806826
* Fill in the special SID based on the mode. See
807827
* http://technet.microsoft.com/en-us/library/hh509017(v=ws.10).aspx

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_authusers_ACE(struct cifs_ace *pace);
216217
extern unsigned int setup_special_mode_ACE(struct cifs_ace *pace, __u64 nmode);
217218

218219
extern void dequeue_mid(struct mid_q_entry *mid, bool malformed);

fs/cifs/smb2pdu.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,13 +2199,14 @@ create_sd_buf(umode_t mode, unsigned int *len)
21992199
struct cifs_ace *pace;
22002200
unsigned int sdlen, acelen;
22012201

2202-
*len = roundup(sizeof(struct crt_sd_ctxt) + sizeof(struct cifs_ace), 8);
2202+
*len = roundup(sizeof(struct crt_sd_ctxt) + sizeof(struct cifs_ace) * 2,
2203+
8);
22032204
buf = kzalloc(*len, GFP_KERNEL);
22042205
if (buf == NULL)
22052206
return buf;
22062207

22072208
sdlen = sizeof(struct smb3_sd) + sizeof(struct smb3_acl) +
2208-
sizeof(struct cifs_ace);
2209+
2 * sizeof(struct cifs_ace);
22092210

22102211
buf->ccontext.DataOffset = cpu_to_le16(offsetof
22112212
(struct crt_sd_ctxt, sd));
@@ -2232,8 +2233,12 @@ create_sd_buf(umode_t mode, unsigned int *len)
22322233
/* create one ACE to hold the mode embedded in reserved special SID */
22332234
pace = (struct cifs_ace *)(sizeof(struct crt_sd_ctxt) + (char *)buf);
22342235
acelen = setup_special_mode_ACE(pace, (__u64)mode);
2236+
/* and one more ACE to allow access for authenticated users */
2237+
pace = (struct cifs_ace *)(acelen + (sizeof(struct crt_sd_ctxt) +
2238+
(char *)buf));
2239+
acelen += setup_authusers_ACE(pace);
22352240
buf->acl.AclSize = cpu_to_le16(sizeof(struct cifs_acl) + acelen);
2236-
buf->acl.AceCount = cpu_to_le16(1);
2241+
buf->acl.AceCount = cpu_to_le16(2);
22372242
return buf;
22382243
}
22392244

0 commit comments

Comments
 (0)