libnbd/0005-copy-file-ops.c-Fix-pa...

33 lines
1.1 KiB
Diff

From 107eb605cfb75238020332b5a5461d0e09d62bec Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Wed, 3 Mar 2021 12:51:51 +0100
Subject: [PATCH 5/6] copy/file-ops.c: Fix page eviction when len < page_size.
On Fedora ppc64le at the moment page size is 64K. When asked to evict
a range with length < 64K the length calculation wrapped around and it
tried to evict a huge number of pages beyond the end of the file.
With Nir's commit 0f6e4f38b this (correctly) resulted in an assertion
failure.
Fix this by checking for the overflow and returning early.
---
copy/file-ops.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/copy/file-ops.c b/copy/file-ops.c
index 47ec768..6bad50c 100644
--- a/copy/file-ops.c
+++ b/copy/file-ops.c
@@ -155,6 +155,7 @@ page_cache_evict (struct rw_file *rwf, uint64_t orig_offset, size_t orig_len)
/* Only bother with whole pages. */
offset = ROUND_UP (orig_offset, page_size);
+ if (orig_len < offset - orig_offset) return;
len = orig_len - (offset - orig_offset);
len = ROUND_DOWN (len, page_size);
--
2.29.0.rc2