Merge tag 'idmapped-mounts-v5.12' of git://git.kernel.org/pub/scm/linux/kernel/git...
[platform/kernel/linux-rpi.git] / fs / f2fs / acl.c
index a19e86c..965037a 100644 (file)
@@ -200,6 +200,27 @@ struct posix_acl *f2fs_get_acl(struct inode *inode, int type)
        return __f2fs_get_acl(inode, type, NULL);
 }
 
+static int f2fs_acl_update_mode(struct inode *inode, umode_t *mode_p,
+                         struct posix_acl **acl)
+{
+       umode_t mode = inode->i_mode;
+       int error;
+
+       if (is_inode_flag_set(inode, FI_ACL_MODE))
+               mode = F2FS_I(inode)->i_acl_mode;
+
+       error = posix_acl_equiv_mode(*acl, &mode);
+       if (error < 0)
+               return error;
+       if (error == 0)
+               *acl = NULL;
+       if (!in_group_p(i_gid_into_mnt(&init_user_ns, inode)) &&
+           !capable_wrt_inode_uidgid(&init_user_ns, inode, CAP_FSETID))
+               mode &= ~S_ISGID;
+       *mode_p = mode;
+       return 0;
+}
+
 static int __f2fs_set_acl(struct inode *inode, int type,
                        struct posix_acl *acl, struct page *ipage)
 {
@@ -213,8 +234,7 @@ static int __f2fs_set_acl(struct inode *inode, int type,
        case ACL_TYPE_ACCESS:
                name_index = F2FS_XATTR_INDEX_POSIX_ACL_ACCESS;
                if (acl && !ipage) {
-                       error = posix_acl_update_mode(&init_user_ns, inode,
-                                                     &mode, &acl);
+                       error = f2fs_acl_update_mode(inode, &mode, &acl);
                        if (error)
                                return error;
                        set_acl_inode(inode, mode);