All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gao Xiang <xiang@kernel.org>
To: linux-erofs@lists.ozlabs.org, Li Guifu <bluce.liguifu@huawei.com>
Cc: Gao Xiang <xiang@kernel.org>
Subject: [PATCH v3 4/5] erofs-utils: zero out garbage trailing data for non-0padding cases
Date: Wed, 28 Apr 2021 12:03:44 +0800	[thread overview]
Message-ID: <20210428040345.4047-4-xiang@kernel.org> (raw)
In-Reply-To: <20210428040345.4047-1-xiang@kernel.org>

When "-E legacy-compress" is used, lz4 0padding feature would be
disabled by default in order to support old kernels (< Linux v5.3).

In that case, the current mkfs leaves previous garbage data after
valid compressed data if the length becomes shorter. This doesn't
matter for kernels >= v5.0 since LZ4_decompress_safe_partial()
is used.

However, for staging erofs v4.19, it uses an in-house customized lz4
implemention due to LZ4_decompress_safe_partial() doesn't work as
expected at that time, yet it doesn't allow trailing random data in
practice or decompression failure could happen.

I don't think it really matters since "obsoleted_mkfs" works perfectly
for such old staging versions (v4.19). Anyway, trailing garbage data
sounds unreasonable, so let's zero out it now.

Fixes: 66653ef10a7f ("erofs-utils: zero out garbage trailing data for non-0padding cases")
Signed-off-by: Gao Xiang <xiang@kernel.org>
---
 lib/compress.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/lib/compress.c b/lib/compress.c
index b8bb89e7ae9d..deef6a2c8ae3 100644
--- a/lib/compress.c
+++ b/lib/compress.c
@@ -189,18 +189,22 @@ nocompression:
 			ctx->compressedblks = 1;
 			raw = true;
 		} else {
-			const unsigned int used = ret & (EROFS_BLKSIZ - 1);
-			const unsigned int margin =
-				erofs_sb_has_lz4_0padding() && used ?
-					EROFS_BLKSIZ - used : 0;
+			const unsigned int tailused = ret & (EROFS_BLKSIZ - 1);
+			const unsigned int padding =
+				erofs_sb_has_lz4_0padding() && tailused ?
+					EROFS_BLKSIZ - tailused : 0;
 
 			ctx->compressedblks = DIV_ROUND_UP(ret, EROFS_BLKSIZ);
+			/* zero out garbage trailing data for non-0padding */
+			if (!erofs_sb_has_lz4_0padding())
+				memset(dst + ret, 0,
+				       roundup(ret, EROFS_BLKSIZ) - ret);
 
 			/* write compressed data */
 			erofs_dbg("Writing %u compressed data to %u of %u blocks",
 				  count, ctx->blkaddr, ctx->compressedblks);
 
-			ret = blk_write(dst - margin, ctx->blkaddr,
+			ret = blk_write(dst - padding, ctx->blkaddr,
 					ctx->compressedblks);
 			if (ret)
 				return ret;
-- 
2.20.1


  parent reply	other threads:[~2021-04-28  4:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-28  4:03 [PATCH v3 1/5] erofs-utils: sync up with in-kernel erofs_fs.h Gao Xiang
2021-04-28  4:03 ` [PATCH v3 2/5] erofs-utils: warn out experimental big pcluster Gao Xiang
2021-04-28  4:03 ` [PATCH v3 3/5] erofs-utils: manpage: add missing -C option for " Gao Xiang
2021-04-28  4:03 ` Gao Xiang [this message]
2021-04-28  4:03 ` [PATCH v3 5/5] erofs-uils: manpage: add manual for erofsfuse Gao Xiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210428040345.4047-4-xiang@kernel.org \
    --to=xiang@kernel.org \
    --cc=bluce.liguifu@huawei.com \
    --cc=linux-erofs@lists.ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.