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]
Date:   Fri,  2 Sep 2022 14:31:34 +0800
From:   Yue Hu <zbestahu@...il.com>
To:     xiang@...nel.org, chao@...nel.org
Cc:     linux-erofs@...ts.ozlabs.org, linux-kernel@...r.kernel.org,
        zhangwen@...lpad.com, Yue Hu <huyue2@...lpad.com>
Subject: [PATCH] erofs: support uncompressed pcluster with more than 1 block

From: Yue Hu <huyue2@...lpad.com>

The length of uncompressed pcluster may exceed one block in some new
scenarios such as non 4K-sized lcluster (which will be supported later).
So, let's support the decompression for this firstly.

Signed-off-by: Yue Hu <huyue2@...lpad.com>
---
 fs/erofs/decompressor.c | 56 +++++++++++++++++++++++++----------------
 1 file changed, 35 insertions(+), 21 deletions(-)

diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c
index 2d55569f96ac..fe6abb79e560 100644
--- a/fs/erofs/decompressor.c
+++ b/fs/erofs/decompressor.c
@@ -320,41 +320,55 @@ static int z_erofs_lz4_decompress(struct z_erofs_decompress_req *rq,
 static int z_erofs_shifted_transform(struct z_erofs_decompress_req *rq,
 				     struct page **pagepool)
 {
+	const unsigned int nrpages_in = rq->inputsize >> PAGE_SHIFT;
 	const unsigned int nrpages_out =
 		PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT;
 	const unsigned int righthalf = min_t(unsigned int, rq->outputsize,
 					     PAGE_SIZE - rq->pageofs_out);
-	const unsigned int lefthalf = rq->outputsize - righthalf;
+	const unsigned int lefthalf = min_t(unsigned int,
+					    rq->outputsize - righthalf,
+					    PAGE_SIZE - righthalf);
 	unsigned char *src, *dst;
+	unsigned int i;
 
-	if (nrpages_out > 2) {
+	if (nrpages_in == 1 && nrpages_out > 2) {
 		DBG_BUGON(1);
 		return -EIO;
 	}
 
-	if (rq->out[0] == *rq->in) {
-		DBG_BUGON(nrpages_out != 1);
-		return 0;
-	}
+	i = 0;
+	do {
+		src = kmap_atomic(rq->in[i]) + rq->pageofs_in;
+
+		if (rq->out[i]) {
+			if (rq->out[i] == rq->in[i]) {
+				DBG_BUGON(nrpages_in == 1 && nrpages_out != 1);
+			} else {
+				dst = kmap_atomic(rq->out[i]);
+				memcpy(dst + rq->pageofs_out, src, righthalf);
+				kunmap_atomic(dst);
+			}
+		}
 
-	src = kmap_atomic(*rq->in) + rq->pageofs_in;
-	if (rq->out[0]) {
-		dst = kmap_atomic(rq->out[0]);
-		memcpy(dst + rq->pageofs_out, src, righthalf);
-		kunmap_atomic(dst);
-	}
+		if (i + 1 == nrpages_out) {
+			kunmap_atomic(src);
+			break;
+		}
 
-	if (nrpages_out == 2) {
-		DBG_BUGON(!rq->out[1]);
-		if (rq->out[1] == *rq->in) {
-			memmove(src, src + righthalf, lefthalf);
+		if (rq->out[i + 1]) {
+			if (rq->out[i + 1] == rq->in[i]) {
+				memmove(src, src + righthalf, lefthalf);
+			} else {
+				dst = kmap_atomic(rq->out[i + 1]);
+				memcpy(dst, src + righthalf, lefthalf);
+				kunmap_atomic(dst);
+			}
 		} else {
-			dst = kmap_atomic(rq->out[1]);
-			memcpy(dst, src + righthalf, lefthalf);
-			kunmap_atomic(dst);
+			DBG_BUGON(nrpages_in == 1 && nrpages_out == 2);
 		}
-	}
-	kunmap_atomic(src);
+		kunmap_atomic(src);
+	} while (++i < nrpages_in);
+
 	return 0;
 }
 
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ