[rh7,2/2] ploop: Add debug check on truncation to kaio_fsync_thread

Submitted by Kirill Tkhai on Feb. 7, 2020, 10:23 a.m.

Details

Message ID 158107098974.193023.12600901298584569429.stgit@localhost.localdomain
State New
Series "Series without cover letter"
Headers show

Commit Message

Kirill Tkhai Feb. 7, 2020, 10:23 a.m.
https://jira.sw.ru/browse/PSBM-101418

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 drivers/block/ploop/io_kaio.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/drivers/block/ploop/io_kaio.c b/drivers/block/ploop/io_kaio.c
index 9f391620a4f7..1cac861e9be0 100644
--- a/drivers/block/ploop/io_kaio.c
+++ b/drivers/block/ploop/io_kaio.c
@@ -479,6 +479,7 @@  static int kaio_fsync_thread(void * data)
 {
 	struct ploop_io * io = data;
 	struct ploop_device * plo = io->plo;
+	loff_t isize;
 
 	set_user_nice(current, -20);
 
@@ -512,6 +513,9 @@  static int kaio_fsync_thread(void * data)
 
 		/* trick: preq->prealloc_size is actually new pos of eof */
 		if (preq->prealloc_size) {
+			isize = i_size_read(io->files.inode);
+			if (WARN_ON_ONCE(preq->prealloc_size < isize))
+				goto out;
 			err = kaio_truncate(io, io->files.file,
 					    preq->prealloc_size >> (plo->cluster_log + 9));
 			if (err)
@@ -536,7 +540,7 @@  static int kaio_fsync_thread(void * data)
 				}
 			}
 		}
-
+out:
 		spin_lock_irq(&plo->lock);
 		list_add_tail(&preq->list, &plo->ready_queue);