]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.19.31/btrfs-setup-a-nofs-context-for-memory-allocation-at-__btrfs_set_acl.patch
Linux 4.14.108
[thirdparty/kernel/stable-queue.git] / releases / 4.19.31 / btrfs-setup-a-nofs-context-for-memory-allocation-at-__btrfs_set_acl.patch
1 From a0873490660246db587849a9e172f2b7b21fa88a Mon Sep 17 00:00:00 2001
2 From: Filipe Manana <fdmanana@suse.com>
3 Date: Thu, 13 Dec 2018 21:16:56 +0000
4 Subject: Btrfs: setup a nofs context for memory allocation at __btrfs_set_acl
5
6 From: Filipe Manana <fdmanana@suse.com>
7
8 commit a0873490660246db587849a9e172f2b7b21fa88a upstream.
9
10 We are holding a transaction handle when setting an acl, therefore we can
11 not allocate the xattr value buffer using GFP_KERNEL, as we could deadlock
12 if reclaim is triggered by the allocation, therefore setup a nofs context.
13
14 Fixes: 39a27ec1004e8 ("btrfs: use GFP_KERNEL for xattr and acl allocations")
15 CC: stable@vger.kernel.org # 4.9+
16 Reviewed-by: Nikolay Borisov <nborisov@suse.com>
17 Signed-off-by: Filipe Manana <fdmanana@suse.com>
18 Reviewed-by: David Sterba <dsterba@suse.com>
19 Signed-off-by: David Sterba <dsterba@suse.com>
20 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
21
22 ---
23 fs/btrfs/acl.c | 9 +++++++++
24 1 file changed, 9 insertions(+)
25
26 --- a/fs/btrfs/acl.c
27 +++ b/fs/btrfs/acl.c
28 @@ -9,6 +9,7 @@
29 #include <linux/posix_acl_xattr.h>
30 #include <linux/posix_acl.h>
31 #include <linux/sched.h>
32 +#include <linux/sched/mm.h>
33 #include <linux/slab.h>
34
35 #include "ctree.h"
36 @@ -72,8 +73,16 @@ static int __btrfs_set_acl(struct btrfs_
37 }
38
39 if (acl) {
40 + unsigned int nofs_flag;
41 +
42 size = posix_acl_xattr_size(acl->a_count);
43 + /*
44 + * We're holding a transaction handle, so use a NOFS memory
45 + * allocation context to avoid deadlock if reclaim happens.
46 + */
47 + nofs_flag = memalloc_nofs_save();
48 value = kmalloc(size, GFP_KERNEL);
49 + memalloc_nofs_restore(nofs_flag);
50 if (!value) {
51 ret = -ENOMEM;
52 goto out;