From patchwork Tue Jun 23 19:53:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 223559 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E93CC433DF for ; Tue, 23 Jun 2020 20:08:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 63BED2078A for ; Tue, 23 Jun 2020 20:08:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592942923; bh=xez/82YlJ7SYV4iZ5OSzgj55WpYE4zP+9siTcqExYDg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=q7wxWj3+14m4DJctwEDS1joFmYpjHzZVeruy3UoXvBXeWJ9Wk1l+JZWs140lWnWYD wYCGTmuvYpyqgEJRbMU3wAGhLV4C25/ZiUaRx2+O/zjHqkqjWrsnjHpBIPK6ZVL3/t H3ur5R5TxDO4HOhsGa2wrUk8S3HSj3xeA3fWkkmo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388248AbgFWUIm (ORCPT ); Tue, 23 Jun 2020 16:08:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:49684 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388208AbgFWUIk (ORCPT ); Tue, 23 Jun 2020 16:08:40 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7D58C20FC3; Tue, 23 Jun 2020 20:08:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592942920; bh=xez/82YlJ7SYV4iZ5OSzgj55WpYE4zP+9siTcqExYDg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PYkOYRnyEiMcJKBd22HGCOeAZ9vx9TNeONjuz60sV989sEOUjkRO85W0xqgsbVE1c CYW7gTK0EatKR4dRPiuYmal8mlLZkvW/awbNBgj3IL0RU3AM+0fzQAjQ+nXNcQRf3M f0WC0cI8M4wr4vz2X+mxULXNUn0Iv3Rmjit2+cMc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daeho Jeong , Chao Yu , Jaegeuk Kim , Sasha Levin Subject: [PATCH 5.7 187/477] f2fs: compress: fix zstd data corruption Date: Tue, 23 Jun 2020 21:53:04 +0200 Message-Id: <20200623195416.427934605@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200623195407.572062007@linuxfoundation.org> References: <20200623195407.572062007@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Chao Yu [ Upstream commit 1454c978efbb57b052670d50023f48c759d704ce ] During zstd compression, ZSTD_endStream() may return non-zero value because distination buffer is full, but there is still compressed data remained in intermediate buffer, it means that zstd algorithm can not save at last one block space, let's just writeback raw data instead of compressed one, this can fix data corruption when decompressing incomplete stored compression data. Fixes: 50cfa66f0de0 ("f2fs: compress: support zstd compress algorithm") Signed-off-by: Daeho Jeong Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/compress.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c index c05801758a358..a5b2e72174bb1 100644 --- a/fs/f2fs/compress.c +++ b/fs/f2fs/compress.c @@ -369,6 +369,13 @@ static int zstd_compress_pages(struct compress_ctx *cc) return -EIO; } + /* + * there is compressed data remained in intermediate buffer due to + * no more space in cbuf.cdata + */ + if (ret) + return -EAGAIN; + cc->clen = outbuf.pos; return 0; }