lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20191227080523.31808-4-naoto.kobayashi4c@gmail.com>
Date:   Fri, 27 Dec 2019 17:05:23 +0900
From:   Naoto Kobayashi <naoto.kobayashi4c@...il.com>
To:     tytso@....edu, adilger.kernel@...ger.ca
Cc:     Naoto Kobayashi <naoto.kobayashi4c@...il.com>,
        linux-ext4@...r.kernel.org
Subject: [PATCH v2 3/3] ext4: Prevent ext4_kvmalloc_nofs() from re-entering the filesystem and deadlocking

Even if __vmalloc() receives GFP_NOFS, this function allocates
data pages and auxiliary structures (e.g. pagetables) with __GFP_FS[1].
To prevent memory reclaim from re-entering the filesystem here and
potentially deadlocking, use memalloc_nofs_save() that gets
__vmalloc() to drop __GFP_FS.

[1] linux-tree/Documentation/core-api/gfp-mask-fs-io.rst

Signed-off-by: Naoto Kobayashi <naoto.kobayashi4c@...il.com>
---
 fs/ext4/super.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index e8965aa6ecce..7f4c9a43a3f3 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -43,6 +43,7 @@
 #include <linux/uaccess.h>
 #include <linux/iversion.h>
 #include <linux/unicode.h>
+#include <linux/sched/mm.h>

 #include <linux/kthread.h>
 #include <linux/freezer.h>
@@ -206,11 +207,13 @@ void ext4_superblock_csum_set(struct super_block *sb)

 void *ext4_kvmalloc_nofs(size_t size)
 {
+	unsigned int nofs_flag;
 	void *ret;

-	ret = kmalloc(size, GFP_NOFS | __GFP_NOWARN);
-	if (!ret)
-		ret = __vmalloc(size, GFP_NOFS, PAGE_KERNEL);
+	/* kvmalloc() does not support GFP_NOFS */
+	nofs_flag = memalloc_nofs_save();
+	ret = kvmalloc(size, GFP_KERNEL);
+	memalloc_nofs_restore(nofs_flag);
 	return ret;
 }

--
2.16.6

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ