Home Home > GIT Browse > stable
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiri Slaby <jslaby@suse.cz>2019-01-18 07:53:27 +0100
committerJiri Slaby <jslaby@suse.cz>2019-01-18 07:53:43 +0100
commit53c17a6aa1902e0f4d6ddb9d4d69f6ba9e272b4a (patch)
tree154a7e831b03ad2f914d194236dc1d8dde34df91
parentfd714bcea58e3fe31b19824b70511f183424fcea (diff)
Btrfs: use nofs context when initializing security xattrs to
avoid deadlock (bnc#1012628).
-rw-r--r--patches.kernel.org/4.20.3-057-Btrfs-use-nofs-context-when-initializing-secur.patch64
-rw-r--r--series.conf1
2 files changed, 65 insertions, 0 deletions
diff --git a/patches.kernel.org/4.20.3-057-Btrfs-use-nofs-context-when-initializing-secur.patch b/patches.kernel.org/4.20.3-057-Btrfs-use-nofs-context-when-initializing-secur.patch
new file mode 100644
index 0000000000..3266d62a88
--- /dev/null
+++ b/patches.kernel.org/4.20.3-057-Btrfs-use-nofs-context-when-initializing-secur.patch
@@ -0,0 +1,64 @@
+From: Filipe Manana <fdmanana@suse.com>
+Date: Mon, 10 Dec 2018 17:53:35 +0000
+Subject: [PATCH] Btrfs: use nofs context when initializing security xattrs to
+ avoid deadlock
+References: bnc#1012628
+Patch-mainline: 4.20.3
+Git-commit: 827aa18e7b903c5ff3b3cd8fec328a99b1dbd411
+
+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>
+Signed-off-by: Jiri Slaby <jslaby@suse.cz>
+---
+ fs/btrfs/xattr.c | 8 ++++++++
+ 1 file changed, 8 insertions(+)
+
+diff --git a/fs/btrfs/xattr.c b/fs/btrfs/xattr.c
+index ea78c3d6dcfc..f141b45ce349 100644
+--- a/fs/btrfs/xattr.c
++++ b/fs/btrfs/xattr.c
+@@ -11,6 +11,7 @@
+ #include <linux/security.h>
+ #include <linux/posix_acl_xattr.h>
+ #include <linux/iversion.h>
++#include <linux/sched/mm.h>
+ #include "ctree.h"
+ #include "btrfs_inode.h"
+ #include "transaction.h"
+@@ -422,9 +423,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);
+@@ -440,6 +447,7 @@ static int btrfs_initxattrs(struct inode *inode,
+ if (err < 0)
+ break;
+ }
++ memalloc_nofs_restore(nofs_flag);
+ return err;
+ }
+
+--
+2.20.1
+
diff --git a/series.conf b/series.conf
index b9ce242ffb..feebc1f72f 100644
--- a/series.conf
+++ b/series.conf
@@ -294,6 +294,7 @@
patches.kernel.org/4.20.3-054-sunrpc-use-after-free-in-svc_process_common.patch
patches.kernel.org/4.20.3-055-Btrfs-fix-access-to-available-allocation-bits-.patch
patches.kernel.org/4.20.3-056-Btrfs-fix-deadlock-when-enabling-quotas-due-to.patch
+ patches.kernel.org/4.20.3-057-Btrfs-use-nofs-context-when-initializing-secur.patch
########################################################
# Build fixes that apply to the vanilla kernel too.