]> git.hungrycats.org Git - linux/commitdiff
Btrfs: use nofs context when initializing security xattrs to avoid deadlock
authorFilipe Manana <fdmanana@suse.com>
Mon, 10 Dec 2018 17:53:35 +0000 (17:53 +0000)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Fri, 15 Mar 2019 20:31:55 +0000 (16:31 -0400)
commit 827aa18e7b903c5ff3b3cd8fec328a99b1dbd411 upstream.

When initializing the security xattrs, we are holding a transaction handle
therefore we need to use a GFP_NOFS context in order to avoid a deadlock
with reclaim in case it's triggered.

Fixes: 39a27ec1004e8 ("btrfs: use GFP_KERNEL for xattr and acl allocations")
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 7a1b9b76bac76498657b9322164957c2a50c573b)

fs/btrfs/xattr.c

index 2c7e53f9ff1b9d3d3c80d6ae5f8b6fcc9e83ec6f..afdebf0dbdd62b2d798863846353f57783c82a6b 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/xattr.h>
 #include <linux/security.h>
 #include <linux/posix_acl_xattr.h>
+#include <linux/sched/mm.h>
 #include "ctree.h"
 #include "btrfs_inode.h"
 #include "transaction.h"
@@ -441,9 +442,15 @@ static int btrfs_initxattrs(struct inode *inode,
 {
        const struct xattr *xattr;
        struct btrfs_trans_handle *trans = fs_info;
+       unsigned int nofs_flag;
        char *name;
        int err = 0;
 
+       /*
+        * We're holding a transaction handle, so use a NOFS memory allocation
+        * context to avoid deadlock if reclaim happens.
+        */
+       nofs_flag = memalloc_nofs_save();
        for (xattr = xattr_array; xattr->name != NULL; xattr++) {
                name = kmalloc(XATTR_SECURITY_PREFIX_LEN +
                               strlen(xattr->name) + 1, GFP_KERNEL);
@@ -459,6 +466,7 @@ static int btrfs_initxattrs(struct inode *inode,
                if (err < 0)
                        break;
        }
+       memalloc_nofs_restore(nofs_flag);
        return err;
 }