public inbox for linux-s390@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: Fix avail_in bytes for s390 zlib HW compression path
@ 2024-12-12 13:50 Mikhail Zaslonko
  2024-12-12 15:37 ` Ilya Leoshkevich
  2024-12-12 20:37 ` Qu Wenruo
  0 siblings, 2 replies; 5+ messages in thread
From: Mikhail Zaslonko @ 2024-12-12 13:50 UTC (permalink / raw)
  To: Qu Wenruo, David Sterba, linux-btrfs
  Cc: Vasily Gorbik, Alexander Gordeev, Heiko Carstens,
	Ilya Leoshkevich, linux-s390

Since the input data length passed to zlib_compress_folios() can be
arbitrary, always setting strm.avail_in to a multiple of PAGE_SIZE may
cause read-in bytes to exceed the input range. Currently this triggers
an assert in btrfs_compress_folios() on the debug kernel. But it may
potentially lead to data corruption.
Fix strm.avail_in calculation for S390 hardware acceleration path.

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Fixes: fd1e75d0105d ("btrfs: make compression path to be subpage compatible")
---
 fs/btrfs/zlib.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c
index ddf0d5a448a7..c9e92c6941ec 100644
--- a/fs/btrfs/zlib.c
+++ b/fs/btrfs/zlib.c
@@ -174,10 +174,10 @@ int zlib_compress_folios(struct list_head *ws, struct address_space *mapping,
 					copy_page(workspace->buf + i * PAGE_SIZE,
 						  data_in);
 					start += PAGE_SIZE;
-					workspace->strm.avail_in =
-						(in_buf_folios << PAGE_SHIFT);
 				}
 				workspace->strm.next_in = workspace->buf;
+				workspace->strm.avail_in = min(bytes_left,
+							       in_buf_folios << PAGE_SHIFT);
 			} else {
 				unsigned int pg_off;
 				unsigned int cur_len;
-- 
2.47.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-12-13  9:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-12 13:50 [PATCH] btrfs: Fix avail_in bytes for s390 zlib HW compression path Mikhail Zaslonko
2024-12-12 15:37 ` Ilya Leoshkevich
2024-12-12 20:37 ` Qu Wenruo
2024-12-13  9:34   ` Zaslonko Mikhail
2024-12-13  9:42     ` Qu Wenruo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox