Merge tag 'nfs-for-4.13-1' of git://git.linux-nfs.org/projects/anna/linux-nfs
[sfrench/cifs-2.6.git] / fs / nfs / super.c
index b5271644b4726558650addef693284bf7fc85283..d828ef88e7db63e83b74e34ef918bee0fbe2b362 100644 (file)
@@ -2547,10 +2547,25 @@ EXPORT_SYMBOL_GPL(nfs_set_sb_security);
 int nfs_clone_sb_security(struct super_block *s, struct dentry *mntroot,
                          struct nfs_mount_info *mount_info)
 {
+       int error;
+       unsigned long kflags = 0, kflags_out = 0;
+
        /* clone any lsm security options from the parent to the new sb */
        if (d_inode(mntroot)->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops)
                return -ESTALE;
-       return security_sb_clone_mnt_opts(mount_info->cloned->sb, s);
+
+       if (NFS_SB(s)->caps & NFS_CAP_SECURITY_LABEL)
+               kflags |= SECURITY_LSM_NATIVE_LABELS;
+
+       error = security_sb_clone_mnt_opts(mount_info->cloned->sb, s, kflags,
+                       &kflags_out);
+       if (error)
+               return error;
+
+       if (NFS_SB(s)->caps & NFS_CAP_SECURITY_LABEL &&
+               !(kflags_out & SECURITY_LSM_NATIVE_LABELS))
+               NFS_SB(s)->caps &= ~NFS_CAP_SECURITY_LABEL;
+       return 0;
 }
 EXPORT_SYMBOL_GPL(nfs_clone_sb_security);