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>] [day] [month] [year] [list]
Message-ID: <20200103095107.8152-1-yuchao0@huawei.com>
Date:   Fri, 3 Jan 2020 17:51:07 +0800
From:   Chao Yu <yuchao0@...wei.com>
To:     <jaegeuk@...nel.org>
CC:     <linux-f2fs-devel@...ts.sourceforge.net>,
        <linux-kernel@...r.kernel.org>, <chao@...nel.org>,
        Chao Yu <yuchao0@...wei.com>
Subject: [PATCH TEST] f2fs: compress: fix deadlock in prepare_compress_overwrite()

   100.00%    13.65%  fsstress  [f2fs]              [k] prepare_compress_overwrite
            |
            |--86.35%--prepare_compress_overwrite
            |          |
            |          |--46.78%--f2fs_read_multi_pages
            |          |          |
            |          |          |--19.81%--f2fs_decompress_end_io
            |          |          |          |
            |          |          |           --5.77%--unlock_page
            |          |          |
            |          |          |--19.53%--f2fs_get_dnode_of_data

In prepare_compress_overwrite(), we need to check cluster state before
read cluster data, otherwise, read normal cluster as a compressed one
will always cause failure and retry.

Signed-off-by: Chao Yu <yuchao0@...wei.com>
---
 fs/f2fs/compress.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c
index 9e8fba78db4d..f993b4ce1970 100644
--- a/fs/f2fs/compress.c
+++ b/fs/f2fs/compress.c
@@ -570,8 +570,7 @@ static void set_cluster_dirty(struct compress_ctx *cc)
 }
 
 static int prepare_compress_overwrite(struct compress_ctx *cc,
-		struct page **pagep, pgoff_t index, void **fsdata,
-		bool prealloc)
+		struct page **pagep, pgoff_t index, void **fsdata)
 {
 	struct f2fs_sb_info *sbi = F2FS_I_SB(cc->inode);
 	struct address_space *mapping = cc->inode->i_mapping;
@@ -582,11 +581,20 @@ static int prepare_compress_overwrite(struct compress_ctx *cc,
 	unsigned int start_idx = start_idx_of_cluster(cc);
 	int i, idx;
 	int ret;
+	bool prealloc;
+
+retry:
+	ret = is_compressed_cluster(cc);
+	if (ret <= 0)
+		return ret;
+
+	/* compressed case */
+	prealloc = (ret == CLUSTER_HAS_SPACE);
 
 	ret = f2fs_init_compress_ctx(cc);
 	if (ret)
 		return ret;
-retry:
+
 	/* keep page reference to avoid page reclaim */
 	for (i = 0; i < cc->cluster_size; i++) {
 		page = f2fs_pagecache_get_page(mapping, start_idx + i,
@@ -632,6 +640,7 @@ static int prepare_compress_overwrite(struct compress_ctx *cc,
 						(idx <= i) ? 1 : 0);
 				cc->rpages[idx] = NULL;
 			}
+			kvfree(cc->rpages);
 			cc->nr_rpages = 0;
 			goto retry;
 		}
@@ -687,14 +696,8 @@ int f2fs_prepare_compress_overwrite(struct inode *inode,
 		.rpages = NULL,
 		.nr_rpages = 0,
 	};
-	int ret = is_compressed_cluster(&cc);
-
-	if (ret <= 0)
-		return ret;
 
-	/* compressed case */
-	return prepare_compress_overwrite(&cc, pagep, index,
-			fsdata, ret == CLUSTER_HAS_SPACE);
+	return prepare_compress_overwrite(&cc, pagep, index, fsdata);
 }
 
 bool f2fs_compress_write_end(struct inode *inode, void *fsdata,
-- 
2.18.0.rc1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ