cifs: modefromsid: make room for 4 ACE
Subsystems (2)
PATCH 1/2 cifs: modefromsid: make room for 4 ACE
when mounting with modefromsid, we end up writing 4 ACE in a security descriptor that only has room for 3, thus triggering an out-of-bounds write. fix this by changing the min size of a security descriptor.
Signed-off-by Aurelien Aptel <[email protected]>
--- fs/cifs/cifsacl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cifs/cifsacl.h +1 -1
@@ -45,7 +45,7 @@*/ #define DEFAULT_SEC_DESC_LEN (sizeof(struct cifs_ntsd) + \ sizeof(struct cifs_acl) + \ - (sizeof(struct cifs_ace) * 3)) + (sizeof(struct cifs_ace) * 4))/* * Maximum size of a string representation of a SID:
Signature · 1 line
2.16.4
PATCH 2/2 cifs: modefromsid: write mode ACE with DENY first
DACL should start with denying ACE first but we are putting it at the end. reorder them to put it first.
Signed-off-by Aurelien Aptel <[email protected]>
--- fs/cifs/cifsacl.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-)
fs/cifs/cifsacl.c +14 -10
@@ -809,17 +809,11 @@ static int set_chmod_dacl(struct cifs_acl *pndacl, struct cifs_sid *pownersid, struct cifs_sid *pgrpsid, __u64 nmode, bool modefromsid) { u16 size = 0; +u32 num_aces =0 ;struct cifs_acl *pnndacl; pnndacl = (struct cifs_acl *)((char *)pndacl +sizeof (struct cifs_acl )); - size +=fill_ace_for_sid ((struct cifs_ace *) ((char *)pnndacl + size), - pownersid, nmode,S_IRWXU ); - size +=fill_ace_for_sid ((struct cifs_ace *)((char *)pnndacl + size), - pgrpsid, nmode,S_IRWXG ); - size +=fill_ace_for_sid ((struct cifs_ace *)((char *)pnndacl + size), - &sid_everyone, nmode,S_IRWXO ); -/* TBD: Move this ACE to the top of ACE list instead of bottom */ if (modefromsid) { struct cifs_ace *pntace =
@@ -840,12 +834,22 @@ static int set_chmod_dacl(struct cifs_acl *pndacl, struct cifs_sid *pownersid, pntace->sid.sub_auth[1 ] = sid_unix_NFS_mode.sub_auth[1 ]; pntace->sid.sub_auth[2 ] =cpu_to_le32 (nmode &07777 ); - pndacl->num_aces =cpu_to_le32 (4 ); size +=fill_ace_for_sid ((struct cifs_ace *)((char *)pnndacl + size), &sid_unix_NFS_mode, nmode,S_IRWXO ); - }else - pndacl->num_aces =cpu_to_le32 (3 ); + num_aces++; + } + + size +=fill_ace_for_sid ((struct cifs_ace *) ((char *)pnndacl + size), + pownersid, nmode,S_IRWXU ); + num_aces++; + size +=fill_ace_for_sid ((struct cifs_ace *)((char *)pnndacl + size), + pgrpsid, nmode,S_IRWXG ); + num_aces++; + size +=fill_ace_for_sid ((struct cifs_ace *)((char *)pnndacl + size), + &sid_everyone, nmode,S_IRWXO ); + num_aces++; + pndacl->num_aces =cpu_to_le32 (num_aces); pndacl->size =cpu_to_le16 (size +sizeof (struct cifs_acl ));return 0 ;
Signature · 1 line
2.16.4